Date: Mon, 28 Jun 2010 08:14:58 -0600 (MDT) From: "M. Warner Losh" <imp@bsdimp.com> To: des@des.no Cc: yanefbsd@gmail.com, freebsd-current@freebsd.org, hselasky@c2i.net Subject: Re: Patch for rc.d/devd on FreeBSD 9-current Message-ID: <20100628.081458.18103541849609641.imp@bsdimp.com> In-Reply-To: <86mxuf7eli.fsf@ds4.des.no> References: <AANLkTilnYGNz7V6z6AkeKsqUvOMN8yLvO57GM1gOIsTD@mail.gmail.com> <20100627.155004.49280345238493664.imp@bsdimp.com> <86mxuf7eli.fsf@ds4.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
In message: <86mxuf7eli.fsf@ds4.des.no>
Dag-Erling Smørgrav <des@des.no> writes:
: "M. Warner Losh" <imp@bsdimp.com> writes:
: > Why not fix pidfile_open to not return a file handle when the PID
: > doesn't match?
:
: It doesn't. If it can't lock the file, or if fstat(2) fails after it
: has locked the file, it returns NULL.
Then we have a bug in the locking code. I've definitely seen things
fail to behave properly after killing devd. Let me trace out what I
think is going on:
From pidfile_open:
/*
* Open the PID file and obtain exclusive lock.
* We truncate PID file here only to remove old PID immediatelly,
* PID file will be truncated again in pidfile_write(), so
* pidfile_write() can be called multiple times.
*/
fd = flopen(pfh->pf_path,
O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode);
if (fd == -1) {
---> We take this path, fd == -1.
count = 0;
rqtp.tv_sec = 0;
rqtp.tv_nsec = 5000000;
if (errno == EWOULDBLOCK && pidptr != NULL) {
again:
---> and this one, so errno is EWOULDBLOCK
errno = pidfile_read(pfh->pf_path, pidptr);
---> errno is 0 here, so
if (errno == 0)
errno = EEXIST;
---> We return NULL with errno set toEEXIST
else if (errno == EAGAIN) {
if (++count <= 3) {
nanosleep(&rqtp, 0);
goto again;
}
}
}
free(pfh);
return (NULL);
}
So what's going on?
Warner
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100628.081458.18103541849609641.imp>
