~ubuntu-branches/ubuntu/precise/spamassassin/precise-updates

« back to all changes in this revision

Viewing changes to lib/Mail/SpamAssassin/Locker/Win32.pm

  • Committer: Bazaar Package Importer
  • Author(s): Noah Meyerhans
  • Date: 2010-01-26 22:53:12 UTC
  • mfrom: (1.1.13 upstream) (5.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100126225312-wkftb10idc1kz2aq
Tags: 3.3.0-1
* New upstream version.
* Switch to dpkg-source 3.0 (quilt) format

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
use strict;
21
21
use warnings;
22
22
use bytes;
 
23
use re 'taint';
23
24
use Fcntl;
24
25
 
25
26
use Mail::SpamAssassin;
58
59
 
59
60
  if (-e $lock_file && -M $lock_file > (LOCK_MAX_AGE / 86400)) {
60
61
    dbg("locker: safe_lock: breaking stale lock: $lock_file");
61
 
    unlink($lock_file) || warn "locker: safe_lock: unlink of lock file $lock_file failed: $!\n";
 
62
    unlink($lock_file)
 
63
      or warn "locker: safe_lock: unlink of lock file $lock_file failed: $!\n";
62
64
  }
63
65
  for (my $retries = 0; $retries < $max_retries; $retries++) {
64
66
    if ($retries > 0) {
66
68
      # TODO: $self->jittery_one_second_sleep();?
67
69
    }
68
70
    dbg("locker: safe_lock: trying to get lock on $path with $retries retries");
69
 
    if (sysopen(LOCKFILE, $lock_file, O_RDWR|O_CREAT|O_EXCL)) {
 
71
    if (!defined sysopen(LOCKFILE, $lock_file, O_RDWR|O_CREAT|O_EXCL)) {
 
72
      dbg("locker: safe_lock: failed to create lock tmpfile $lock_file: $!");
 
73
    } else {
70
74
      dbg("locker: safe_lock: link to $lock_file: sysopen ok");
71
 
      close(LOCKFILE);
 
75
      close(LOCKFILE)  or warn "error closing a lock file: $!";
72
76
      return 1;
73
77
    }
74
78
    my @stat = stat($lock_file);
 
79
    @stat  or warn "locker: error accessing $lock_file: $!";
 
80
 
75
81
    # check age of lockfile ctime
76
82
    my $age = ($#stat < 11 ? undef : $stat[10]);
77
83
    if ((!defined($age) && $retries > $max_retries / 2) ||
78
84
        (defined($age) && (time - $age > LOCK_MAX_AGE)))
79
85
    {
80
86
      dbg("locker: safe_lock: breaking stale lock: $lock_file");
81
 
      unlink ($lock_file) || warn "locker: safe_lock: unlink of lock file $lock_file failed: $!\n";
 
87
      unlink($lock_file)
 
88
        or warn "locker: safe_lock: unlink of lock file $lock_file failed: $!\n";
82
89
    }
83
90
  }
84
91
  return 0;
89
96
sub safe_unlock {
90
97
  my ($self, $path) = @_;
91
98
 
92
 
  unlink ("$path.lock") || warn "locker: safe_unlock: unlink failed: $path.lock\n";
 
99
  unlink("$path.lock")
 
100
    or warn "locker: safe_unlock: unlink failed: $path.lock\n";
93
101
  dbg("locker: safe_unlock: unlink $path.lock");
94
102
}
95
103