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=F8rgrav <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=20pidfile_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 =3D flopen(pfh->pf_path, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode); if (fd =3D=3D -1) { ---> We take this path, fd =3D=3D -1. count =3D 0; rqtp.tv_sec =3D 0; rqtp.tv_nsec =3D 5000000; if (errno =3D=3D EWOULDBLOCK && pidptr !=3D NULL) { again: ---> and this one, so errno is EWOULDBLOCK errno =3D pidfile_read(pfh->pf_path, pidptr); ---> errno is 0 here, so if (errno =3D=3D 0) errno =3D EEXIST; ---> We return NULL with errno set toEEXIST = else if (errno =3D=3D EAGAIN) { if (++count <=3D 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>