Bug 198903 - exit codes do not match errno
Summary: exit codes do not match errno
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: man-pages
Version: 4
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Marcela Mašláňová
QA Contact: Ben Levenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2006-07-14 15:10 UTC by Steve Friedman
Modified: 2007-11-30 22:11 UTC (History)
1 user (show)

Fixed In Version: man-pages-2.36-2
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-07-20 11:23:58 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

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:
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).

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.


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