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!).
This commit is contained in:
nacitar sevaht 2011-05-07 21:40:56 -05:00 committed by Mathias Gumz
parent de2cca8988
commit 2f166eb4ae

View file

@ -25,6 +25,14 @@
#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 @@ 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));
XSync(disp,False);
int ret=(g_gotError?EXIT_FAILURE:EXIT_SUCCESS);
XSetErrorHandler(handler);
XCloseDisplay(disp);
if (ret == Success)
return EXIT_SUCCESS;
return EXIT_FAILURE;
return ret;
}