Date: Thu, 13 Oct 2011 12:54:38 +0200 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no> To: current@freebsd.org Cc: pjd@freebsd.org Subject: incorrect use of pidfile(3) Message-ID: <86pqi1b1qp.fsf@ds4.des.no>
next in thread | raw e-mail | index | archive | help
I looked at some of the programs that use pidfile(3) in base, and they
pretty much all get it wrong. Consider these two scenarios:
1) common case
process A process B
main()
pidfile_open() -> success
perform_initialization()
daemon()
pidfile_write() -> success
perform_work() main()
pidfile_open() -> EEXIST
exit()
2) very unlikely but still possible case
process A process B
main()
pidfile_open() -> success main()
perform_initialization() pidfile_open() -> EAGAIN
daemon() perform_initialization()
pidfile_write() -> success daemon()
perform_work() perform_work()
The problem is that most of them (at least the ones I checked) ignore a
pidfile_open() failure unless errno == EEXIST.
How do we fix this? My suggestion is to loop until pidfile_open()
succeeds or errno != EAGAIN. Does anyone have any objections to that
approach?
DES
--
Dag-Erling Smørgrav - des@des.no
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86pqi1b1qp.fsf>
