Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 235296 - function system() from sys-libs/glibc-2.6.1 gives return values in wrong byte-order
Summary: function system() from sys-libs/glibc-2.6.1 gives return values in wrong byte...
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Gentoo Linux bug wranglers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-20 14:28 UTC by Guido Winkelmann
Modified: 2008-08-20 21:48 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Guido Winkelmann 2008-08-20 14:28:29 UTC
The system() function in glibc-2.6.1 seems to swap the first 2 bytes of the return code of executed commands.

For example, if you have a program that returns 2 as its return code, system() will give you the return code as 512 (Hex 0x0200).

Reproducible: Always

Steps to Reproduce:
1. Compile the following two test programs in your homedir as return2 and test, respectively:
return2.c:
----------
#include <stdlib.h>
int main(int argc, char **argv)
  {exit(2);}
----------

test.c:
----------
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
  int ret;
  ret = system("~/return2");
  printf("return code was %d (hex: %x)\n", ret, ret);
}
----------

2. Run ./test

Actual Results:  
"return code was 512 (hex: 200)"

Expected Results:  
"return code was 2 (hex: 2)"
Comment 1 Jeroen Roovers (RETIRED) gentoo-dev 2008-08-20 16:43:42 UTC
Please post your `emerge --info' too.
Comment 2 Harald van Dijk (RETIRED) gentoo-dev 2008-08-20 21:48:13 UTC
There's no need for emerge --info output.

Please take a look at the documentation; this is the correct behaviour.
From `man system`:

RETURN VALUE
       The value returned is -1 on error (e.g.  fork(2) failed), and the return status of the command otherwise.  This latter
       return  status is in the format specified in wait(2).  Thus, the exit code of the command will be WEXITSTATUS(status).