funny waitpid behaviour in new vfs module

Jeremy Allison jra at
Mon Oct 10 16:45:46 GMT 2005

On Mon, Oct 10, 2005 at 08:28:40PM +0530, Raja Subramanian wrote:
> Hi,
> I'm developing a vfs module for samba 3.014a-3 (debian sarge).
> On file close/rename, my vfs module tries to validate files by calling
> a user specified validation program.  If the validation app fails, I
> simply return EACCES and the validation app takes care of deleting or
> renaming the file.
> I've got most of it going, except the validation phase where I have to
> fork/execl and wait for the exit status of the validation app.  I'm
> having problems with waitpid().
> The offending validate() code is below.  waitpid (magic.c line 96)
> bombs randomly with "ECHILD: No child processes".  However, my
> validation application (just an empty shell script with "exit 0") is
> always run.  If I test  validate() outside of samba, it works
> flawlessly.

Samba is eating your signal. Look at the SIGCLD handler in lib/signal.c

static void sig_cld(int signum)
        while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0)

         * Turns out it's *really* important not to
         * restore the signal handler here if we have real POSIX
         * signal handling. If we do, then we get the signal re-delivered
         * immediately - hey presto - instant loop ! JRA.

#if !defined(HAVE_SIGACTION)
        CatchSignal(SIGCLD, sig_cld);

Look at how this is done in lib/smbrun.c - it temporarily changes
the handler :


        if ((pid=sys_fork()) < 0) {

	... fork exec handling...

	while((wpid = sys_waitpid(pid,&status,0)) < 0) {

	... pid handling ....

	CatchChild(); <---- restores ignore child handling.

You need the same logic in your code.


More information about the samba-technical mailing list