~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

Viewing changes to src/lib/file-dotlock.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/{control,rules}: enable PIE hardening.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2003-2011 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "ioloop.h"
33
33
/* Maximum difference between current time and create file's ctime before
34
34
   logging a warning. Should be less than a second in normal operation. */
35
35
#define MAX_TIME_DIFF 30
 
36
/* NFS may return a cached mtime in stat(). A later non-cached stat() may
 
37
   return a slightly different mtime. Allow the difference to be this much
 
38
   and still consider it to be the same mtime. */
 
39
#define FILE_DOTLOCK_MAX_STAT_MTIME_DIFF 1
36
40
 
37
41
struct dotlock {
38
42
        struct dotlock_settings settings;
530
534
                                try_create_lock_excl(&lock_info, write_pid) :
531
535
                                try_create_lock_hardlink(&lock_info, write_pid,
532
536
                                                         tmp_path, now);
533
 
                        if (ret != 0)
 
537
                        if (ret != 0) {
 
538
                                /* if we succeeded, get the current time once
 
539
                                   more in case disk I/O usage was really high
 
540
                                   and it took a long time to create the lock */
 
541
                                now = time(NULL);
534
542
                                break;
 
543
                        }
535
544
                }
536
545
 
537
546
                if (last_notify != now && set->callback != NULL) {
699
708
        }
700
709
}
701
710
 
 
711
static bool file_dotlock_has_mtime_changed(time_t t1, time_t t2)
 
712
{
 
713
        time_t diff;
 
714
 
 
715
        if (t1 == t2)
 
716
                return FALSE;
 
717
 
 
718
        /* with NFS t1 may have been looked up from local cache.
 
719
           allow it to be a little bit different. */
 
720
        diff = t1 > t2 ? t1-t2 : t2-t1;
 
721
        return diff > FILE_DOTLOCK_MAX_STAT_MTIME_DIFF;
 
722
}
 
723
 
702
724
int file_dotlock_delete(struct dotlock **dotlock_p)
703
725
{
704
726
        struct dotlock *dotlock;
729
751
                return 0;
730
752
        }
731
753
 
732
 
        if (dotlock->mtime != st.st_mtime && dotlock->fd == -1) {
 
754
        if (file_dotlock_has_mtime_changed(dotlock->mtime, st.st_mtime) &&
 
755
            dotlock->fd == -1) {
733
756
                i_warning("Our dotlock file %s was modified (%s vs %s), "
734
757
                          "assuming it wasn't overridden (kept it %d secs)",
735
758
                          lock_path,