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)"
Please post your `emerge --info' too.
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).