procmail
[Top] [All Lists]

Re: Calling procmail from program

1998-07-13 05:38:16
On 11 July 1998, Glenn W. Bach 
<glenn(_at_)dodgson(_dot_)wonderland(_dot_)caltech(_dot_)edu>
wrote:
I have a program that exec's procmail and pipes the data to it. I then
close the pipe. At this point shouldn't procmail receive the EOF,
process everything and terminate? It doesn't. It never delivers the
data, and it never quits. I'm forced to kill it myself which causes
procmail to give up.

    You didn't give us enough details about what exactly are you trying
to do, so I'll take a wild guess: you didn't close the "dead" ends of
the pipe in either the father or the child process.  A few systems will
allow you to get along with this (Solaris and SunOS come to mind), but
on most systems this will prevent the pipe from being destroyed, the
child will never see the EOF, and it won't die of "natural causes".

    Basically, you want something like this:


        int pipefd[2];
        int thepid;
        ...
        pipe (pipefd);
        ...
        /* set signals and so on */
        ...
        if ((thepid = fork ()) == 0)
        {
          ...
          /* reset signals in the child */
          ...
          close (pipefd[1]);    /* <--- closes the dead end */
          dup2 (pipefd[0], 0);
          close (pipefd[0]);    /* <--- not referenced any more */
          execlp ("procmail", "/usr/bin/procmail", ...);
          _exit (127);
        }
        /* reset signals in the parent */
        ...
        close (pipefd[0]);      /* <--- closes the dead end */
        while (...)
        {
          ...
          write (pipefd[1], ...);
          ...
        }
        close (pipefd[1]);      /* <--- sends EOF to the child and
                                 *      releases the pipe */
        waitpid (thepid, NULL, 0);
        ...


    Oh, and this is not exactly procmail-related, is it?

    Regards,

    Liviu

-- 
Dr. Liviu Daia                   e-mail:   daia(_at_)stoilow(_dot_)imar(_dot_)ro
Institute of Mathematics         web page: http://www.imar.ro/~daia
of the Romanian Academy          PGP key:  finger 
daia(_at_)stoilow(_dot_)imar(_dot_)ro

<Prev in Thread] Current Thread [Next in Thread>