flatpak / flatpak-xdg-utils

Simple portal-based commandline tools for use inside flatpak sandboxes
GNU Lesser General Public License v2.1
32 stars 14 forks source link

spawn: fix propagating exit code #10

Closed wjt closed 6 years ago

wjt commented 6 years ago

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.