funny waitpid behaviour in new vfs module

Raja Subramanian rajasuperman at gmail.com
Mon Oct 10 14:58:40 GMT 2005


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.


     70 static BOOL validate(vfs_handle_struct *handle, 
connection_struct *conn,  const char *fname)
     71 {
     72
     73     int status;
     74     pid_t pid, status_pid;
     75
     76     pid = fork();
     77
     78     switch(pid) {
     79
     80         case -1:        /* fork failed */
     81             /* TODO: log event */
     82             break;
     83
     84
     85         case 0:         /* child */
     86             /* TODO: may have to close all fds here */
     87             execl(validate_prog, validate_prog, fname, (char *) NULL);
     88
     89             /* if we get here, exec failed so kill child */
     90             _exit(1);
     91
     92             break;
     93
     94
     95         default:        /* parent */
     96             if (waitpid(pid, &status_pid, 0) == -1) {  /* BUG:
waitpid fails at random! */
     97                 syslog(0, "MAGIC: waitpid failed: %s", strerror(errno));
     98                 return False;
     99             }
    100
    101             if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
    102                 return True;
    103     }
    104
    105     return False;
    106 }


I have attached the entire source with build instructions in the README file.

Thanks in advance for your time!

- Raja
-------------- next part --------------
A non-text attachment was scrubbed...
Name: magic.tar.bz2
Type: application/x-bzip2
Size: 2380 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20051010/7002c518/magic.tar.bin


More information about the samba-technical mailing list