[NPTH] npth and fork

NIIBE Yutaka gniibe at fsij.org
Mon Oct 3 03:13:20 CEST 2016


On 10/01/2016 05:33 PM, NIIBE Yutaka wrote:
> * PROPOSAL
> 
> It is better to use unnamed private semaphore for all OSes.  For
> macOS, I think that the semaphore in "Grand Central Dispatch" instead
> of POSIX named semaphore is good.
> 
> Note that Grand Central Dispatch implementation also prohibits use of
> semaphore after fork.
> 
> For those OSes which prohibits use of
> already-allocated-semaphore-by-parent after fork, we call
> pthread_atfork at npth_init; We setup a callback for child.  In the
> callback for child, the child process initializes a unnamed semaphore,
> so that threads can be controlled by the semaphore.

Considering again, it is best to document in nPth that fork is only
allowed in a way that child will soon exec another program under
the condition of no nPth access.

The specific use case of fork to daemonize a program should be done
_before_ calling npth_init, ideally.

I'm going to examine code of gpg-agent and scdaemon if fix is easy.
-- 



More information about the Gnupg-devel mailing list