Re: waitpid(), partitions

Linus Torvalds (Linus.Torvalds@cs.helsinki.fi)
Thu, 5 Oct 1995 07:53:16 +0200


Erik Troan: "waitpid(), partitions" (Oct 4, 15:26):
>
> Secondly, playing with SysVinit illuminated a odditiy of waitpid() on axp.
> It seems to return -10 instead of -1 if no child processes exist and/or no
> status information is avilable. Under i386 Linux, it returns -1 or 0 for those
> two cases.

You're right.. Interesting.

It seems to be a library question, though, because runnin the program
under gdb and single-stepping over the wait4() system call that it uses
reveals that the kernel will return

v0=10 /* errno=10, ECHILD */
a3=1 /* error marker */

which is what it should return. Instruction trace then shows

syscall4:

beq a3, 0x120000988 /* jump if no error */
subq zero, v0, v0 /* v0 = -v0 = -10 */
ret

which returns the -10 from the low-level system call.

Now, this emulates what Linux/i386 does: the low-level "int $0x80"
system call mechanism returns the negative errno as the return value.
That's kind of ok, even though it's silly to emulate this behaviour on
the alpha where the kernel returns better information about whether the
system call succeeded or not.

The problem is that __waitpid() which calls syscall4() doesn't test for
the error case, so -10 is returned all the way to the user program. On
the x86, waitpid() will do something like

if (retval < 0) {
errno = -retval;
retval = -1;
}

resulting in the correct error return.

Linus