all repos — fluxbox @ 2f166eb4aeb5d77407e9380d644215cd5e94d592

custom fork of the fluxbox windowmanager

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!).
nacitar sevaht nacitar@ubercpp.com
commit

2f166eb4aeb5d77407e9380d644215cd5e94d592

parent

de2cca8988f43443f83f6f324c73d6ea03edfae3

1 files changed, 20 insertions(+), 5 deletions(-)

jump to
M util/fluxbox-remote.ccutil/fluxbox-remote.cc

@@ -25,6 +25,14 @@ #include <string.h>

#include <stdlib.h> #include <stdio.h> +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 @@ Atom fbcmd_atom = XInternAtom(disp, "_FLUXBOX_ACTION", False);

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; }