Package: moreutils
Version: 0.37
Severity: important

Hi,

It seems that parallel can return -1 in most of the cases for no
good reason.  All childs returned 0, and there were no other
errors.

The code looks like:
int wait_for_child(int options) {
        id_t id_ignored = 0;
        siginfo_t infop;

        infop.si_pid = 0;
        waitid(P_ALL, id_ignored, &infop, WEXITED | options);
        if (infop.si_pid == 0)
                return -1; /* Nothing to wait for */
        if (infop.si_code == CLD_EXITED)
                return infop.si_status;
        return 1;
}

And this return value is or'd between all calls.  

The first thing that looks wrong to this is that the return
value of waitid() is not checked.  The strace shows that
I have atleast 2 calls to it that return -1.  It most
likely still contains a pid of 0 in that case.  You really
don't want to return -1 for that.

An other reason that you could get that -1 is that you called
it with WNOHANG.  In that case you check for the value
being smaller than 0 and don't add it.  But I think values
smaller than 0 are valid, and so you can't tell the difference
between a child that exited and returning because you don't
want to wait.

I think the code will also behave wrong in case the child
did not call exit() itself but instead got killed or something.
In that case infop.si_code can be != CLD_EXITED, and you'd
want to consider that a reason to make parallel return an
non-zero exit code.


Kurt




-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to