cyrusimap / cassandane

Other
6 stars 11 forks source link

Return an exit status even if we fork using a filehandle #53

Closed wolfsage closed 6 years ago

wolfsage commented 6 years ago

In some cases, run_command() would fork using a pipe:

    # Use the fork()ing form of open()
    my $pid = open $fh,'|-';
    die "Cannot fork: $!"
        if !defined $pid;
    if ($pid)
    {
        # parent process
        $self->_add_child($binary, $pid, $options->{handlers}, $fh);
        print $fh ${$data};
        close ($fh);
        return $pid;
    }

The problem is, the close ($fh) there waits for the child to exit, which means later in reap_command(), waitpid($pid, 0) returns -1 since there are no children, and our caller gets back undef.

This fixes that by returning the child status if we know we already have one and bypassing reap_command() entirely.

Solves #52

elliefm commented 6 years ago

Nice!

One of the tests in Delivery.pm now errors out, now that the non-zero exit code is actually noticed, so I'm adding a couple of commits to sort that out too.

elliefm commented 6 years ago

(added a7a624d and aa3943e fyi :) )

wolfsage commented 6 years ago

Awesome, thanks!