cvs commit: src/lib/libutil pidfile.c

Pawel Jakub Dawidek pjd at
Wed Apr 12 07:51:52 UTC 2006

On Wed, Apr 12, 2006 at 12:31:25AM -0700, Colin Percival wrote:
+> Pawel Jakub Dawidek wrote:
+> > On Tue, Apr 11, 2006 at 11:10:02PM +0000, John-Mark Gurney wrote:
+> > +>   use pwrite to always write at the begining of the file..  If multiple calls
+> > +>   to pidfile_write happen, the pidfile will have nul characters prepended
+> > +>   due to the cached file descriptor offset...
+> > 
+> > Multiple pidfile_write()s from the same process? If not, then we must
+> > truncate the file before writting the PID.
+> We already do -- there's a call to ftruncate(fd, 0) a few lines earlier.

Right. Hmm, when I placed this ftruncate(2) there, I must thought that
it will reset the file position indicator...

+> > Imagine a situation, where PID 10000 is written first and then we
+> > overwrite it with 9999. The result will be 99990.
+> The only way this can happen is if two different processes call
+> pidfile_write simultaneously and both ftruncate calls complete
+> before either pwrite call starts; I don't think this is really
+> worth worrying about.

That's not possible, because we lock the file.

I was more thinking about situation, like:
1. daemon()
2. pidfile_write()
4. fork()/daemon()
5. pidfile_write()

Pawel Jakub Dawidek             
pjd at                 
FreeBSD committer                         Am I Evil? Yes, I Am!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url :

More information about the cvs-src mailing list