Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
spawn: fix propagating exit code #10
The exit status in the HostCommandExited/SpawnExited signal is as returned by waitpid(), which is a combination of flags indicating the way in which the process exited (or was SIGSTOPed or SIGCONTed) and the exit code or signal number. The exact layout is platform-specific, but on Linux the gist is:
The number passed to exit() is specified to be masked with 0xff to fall in the range [0, 255].
These are different numbers, so passing one where the other is expected does not work:
So, we need to use the macros from sys/wait.h to inspect the exit status and recover the exit code or signal. For normal termination, we can pass the exit code to exit(). For signals, our options are:
The latter is implemented here. It means that (for example) g_spawn_check_exit_status() reports "g-spawn-exit-error-quark: Child process exited with code 139 (139)" rather than "g-exec-error-quark: Child process killed by signal 11 (19)", but this is just the old behaviour, give or take the 0x80 bit always being set.