View | Details | Raw Unified | Return to bug 5612
Collapse All | Expand All

(-)lib/Mail/SpamAssassin/BayesStore/DBM.pm (-1 / +5 lines)
Lines 279-285 Link Here
279
    my $name = $path.'_'.$dbname;
279
    my $name = $path.'_'.$dbname;
280
    my $db_var = 'db_'.$dbname;
280
    my $db_var = 'db_'.$dbname;
281
    dbg("bayes: tie-ing to DB file R/W $name");
281
    dbg("bayes: tie-ing to DB file R/W $name");
282
    tie %{$self->{$db_var}},$self->DBM_MODULE,$name, O_RDWR|O_CREAT,
282
283
    ($self->DBM_MODULE eq 'DB_File') and
284
         Mail::SpamAssassin::Util::avoid_db_file_locking_bug ($name);
285
286
    tie %{$self->{$db_var}},$self->DBM_MODULE, $name, O_RDWR|O_CREAT,
283
		 (oct($main->{conf}->{bayes_file_mode}) & 0666)
287
		 (oct($main->{conf}->{bayes_file_mode}) & 0666)
284
       or goto failed_to_tie;
288
       or goto failed_to_tie;
285
  }
289
  }
(-)lib/Mail/SpamAssassin/DBBasedAddrList.pm (-7 / +11 lines)
Lines 82-96 Link Here
82
82
83
    dbg("auto-whitelist: tie-ing to DB file of type $dbm_module $mod1 in $path");
83
    dbg("auto-whitelist: tie-ing to DB file of type $dbm_module $mod1 in $path");
84
84
85
    ($self->{is_locked} && $dbm_module eq 'DB_File') and 
86
            Mail::SpamAssassin::Util::avoid_db_file_locking_bug ($path);
87
85
    if (! tie %{ $self->{accum} }, $dbm_module, $path, $mod2,
88
    if (! tie %{ $self->{accum} }, $dbm_module, $path, $mod2,
86
      oct($main->{conf}->{auto_whitelist_file_mode}) ) {
89
            oct($main->{conf}->{auto_whitelist_file_mode}) )
87
        my $err = $!;   # might get overwritten later
90
    {
88
        if ($self->{is_locked}) {
91
      my $err = $!;   # might get overwritten later
89
          $self->{main}->{locker}->safe_unlock($self->{locked_file});
92
      if ($self->{is_locked}) {
90
          $self->{is_locked} = 0;
93
        $self->{main}->{locker}->safe_unlock($self->{locked_file});
91
        }
94
        $self->{is_locked} = 0;
92
        die "auto-whitelist: cannot open auto_whitelist_path $path: $err\n";
93
      }
95
      }
96
      die "auto-whitelist: cannot open auto_whitelist_path $path: $err\n";
97
    }
94
  }
98
  }
95
99
96
  bless ($self, $class);
100
  bless ($self, $class);
(-)lib/Mail/SpamAssassin/Util.pm (+23 lines)
Lines 61-66 Link Here
61
61
62
use Config;
62
use Config;
63
use File::Spec;
63
use File::Spec;
64
use File::Basename;
64
use Time::Local;
65
use Time::Local;
65
use Sys::Hostname (); # don't import hostname() into this namespace!
66
use Sys::Hostname (); # don't import hostname() into this namespace!
66
use Fcntl;
67
use Fcntl;
Lines 1555-1560 Link Here
1555
1556
1556
###########################################################################
1557
###########################################################################
1557
1558
1559
# bug 5612: work around for bugs in Berkeley db 4.2
1560
#
1561
# on 4.2 having the __db.[DBNAME] file will cause an loop that will never finish
1562
# on 4.3+ the loop will timeout after 301 open attempts, but we will still
1563
# be unable to open the database.  This workaround solves both problems. 
1564
#
1565
sub avoid_db_file_locking_bug {
1566
  my ($path) = @_;
1567
1568
  my $parentdir = dirname($path);
1569
  my $db_tmpfile = File::Spec->catfile($parentdir,'__db.'.basename($path));
1570
1571
  if (-e $db_tmpfile) {
1572
    dbg("Berkeley DB bug work-around: cleaning tmp file $db_tmpfile");
1573
    if (!unlink($db_tmpfile)) {
1574
      die "cannot remove Berkeley DB tmp file $db_tmpfile: $!\n";
1575
    }
1576
  }
1577
}
1578
1579
###########################################################################
1580
1558
1;
1581
1;
1559
1582
1560
=back
1583
=back

Return to bug 5612