After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 710791 - hotplug-command (run_custom_command) exit status isn't honored.
hotplug-command (run_custom_command) exit status isn't honored.
Status: RESOLVED FIXED
Product: gnome-settings-daemon
Classification: Core
Component: general
3.8.x
Other Linux
: Normal normal
: ---
Assigned To: gnome-settings-daemon-maint
gnome-settings-daemon-maint
Depends on:
Blocks:
 
 
Reported: 2013-10-24 11:50 UTC by danielpgb_vasquez
Modified: 2014-04-25 13:44 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description danielpgb_vasquez 2013-10-24 11:50:25 UTC
When a command exits with status 1 it doesn't stop gnome-settings-daemon from processing the input device.

Issue
=====
In run_custom_command, when spawned process exits with code 1, the exit_status variable is set to 256

Test:
echo -e '#include <stdlib.h>\nvoid main(){exit(1);}' > test_exit_code.c
gcc test_exit_code.c -o test_exit_code
dconf write /org/gnome/settings-daemon/peripherals/input-devices/hotplug-command "'`pwd`/text_exit_code'"

// Now run g-s-d inside gdb:
gdb --args /usr/libexec/gnome-settings-daemon
# Set breakpoint (the line is as found in Gnome 3.8.4
(gdb) b gsd-input-helper.c:531
(gdb) r
# Plug in device and wait for gdb to break 
(gdb) p exit_status
$1 = 256 # Should be 1.


Origin
=======
It appears that in POSIX the exit status has two bytes. The lowest byte is the signal that stopped the program if any. The highest byte is the exit status.

http://docs.python.org/2/library/os.html#os.wait
http://en.wikipedia.org/wiki/Exit_status#POSIX

It is the same for the input-device-example.sh in the g-s-d source code.
It also behaves the same for Python scripts:
echo -e '#!/usr/bin/python\nimport sys\nsys.exit(1)' > test_exit_code
gcc test_exit_code.c -o test_exit_code


Possible solutions
==================
Either:
* Change the semantics of run_custom_command to return TRUE if (exit_code!=0)
* Get actual error code with https://developer.gnome.org/glib/stable/glib-Spawning-Processes.html#g-spawn-check-exit-status
* Something else?

Daniel
Comment 1 danielpgb_vasquez 2013-10-24 12:03:59 UTC
I've just checked the master git code and the supposed mistake is there too.

blob: fc4f10cbde9c8e49e28af99bf1500d77617efe48
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/common/gsd-input-helper.c#n542

Daniel
PS: In previous msg, the "gcc test_exit_code.c -o test_exit_code" in the 'Origin' section is a harmful+useless copy/paste leftover.
Comment 2 Bastien Nocera 2014-04-25 13:44:05 UTC
commit 2329da7dad28f61109cecd8ca8ce93580f62f349
Author: Bastien Nocera <hadess@hadess.net>
Date:   Fri Apr 25 15:42:39 2014 +0200

    common: Check the exit status of hotplug scripts correctly
    
    Instead of comparing the shell's exit code by hand, use
    g_spawn_check_exit_status() to get the script's exit code.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710791

commit 8d8db8f796d9cdb9d9dee62de1bcb2ce1cef562f
Author: Bastien Nocera <hadess@hadess.net>
Date:   Fri Apr 25 15:41:42 2014 +0200

    common: Fix documentation for hotplug script
    
    The code at the bottom says we'll ignore further configuration if
    "1" is returned, but the top said if "0" is returned.
    
    Make both say "1".