Bug 198903

Summary: exit codes do not match errno
Product: [Fedora] Fedora Reporter: Steve Friedman <steve>
Component: man-pagesAssignee: Marcela Mašláňová <mmaslano>
Status: CLOSED NOTABUG QA Contact: Ben Levenson <benl>
Severity: medium Docs Contact:
Priority: medium    
Version: 4CC: meyering
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: All   
OS: Linux   
Fixed In Version: man-pages-2.36-2 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-07-20 11:23:58 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Steve Friedman 2006-07-14 15:10:19 UTC
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 16:01:03 UTC
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 16:46:48 UTC
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 09:15:57 UTC
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 13:56:17 UTC
#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 11:23:58 UTC
Ok, I fixed it.

Comment 6 Marcela Mašláňová 2006-12-11 12:33:52 UTC
Upstream solved it as not a bug. Changed.