Add handler for fatal X server conditions

Unless X server failures are caught, these can cause a premature
exit of chansrv, giving it no chance to clean up. This is currently a
particular problem for fuser mounts.
master
matt335672 6 years ago
parent a9e2dcc99f
commit c467ba6b04

@ -1278,6 +1278,16 @@ segfault_signal_handler(int sig)
exit(0); exit(0);
} }
/*****************************************************************************/
static void
x_server_fatal_handler(void)
{
LOGM((LOG_LEVEL_INFO, "xserver_fatal_handler: entered......."));
/* At this point the X server has gone away. Dont make any X calls. */
xfuse_deinit();
exit(0);
}
/*****************************************************************************/ /*****************************************************************************/
static int static int
get_display_num_from_display(char *display_text) get_display_num_from_display(char *display_text)
@ -1576,6 +1586,9 @@ main(int argc, char **argv)
g_signal_child_stop(child_signal_handler); /* SIGCHLD */ g_signal_child_stop(child_signal_handler); /* SIGCHLD */
g_signal_segfault(segfault_signal_handler); g_signal_segfault(segfault_signal_handler);
/* Cater for the X server exiting unexpectedly */
xcommon_set_x_server_fatal_handler(x_server_fatal_handler);
LOGM((LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text)); LOGM((LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text));
if (g_display_num == 0) if (g_display_num == 0)

@ -28,6 +28,7 @@
#include "log.h" #include "log.h"
#include "clipboard.h" #include "clipboard.h"
#include "rail.h" #include "rail.h"
#include "xcommon.h"
/* /*
#undef LOG_LEVEL #undef LOG_LEVEL
@ -50,6 +51,9 @@ Atom g_utf8_string = 0;
Atom g_net_wm_name = 0; Atom g_net_wm_name = 0;
Atom g_wm_state = 0; Atom g_wm_state = 0;
static x_server_fatal_cb_type x_server_fatal_handler = 0;
/*****************************************************************************/ /*****************************************************************************/
static int static int
xcommon_error_handler(Display *dis, XErrorEvent *xer) xcommon_error_handler(Display *dis, XErrorEvent *xer)
@ -64,16 +68,27 @@ xcommon_error_handler(Display *dis, XErrorEvent *xer)
} }
/*****************************************************************************/ /*****************************************************************************/
/* The X server had an internal error. This is the last function called. /* Allow the caller to be notified on X server failure
Do any cleanup that needs to be done on exit, like removing temporary files. Specified callback can do any cleanup that needs to be done on exit,
like removing temporary files. This is the last function called.
Don't worry about memory leaks */ Don't worry about memory leaks */
#if 0 void
xcommon_set_x_server_fatal_handler(x_server_fatal_cb_type handler)
{
x_server_fatal_handler = handler;
}
/*****************************************************************************/
/* The X server had an internal error */
static int static int
xcommon_fatal_handler(Display *dis) xcommon_fatal_handler(Display *dis)
{ {
if (x_server_fatal_handler)
{
x_server_fatal_handler();
}
return 0; return 0;
} }
#endif
/*****************************************************************************/ /*****************************************************************************/
/* returns time in milliseconds /* returns time in milliseconds
@ -110,7 +125,7 @@ xcommon_init(void)
/* setting the error handlers can cause problem when shutting down /* setting the error handlers can cause problem when shutting down
chansrv on some xlibs */ chansrv on some xlibs */
XSetErrorHandler(xcommon_error_handler); XSetErrorHandler(xcommon_error_handler);
//XSetIOErrorHandler(xcommon_fatal_handler); XSetIOErrorHandler(xcommon_fatal_handler);
g_x_socket = XConnectionNumber(g_display); g_x_socket = XConnectionNumber(g_display);

@ -26,6 +26,8 @@
#define FORMAT_TO_BYTES(_format) \ #define FORMAT_TO_BYTES(_format) \
(_format) == 32 ? sizeof(long) : (_format) / 8 (_format) == 32 ? sizeof(long) : (_format) / 8
typedef void (*x_server_fatal_cb_type)(void);
int int
xcommon_get_local_time(void); xcommon_get_local_time(void);
int int
@ -34,5 +36,7 @@ int
xcommon_get_wait_objs(tbus* objs, int* count, int* timeout); xcommon_get_wait_objs(tbus* objs, int* count, int* timeout);
int int
xcommon_check_wait_objs(void); xcommon_check_wait_objs(void);
void
xcommon_set_x_server_fatal_handler(x_server_fatal_cb_type handler);
#endif #endif

Loading…
Cancel
Save