Date: Mon, 27 Apr 2009 02:20:04 GMT From: Garrett Cooper <gcooper@FreeBSD.org> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/124748: [patch] sh(1): sh -c 'exit -1' fails with "Illegal number: -1", instead of exiting with a code of 255 Message-ID: <200904270220.n3R2K4j1049951@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/124748; it has been noted by GNATS. From: Garrett Cooper <gcooper@FreeBSD.org> To: Garrett Cooper <gcooper@freebsd.org> Cc: Jilles Tjoelker <jilles@stack.nl>, bug-followup@freebsd.org Subject: Re: bin/124748: [patch] sh(1): sh -c 'exit -1' fails with "Illegal number: -1", instead of exiting with a code of 255 Date: Sun, 26 Apr 2009 18:49:38 -0700 On Sun, Apr 26, 2009 at 6:46 PM, Garrett Cooper <gcooper@freebsd.org> wrote= : > On Sun, Apr 26, 2009 at 7:40 AM, Jilles Tjoelker <jilles@stack.nl> wrote: >> Do people actually use 'exit -1' instead of the clearer 'exit 255'? '-1' >> is not an unsigned integer, so not a posix compliant parameter to the >> exit special builtin. Even then, sh still aborts a script with a nonzero >> exit code if exit is used wrongly like this. > > Some people do, but I've since then stopped doing this. > > The question I have is: > - Is the value of the return code uint8_t? > - Where in the documentation for sh(1) does it say that it can't be > <0? Here are all of the relevant documentation items for exit codes I > could find: > > =A0 Command Exit Status > =A0 =A0 Each command has an exit status that can influence the behavior o= f other > =A0 =A0 shell commands. =A0The paradigm is that a command exits with zero= for nor- > =A0 =A0 mal or success, and non-zero for failure, error, or a false indic= ation. > =A0 =A0 The man page for each command should indicate the various exit co= des and > =A0 =A0 what they mean. =A0Additionally, the built-in commands return exi= t codes, > =A0 =A0 as does an executed shell function. > > =A0 =A0 If a command is terminated by a signal, its exit status is 128 pl= us the > =A0 =A0 signal number. =A0Signal numbers are defined in the header file > =A0 =A0 <sys/signal.h>. > > ---- > > =A0 =A0 exit [exitstatus] > =A0 =A0 =A0 =A0 =A0 =A0 Terminate the shell process. =A0If exitstatus is = given it is used > =A0 =A0 =A0 =A0 =A0 =A0 as the exit status of the shell; otherwise the ex= it status of the > =A0 =A0 =A0 =A0 =A0 =A0 preceding command is used. > > ---- > > Nowhere in the above documentation does it mention valid limits being > in the set, [0, 128+SIGRTMAX] =3D> [0, 254]. It's merely implied by the > resources at one's disposal (the source, sys/signal.h, etc). > > Thanks, > -Garrett Furthermore, exit permits signed integers, which is a different -- much larger -- dataset of valid input values: EXIT(3) FreeBSD Library Functions Manual EXIT= (3) NAME exit, _Exit -- perform normal program termination LIBRARY Standard C Library (libc, -lc) SYNOPSIS #include <stdlib.h> void exit(int status); void _Exit(int status); Thanks, -Garrett
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904270220.n3R2K4j1049951>