Subject: Re: exit(-x) cleanup
To: None <email@example.com>
From: Greg A. Woods <firstname.lastname@example.org>
Date: 04/07/2001 14:18:59
[ On Friday, April 6, 2001 at 20:21:16 (-0700), Greywolf wrote: ]
> Subject: Re: exit(-x) cleanup
> If the original struct wait is any indication, it looks to me to be 0..127,
> with the top bit set if it was due to a signal delivery. At least it's that
> way without fiddling the exit value -- this is reflected in the fsck part of
> the startup scripts (130 -> stop_boot).
Careful there. The exit status is the high-order _8_ bits of the wait
status, and it contains the low-order 8 bits from the value passed to
exit(). Look at WEXITSTATUS() in <sys/wait.h>.
> I would think, then, that the exit values are NOT machine-dependent; else
> we'd have a HELL of a time keeping up with reality.
I don't know what the state of affairs is across all NetBSD ports, but I
seem to recall back when I was porting stuff (at least stuff which used
shell scripts and other interpreters that could be used to call other
programs) across many types of Unix and near-Unix that it was almost
impossible to portably extract any information other than "!= 0" from
the exit code of any program which tried to use a negative number with
exit(), even if it was careful never to wander outside of using 7 bits
In other words you literally cannot keep up with reality if the programs
you are calling pass negative numbers to exit(). What comes out of an
interpreter after the fact depends on the exact implementation of that
interpreter, and for some implementations on whether or not chars are
signed on the current platform.
In the V7 manual the meaning was clear that only those low-order 8 bits
were copied from the exit() parameter and so if every caller to wait()
is careful to avoid sign extension (as I believe the V7 shell was) then
a -1 turns into 255, at least on a PDP-11.
I think that in *BSD (i.e. including in NetBSD) the _W_INT() macro in
<sys/wait.h> will help prevent any sign extension.
Greg A. Woods
+1 416 218-0098 VE3TCP <email@example.com> <firstname.lastname@example.org>
Planix, Inc. <email@example.com>; Secrets of the Weird <firstname.lastname@example.org>