While I'm not sure what the best fix is, I've also encountered the file name collision
problem in my
clamav plugin.
In my plugin I did:
srand($$+time);
which is not perfect, but fixed the problem for me.
Jim
James H. Thompson
[EMAIL PROTECTED]
----- Original Message -----
From: "Matt Sergeant" <[EMAIL PROTECTED]>
To: "Robert Spier" <[EMAIL PROTECTED]>
Cc: "qpsmtpd List" <[EMAIL PROTECTED]>
Sent: Friday, July 16, 2004 11:44 PM
Subject: Re: srand() for forkserver
> On 17 Jul 2004, at 05:52, Robert Spier wrote:
>
> >> +
> >> + ## call srand(), else we will have (e.g.) the same tempfile in
> >> + ## _all_ children
> >> + ## i.e. after 'use File::Temp; ($fh,$name)=tempfile();' in a
> >> plugin
> >> + srand( ($$ ^ $port) ^ (time ^ unpack("C*", $iaddr)) );
> >>
> >> close($server);
> >
> > What version of perl are you using? That shouldn't be necessary, and
> > I can't replicate the problem.
> >
> > perl -MFile::Temp=tempfile -le' print $]; for(1..4) { unless ( fork()
> > ) { ($h,$n) = tempfile(); print "$_:$n"; exit; } } while(wait>0){1};'
> > 5.008003
> > 1:/tmp/uNb2fHtfHs
> > 2:/tmp/R039hLPiKO
> > 3:/tmp/Wish2wqoM7
> > 4:/tmp/488A0F4Hrx
> >
> > All children. All forked. No srand. All different.
>
> I've seen this before - it might depend on loaded modules (e.g. a
> module might call srand in the parent). I've applied the patch anyway
> as it's sensible.
>
> Matt.
>