incorrect use of pidfile(3)

Pawel Jakub Dawidek pjd at FreeBSD.org
Thu Oct 13 11:47:08 UTC 2011


On Thu, Oct 13, 2011 at 12:54:38PM +0200, Dag-Erling Smørgrav wrote:
> 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?

I think we already do that internally in pidfile_open(). Can you take a look at
the source and confirm that this is what you mean?

-- 
Pawel Jakub Dawidek                       http://www.wheelsystems.com
FreeBSD committer                         http://www.FreeBSD.org
Am I Evil? Yes, I Am!                     http://yomoli.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20111013/af157e4d/attachment.pgp


More information about the freebsd-current mailing list