cvs commit: src/lib/libutil pidfile.c

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

On Tue, Apr 11, 2006 at 11:10:02PM +0000, John-Mark Gurney wrote:
+> jmg         2006-04-11 23:10:02 UTC
+>   FreeBSD src repository
+>   Modified files:
+>     lib/libutil          pidfile.c 
+>   Log:
+>   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...
+>  	snprintf(pidstr, sizeof(pidstr), "%u", getpid());
+> -	if (write(fd, pidstr, strlen(pidstr)) != (ssize_t)strlen(pidstr)) {
+> +	if (pwrite(fd, pidstr, strlen(pidstr), 0) != (ssize_t)strlen(pidstr)) {

Multiple pidfile_write()s from the same process? If not, then we must
truncate the file before writting the PID.
Imagine a situation, where PID 10000 is written first and then we
overwrite it with 9999. The result will be 99990.

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