diff options
author | nacitar sevaht <nacitar@ubercpp.com> | 2011-05-08 02:40:56 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2011-05-08 05:47:02 (GMT) |
commit | 2f166eb4aeb5d77407e9380d644215cd5e94d592 (patch) | |
tree | 8ddb3321158418d0af332bad8b82e6ea7bcd678a /util | |
parent | de2cca8988f43443f83f6f324c73d6ea03edfae3 (diff) | |
download | fluxbox-2f166eb4aeb5d77407e9380d644215cd5e94d592.zip fluxbox-2f166eb4aeb5d77407e9380d644215cd5e94d592.tar.bz2 |
fluxbox-remote now properly returns exit status
The previous check relied upon the (undocumented) return value of
XChangeProperty to determine the exit status; at least, on my gentoo system,
the function seems to return 1 even when it fails to change the property
due to contrived, and invalid, parameters. However, setting an error
handler allows proper detection of this case. So, now the return status
properly indicates whether or not the property was changed (but not
whether fluxbox liked the command!).
Diffstat (limited to 'util')
-rw-r--r-- | util/fluxbox-remote.cc | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/util/fluxbox-remote.cc b/util/fluxbox-remote.cc index 05f251a..5c66583 100644 --- a/util/fluxbox-remote.cc +++ b/util/fluxbox-remote.cc | |||
@@ -25,6 +25,14 @@ | |||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | #include <stdio.h> | 26 | #include <stdio.h> |
27 | 27 | ||
28 | bool g_gotError; | ||
29 | static int HandleIPCError(Display *disp, XErrorEvent*ptr) | ||
30 | { | ||
31 | // ptr->error_code contains the actual error flags | ||
32 | g_gotError=true; | ||
33 | return( 0 ); | ||
34 | } | ||
35 | |||
28 | int main(int argc, char **argv) { | 36 | int main(int argc, char **argv) { |
29 | 37 | ||
30 | if (argc <= 1) { | 38 | if (argc <= 1) { |
@@ -42,14 +50,21 @@ int main(int argc, char **argv) { | |||
42 | Window root = DefaultRootWindow(disp); | 50 | Window root = DefaultRootWindow(disp); |
43 | 51 | ||
44 | char *str = argv[1]; | 52 | char *str = argv[1]; |
45 | int ret = XChangeProperty(disp, root, fbcmd_atom, | 53 | |
54 | typedef int (*x_error_handler_t)(Display*,XErrorEvent*); | ||
55 | |||
56 | // assign the custom handler, clear the flag, sync the data, then check it for success/failure | ||
57 | x_error_handler_t handler = XSetErrorHandler( HandleIPCError ); | ||
58 | g_gotError=false; | ||
59 | XChangeProperty(disp, root, fbcmd_atom, | ||
46 | XA_STRING, 8, PropModeReplace, | 60 | XA_STRING, 8, PropModeReplace, |
47 | (unsigned char *) str, strlen(str)); | 61 | (unsigned char *) str, strlen(str)); |
48 | XCloseDisplay(disp); | 62 | XSync(disp,False); |
63 | int ret=(g_gotError?EXIT_FAILURE:EXIT_SUCCESS); | ||
64 | XSetErrorHandler(handler); | ||
49 | 65 | ||
50 | if (ret == Success) | 66 | XCloseDisplay(disp); |
51 | return EXIT_SUCCESS; | ||
52 | 67 | ||
53 | return EXIT_FAILURE; | 68 | return ret; |
54 | } | 69 | } |
55 | 70 | ||