Description of problem: The exit codes of various coreutils routines do not match the errno.h value for that failue. Version-Release number of selected component (if applicable): tested on FC1-FC4 (what I have around here). How reproducible: Every time. Steps to Reproduce: Example 1: mkdir asdf rm asdf/* echo $? Example 2: su /sbin/route add 10.1.2.3 dev eth0 /sbin/route add 10.1.2.3 dev eth0 echo $? Actual results: Example 1 returns 1 Example 2 returns 7 Expected results: Example 1 prints out "No such file or directory" which is errno=2, but returns 1 Example 2 prints out "File exists" which is errno=17, but returns 7 Additional info: Also, "man 2 wait" indicates for WEXITSTATUS that the return code is the least 8 bits; however, it is actually the bits 16-8 (if lsb is bit 1).
Example 1 (rm): the info page states: An exit status of zero indicates success, and a nonzero value indicates failure. Nothing is guaranteed except zero or non-zero. -> NOTABUG Example 2 (route): route is not a coreutils program; besides, the man page does not specify any special exit codes so again you only get to rely on zero or non-zero. -> NOTABUG 'man 2 wait' problem: 'rpm -qf $(man -W 2 wait)' shows that the man page comes from the man-pages package. Reassigning.
I am quite aware that the man pages does not specify any behavior. However, if the command is called by via system() and then then strerror() is called on the resultant error, a misleading cause is logged. Mark it a feature request and ship it upstream, at least.
Additional info: Also, "man 2 wait" indicates for WEXITSTATUS that the return code is the least 8 bits; however, it is actually the bits 16-8 (if lsb is bit 1). Status has range 0-255 and in library used for WEXITSTATUS is written least significant 8 bits. So I think it's OK. If you have some code, where is more bits, send it here please.
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> int main( int argc, char *argv[]) { int retval = system("asdf"); printf("retval=%d=0x%X WEXITSTATUS(retval)=%d\n", retval, retval, WEXITSTATUS(retval)); } This prints out: sh: line 1: asdf: command not found retval=32512=7F00 WEXITSTATUS(retval)=127
Ok, I fixed it.
Upstream solved it as not a bug. Changed.