Bug 198903 - exit codes do not match errno
exit codes do not match errno
Product: Fedora
Classification: Fedora
Component: man-pages (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Marcela Mašláňová
Ben Levenson
: Reopened
Depends On:
  Show dependency treegraph
Reported: 2006-07-14 11:10 EDT by Steve Friedman
Modified: 2007-11-30 17:11 EST (History)
1 user (show)

See Also:
Fixed In Version: man-pages-2.36-2
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-07-20 07:23:58 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Steve Friedman 2006-07-14 11:10:19 EDT
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:
/sbin/route add dev eth0
/sbin/route add 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).
Comment 1 Tim Waugh 2006-07-14 12:01:03 EDT
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.
Comment 2 Steve Friedman 2006-07-14 12:46:48 EDT
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.
Comment 3 Marcela Mašláňová 2006-07-18 05:15:57 EDT
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.
Comment 4 Steve Friedman 2006-07-19 09:56:17 EDT
#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
Comment 5 Marcela Mašláňová 2006-07-20 07:23:58 EDT
Ok, I fixed it.
Comment 6 Marcela Mašláňová 2006-12-11 07:33:52 EST
Upstream solved it as not a bug. Changed.

Note You need to log in before you can comment on or make changes to this bug.