Re: incorrect use of pidfile(3)

看板FB_current作者時間14年前 (2011/10/13 20:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/10 (看更多)
Pawel Jakub Dawidek <pjd@FreeBSD.org> writes: > Dag-Erling Sm=C3=B8rgrav <des@des.no> writes: > > How do we fix this? My suggestion is to loop until pidfile_open() > > succeeds or errno !=3D EAGAIN. Does anyone have any objections to that > > approach? > I think we already do that internally in pidfile_open(). Can you take a l= ook at > the source and confirm that this is what you mean? No, it doesn't; pidfile_open(3) returns NULL with errno =3D=3D EAGAIN if the pidfile is locked but empty, as is the case in the window between a successful pidfile_open(3) and the first pidfile_write(3). This is documented in the man page: [EAGAIN] Some process already holds the lock on the given pi= d=E2=80=90 file, but the file is truncated. Most likely, the existing daemon is writing new PID into the file. I have a patch that adds a pidfile to dhclient(8), where I do this: for (;;) { pidfile =3D pidfile_open(path_dhclient_pidfile, 0600, &othe= rpid); if (pidfile !=3D NULL || errno !=3D EAGAIN) break; sleep(1); } if (pidfile =3D=3D NULL) { if (errno =3D=3D EEXIST) error("dhclient already running, pid: %d.", otherpi= d); warning("Cannot open or create pidfile: %m"); } I'm not sure I agree with the common idiom (which I copied here) of ignoring all other errors than EEXIST, but that's a different story. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no _______________________________________________ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"
文章代碼(AID): #1EbjC0P9 (FB_current)
討論串 (同標題文章)
文章代碼(AID): #1EbjC0P9 (FB_current)