Re: incorrect use of pidfile(3)

看板FB_current作者時間14年前 (2011/10/13 21:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/10 (看更多)
--=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable After discussing this with pjd@ on IRC, I arrived at the attached patch, which increases the length of time pidfile_open() itself waits (I hadn't noticed that it already looped) and sets *pidptr to -1 if it fails to read a pid. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=pidfile_open-loop.diff Index: lib/libutil/pidfile.c =================================================================== --- lib/libutil/pidfile.c (revision 226271) +++ lib/libutil/pidfile.c (working copy) @@ -118,22 +118,19 @@ */ fd = flopen(pfh->pf_path, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode); - if (fd == -1) { - count = 0; + if (fd == -1 && errno == EWOULDBLOCK && pidptr != NULL) { + *pidptr = -1; + count = 20; rqtp.tv_sec = 0; rqtp.tv_nsec = 5000000; - if (errno == EWOULDBLOCK && pidptr != NULL) { - again: + for (;;) { errno = pidfile_read(pfh->pf_path, pidptr); - if (errno == 0) - errno = EEXIST; - else if (errno == EAGAIN) { - if (++count <= 3) { - nanosleep(&rqtp, 0); - goto again; - } - } + if (errno != EAGAIN || --count == 0) + break; + nanosleep(&rqtp, 0); } + if (errno == 0) + errno = EEXIST; free(pfh); return (NULL); } --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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): #1Ebk4FSY (FB_current)
討論串 (同標題文章)
文章代碼(AID): #1Ebk4FSY (FB_current)