Update of bug #68501 (group findutils):

             Assigned to:                    None => jay

    _______________________________________________________

Follow-up Comment #1:


> Despite the last paragraph, there's nothing stopping a script from running
> `exit 128` or higher to achieve the same result as receiving a fatal signal.

This is not correct.   The 128+n convention applies to the shell itself.  IOW
this is how it sets $?.  But, xargs doesn't use the shell to run programs.

The waitpid() and related system calls distinguish exit-due-to-fatal signal
from a normal call to exit() (or _exit() or Exit() or, in the case of Linux,
exit_group()).



horizon:~/source/GNU/findutils/git/gnu/compile/xargs$ for rv in   $(seq 0 255)
 ; do echo x | ./xargs bash -c "exit ${rv}; true {}" fnord; ev=$?; if [ $ev
-ne 123 ]; then printf '%3d -> %3d\n' "$rv" "$ev"; fi; done
  0 ->   0
./xargs: bash: exited with status 255; aborting
255 -> 124
horizon:~/source/GNU/findutils/git/gnu/compile/xargs$ for rv in   $(seq 0 255)
 ; do echo x | ./xargs -I{}  bash -c "exit ${rv}; true {}" fnord; ev=$?; if [
$ev -ne 123 ]; then printf '%3d -> %3d\n' "$rv" "$ev"; fi; done
  0 ->   0
./xargs: bash: exited with status 255; aborting
255 -> 124



The current behaviour is that the xargs exit status is 123 for all normal exit
values other than 0 and 255.  A child exit value of 0 caused GNU xargs to exit
with status 0 and a child exit value of 255 causes an exit status of 124.

It is possible that the exit status used in response to the utility exiting
with 255 is under-specified in POSIX.1-2024. POSIX.1-2024 requirements around
255:

> DESCRIPTION
> 
> The xargs utility shall then invoke the constructed command line and wait for
> its completion. This sequence shall be repeated until one of the following
> occurs:
> 
> [...]
> 
> o An invocation of a constructed command line returns an exit status of 255.
> 
> [...]
> 
> EXIT STATUS
> 
> The following exit values shall be returned:
> 
> 0 Successful completion.
> 1-125 A command line meeting the specified requirements could not be
> assembled, one or more of the invocations of utility returned a non-zero exit
> status, or some other error occurred.
> 126 The utility specified by utility was found but could not be invoked.
> 127 The utility specified by utility could not be found.
> 
> CONSEQUENCES OF ERRORS
> 
> If a command line meeting the specified requirements cannot be assembled, the
> utility cannot be invoked, an invocation of the utility is terminated by a
> signal, or an invocation of the utility exits with exit status 255, the xargs
> utility shall write a diagnostic message and exit without processing any
> remaining input.

So the diagnostic message and immediate stop are both required.  But there is
no explicit requirement above about the exit status.   Many POSIX utilities
are required to have a non-zero exit status after issuing a diagnostic, per
section 1.4 Utility Description Defaults of the "Shell & Utilities" section of
POSIX.1-2024 which says (see "Default Behavior"):

> STDERR
> 
> The STDERR section describes the standard error output of the utility. Only
> those messages that are purposely sent by the utility are described.
Use of a terminal for standard error may cause any of the standard utilities
that write standard error output to stop when used in the background. For this
reason, applications should not use interactive features in scripts to be
placed in the background.
> 
> The format of diagnostic messages for most utilities is unspecified, but the
> language and cultural conventions of diagnostic and informative messages
> whose format is unspecified by this volume of POSIX.1-2024 should be affected
> by the setting of LC_MESSAGES and [XSI] [Option Start] NLSPATH . [Option
> End]
> 
> The specified standard error output of standard utilities shall not depend on
> the existence or value of the environment variables defined in this volume of
> POSIX.1-2024, except as provided by this volume of POSIX.1-2024.
> 
> Default Behavior: When this section is listed as "The standard error shall be
> used only for diagnostic messages.", it means that, unless otherwise stated,
> the diagnostic messages shall be sent to the standard error only when the
> exit status indicates that an error occurred and the utility is used as
> described by this volume of POSIX.1-2024.
> 
> When this section is listed as "Not used.", it means that the standard error
> shall not be used when the utility is used as described in this volume of
> POSIX.1-2024.


However, the "Default Behavior" requirement doesn't apply to xargs because its
STDERR section doesn't state "The standard error shall be used only for
diagnostic messages." (because xargs' standard error is also used for other
things).

So, a narrow reading could even be that an exit status of 0 would be
standard-conforming.  However, I think would not be a helpful choice.

Anyway the current behaviour of xargs seems to be compliant to me.  Though the
remark in the manual page is perhaps confusing given that it spuriously
mentions the shell.



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?68501>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to