On Tue, Feb 26, 2002 at 09:35:30AM -0500, Theo Van Dinter wrote:
> On Tue, Feb 26, 2002 at 03:04:27AM -0800, Craig Hughes wrote:
> > FYI, your code example is not even close to concurrency-safe.  If one
> > instance checks (-f $path) and finds no file, then context switches, and
> > instance #2 performs the same check, then both instances will try to
> > create a new file, and you'll probably end up with some weird mangled DB
> > file.
> > 
> > >          if ( -f $path ) {
> > >            tie %{$self->{accum}},"AnyDBM_File",$path, O_RDWR,   #open rw w/lock
> > >                    (oct ($main->{conf}->{auto_whitelist_file_mode}) & 0666)
> > >          or die "Cannot open existing auto_whitelist_path $path: $!\n";
> > >            
> > >          } else {
> > >            tie %{$self->{accum}},"AnyDBM_File",$path, O_RDWR|O_CREAT,   #open rw 
>w/lock
> > >                    (oct ($main->{conf}->{auto_whitelist_file_mode}) & 0666)
> > >          or die "Cannot open auto_whitelist_path $path for creation: $!\n";
> > >          }
> 
> Is there a reason you do a check for O_CREAT?  O_CREAT just says "create if
> it doesn't already exist", it won't truncate the current data (that's
> O_TRUNC).  I would elliminate this code and just have a single tie with
> O_CREAT.

I just noticed the comment in the code about "with lock", which O_CREAT
won't give you either.  You'd want to do this check if you're using
O_CREAT|O_EXCL (which will error if the file already exists.)

-- 
Randomly Generated Tagline:
"No boom *today*.  Boom *tomorrow*.  There's always a boom tomorrow."
                 - Ivanova from Babylon 5

_______________________________________________
Spamassassin-talk mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/spamassassin-talk

Reply via email to