[bug #68501] Manual unclear about exit codes 128 through 254

James Youngman <[email protected]> Mon, 6 Jul 2026 10:39:55 -0400 (EDT)
Newsgroups gmane.comp.gnu.findutils.bugs
Message-ID <[email protected]>
--8323329-424238335-1783348795=:680485
Content-Type: TEXT/plain; CHARSET=utf-8
Content-Transfer-Encoding: QUOTED-PRINTABLE
Content-Disposition: inline

Update of bug #68501 (group findutils):=0A=0A             Assigned to:     =
               None =3D> jay=0A=0A    _____________________________________=
__________________=0A=0AFollow-up Comment #1:=0A=0A=0A> Despite the last pa=
ragraph, there's nothing stopping a script from running=0A> `exit 128` or h=
igher to achieve the same result as receiving a fatal signal.=0A=0AThis is =
not correct.   The 128+n convention applies to the shell itself.  IOW=0Athi=
s is how it sets $?.  But, xargs doesn't use the shell to run programs.=0A=
=0AThe waitpid() and related system calls distinguish exit-due-to-fatal sig=
nal=0Afrom a normal call to exit() (or _exit() or Exit() or, in the case of=
 Linux,=0Aexit_group()).=0A=0A=0A=0Ahorizon:~/source/GNU/findutils/git/gnu/=
compile/xargs$ for rv in   $(seq 0 255)=0A ; do echo x | ./xargs bash -c "e=
xit ${rv}; true {}" fnord; ev=3D$?; if [ $ev=0A-ne 123 ]; then printf '%3d =
-> %3d\n' "$rv" "$ev"; fi; done=0A  0 ->   0=0A./xargs: bash: exited with s=
tatus 255; aborting=0A255 -> 124=0Ahorizon:~/source/GNU/findutils/git/gnu/c=
ompile/xargs$ for rv in   $(seq 0 255)=0A ; do echo x | ./xargs -I{}  bash =
-c "exit ${rv}; true {}" fnord; ev=3D$?; if [=0A$ev -ne 123 ]; then printf =
'%3d -> %3d\n' "$rv" "$ev"; fi; done=0A  0 ->   0=0A./xargs: bash: exited w=
ith status 255; aborting=0A255 -> 124=0A=0A=0A=0AThe current behaviour is t=
hat the xargs exit status is 123 for all normal exit=0Avalues other than 0 =
and 255.  A child exit value of 0 caused GNU xargs to exit=0Awith status 0 =
and a child exit value of 255 causes an exit status of 124.=0A=0AIt is poss=
ible that the exit status used in response to the utility exiting=0Awith 25=
5 is under-specified in POSIX.1-2024. POSIX.1-2024 requirements around=0A25=
5:=0A=0A> DESCRIPTION=0A> =0A> The xargs utility shall then invoke the cons=
tructed command line and wait for=0A> its completion. This sequence shall b=
e repeated until one of the following=0A> occurs:=0A> =0A> [...]=0A> =0A> o=
 An invocation of a constructed command line returns an exit status of 255.=
=0A> =0A> [...]=0A> =0A> EXIT STATUS=0A> =0A> The following exit values sha=
ll be returned:=0A> =0A> 0 Successful completion.=0A> 1-125 A command line =
meeting the specified requirements could not be=0A> assembled, one or more =
of the invocations of utility returned a non-zero exit=0A> status, or some =
other error occurred.=0A> 126 The utility specified by utility was found bu=
t could not be invoked.=0A> 127 The utility specified by utility could not =
be found.=0A> =0A> CONSEQUENCES OF ERRORS=0A> =0A> If a command line meetin=
g the specified requirements cannot be assembled, the=0A> utility cannot be=
 invoked, an invocation of the utility is terminated by a=0A> signal, or an=
 invocation of the utility exits with exit status 255, the xargs=0A> utilit=
y shall write a diagnostic message and exit without processing any=0A> rema=
ining input.=0A=0ASo the diagnostic message and immediate stop are both req=
uired.  But there is=0Ano explicit requirement above about the exit status.=
   Many POSIX utilities=0Aare required to have a non-zero exit status after=
 issuing a diagnostic, per=0Asection 1.4 Utility Description Defaults of th=
e "Shell & Utilities" section of=0APOSIX.1-2024 which says (see "Default Be=
havior"):=0A=0A> STDERR=0A> =0A> The STDERR section describes the standard =
error output of the utility. Only=0A> those messages that are purposely sen=
t by the utility are described.=0AUse of a terminal for standard error may =
cause any of the standard utilities=0Athat write standard error output to s=
top when used in the background. For this=0Areason, applications should not=
 use interactive features in scripts to be=0Aplaced in the background.=0A> =
=0A> The format of diagnostic messages for most utilities is unspecified, b=
ut the=0A> language and cultural conventions of diagnostic and informative =
messages=0A> whose format is unspecified by this volume of POSIX.1-2024 sho=
uld be affected=0A> by the setting of LC_MESSAGES and [XSI] [Option Start] =
NLSPATH . [Option=0A> End]=0A> =0A> The specified standard error output of =
standard utilities shall not depend on=0A> the existence or value of the en=
vironment variables defined in this volume of=0A> POSIX.1-2024, except as p=
rovided by this volume of POSIX.1-2024.=0A> =0A> Default Behavior: When thi=
s section is listed as "The standard error shall be=0A> used only for diagn=
ostic messages.", it means that, unless otherwise stated,=0A> the diagnosti=
c messages shall be sent to the standard error only when the=0A> exit statu=
s indicates that an error occurred and the utility is used as=0A> described=
 by this volume of POSIX.1-2024.=0A> =0A> When this section is listed as "N=
ot used.", it means that the standard error=0A> shall not be used when the =
utility is used as described in this volume of=0A> POSIX.1-2024.=0A=0A=0AHo=
wever, the "Default Behavior" requirement doesn't apply to xargs because it=
s=0ASTDERR section doesn't state "The standard error shall be used only for=
=0Adiagnostic messages." (because xargs' standard error is also used for ot=
her=0Athings).=0A=0ASo, a narrow reading could even be that an exit status =
of 0 would be=0Astandard-conforming.  However, I think would not be a helpf=
ul choice.=0A=0AAnyway the current behaviour of xargs seems to be compliant=
 to me.  Though the=0Aremark in the manual page is perhaps confusing given =
that it spuriously=0Amentions the shell.=0A=0A=0A=0A    ___________________=
____________________________________=0A=0AReply to this item at:=0A=0A  <ht=
tps://savannah.gnu.org/bugs/?68501>=0A=0A__________________________________=
_____________=0AMessage sent via Savannah=0Ahttps://savannah.gnu.org/=0A
--8323329-424238335-1783348795=:680485
Content-Type: APPLICATION/pgp-signature; name=signature.asc

-----BEGIN PGP SIGNATURE-----

iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCaku+OwAKCRCqLAuaBUf3
TkKDAP4p3Oa95vhq41V3VRsri9w9pK7bx9vp83m8sPcBjRJflQD/b9b6i4CtSasD
V4+SGQYLW800JA2Zi+3kJ35RdhCEBAM=
=IF9J
-----END PGP SIGNATURE-----

--8323329-424238335-1783348795=:680485--