At 09:02 PM 12/17/99 -0400, Eric L. Brine wrote:
>Maybe a reaper is needed here?  From perlipc:
>
>    sub REAPER {
>        $waitedpid = wait;
>        # loathe sysV: it makes us not only reinstate
>        # the handler, but place it after the wait
>        $SIG{CHLD} = \&REAPER;
>    }
>    $SIG{CHLD} = \&REAPER;
>    # now do something that forks...

I think the close() does the wait, so I don't really need to worry about
reaping my children.

At 04:59 PM 12/17/99 -0800, Cliff Rayman wrote:
>How about closing it after you have reaped the child?
>
>local $SIG{CHLD}= sub {my $child=wait ; close PROG or log_message("close
>failed for program and $child $!");};

Then I seem to get "Bad file number" from the above error message, and "No
child processes" returned in $! from the close();

At 07:09 PM 12/17/99 -0600, Gerd Knops wrote:
>The SIGPIPE is coming from the child. If you can modify the child,
something  
>like $SIG{'CHLD'}=sub{exit(0)}; in the child would probably do the trick.

Well, I'm exec()ing a program I can't modify.  But isn't $SIG{CHLD} sent to
the parent?  I'm not sure the child would see the signal even if I could
trap the signal in the child.

Here's something that 'works':
     my $pid = open( PROG, "-|" );

     if ($pid) {
         while (<PROG>) {
             [..]
         }
     kill( 'HUP', $pid );
     wait;

But that's just a close() without checking the return from the close().  So
that's no good.

I'd like to check the return value of the close.  Perhaps the only solution
is to just use close(), and ignore a $? error of 13.  And if I use close()
I feel like it's less likely to leak in mod_perl.

      return if $? && ($? & 255) == 13;  # Ignore SIGPIPE
      log_message("Bad close on 'program' \$!=$! \$?=" . ($? & 255) );

Wish I understood this stuff more.



Bill Moseley
mailto:[EMAIL PROTECTED]

Reply via email to