From 2f166eb4aeb5d77407e9380d644215cd5e94d592 Mon Sep 17 00:00:00 2001 From: nacitar sevaht Date: Sat, 7 May 2011 21:40:56 -0500 Subject: 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!). --- util/fluxbox-remote.cc | 25 ++++++++++++++++++++----- 1 file 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 @@ #include #include +bool g_gotError; +static int HandleIPCError(Display *disp, XErrorEvent*ptr) +{ + // ptr->error_code contains the actual error flags + g_gotError=true; + return( 0 ); +} + int main(int argc, char **argv) { if (argc <= 1) { @@ -42,14 +50,21 @@ int main(int argc, char **argv) { Window root = DefaultRootWindow(disp); char *str = argv[1]; - int ret = XChangeProperty(disp, root, fbcmd_atom, + + typedef int (*x_error_handler_t)(Display*,XErrorEvent*); + + // assign the custom handler, clear the flag, sync the data, then check it for success/failure + x_error_handler_t handler = XSetErrorHandler( HandleIPCError ); + g_gotError=false; + XChangeProperty(disp, root, fbcmd_atom, XA_STRING, 8, PropModeReplace, (unsigned char *) str, strlen(str)); - XCloseDisplay(disp); + XSync(disp,False); + int ret=(g_gotError?EXIT_FAILURE:EXIT_SUCCESS); + XSetErrorHandler(handler); - if (ret == Success) - return EXIT_SUCCESS; + XCloseDisplay(disp); - return EXIT_FAILURE; + return ret; } -- cgit v0.11.2