handle X server crash better

ulab-original
jsorg71 15 years ago
parent 359a190850
commit c7838641cf

@ -17,6 +17,7 @@
Copyright (C) Jay Sorg 2009 Copyright (C) Jay Sorg 2009
*/ */
#include <X11/Xlib.h>
#include "arch.h" #include "arch.h"
#include "os_calls.h" #include "os_calls.h"
#include "thread_calls.h" #include "thread_calls.h"
@ -42,6 +43,8 @@ int g_cliprdr_chan_id = -1; /* cliprdr */
int g_rdpsnd_chan_id = -1; /* rdpsnd */ int g_rdpsnd_chan_id = -1; /* rdpsnd */
int g_rdpdr_chan_id = -1; /* rdpdr */ int g_rdpdr_chan_id = -1; /* rdpdr */
Display* g_display = 0;
/*****************************************************************************/ /*****************************************************************************/
/* returns error */ /* returns error */
int APP_CC int APP_CC
@ -550,6 +553,19 @@ get_display_num_from_display(char* display_text)
return 0; return 0;
} }
/*****************************************************************************/
/* The X server had an internal error. This is the last function called.
Do any cleanup that needs to be done on exit, like removing temporary files.
Don't worry about memory leaks */
int DEFAULT_CC
my_fatal_handler(Display* dis)
{
g_writeln("xrdp-chansrv: fatal error, exiting");
g_delete_wait_obj(g_term_event);
g_delete_wait_obj(g_thread_done_event);
return 0;
}
/*****************************************************************************/ /*****************************************************************************/
int DEFAULT_CC int DEFAULT_CC
main(int argc, char** argv) main(int argc, char** argv)
@ -574,6 +590,13 @@ main(int argc, char** argv)
return 1; return 1;
} }
g_writeln("xrdp-chansrv: main: using DISPLAY %d", g_display_num); g_writeln("xrdp-chansrv: main: using DISPLAY %d", g_display_num);
g_display = XOpenDisplay(0);
if (g_display == 0)
{
g_writeln("xrdp-chansrv: main: XOpenDisplay failed");
return 1;
}
XSetIOErrorHandler(my_fatal_handler);
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid); g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
g_term_event = g_create_wait_obj(text); g_term_event = g_create_wait_obj(text);
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid); g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid);

@ -30,7 +30,6 @@
#include "os_calls.h" #include "os_calls.h"
#include "chansrv.h" #include "chansrv.h"
static Display* g_display = 0;
static Atom g_clipboard_atom = 0; static Atom g_clipboard_atom = 0;
static Atom g_clip_property_atom = 0; static Atom g_clip_property_atom = 0;
static Atom g_timestamp_atom = 0; static Atom g_timestamp_atom = 0;
@ -45,7 +44,6 @@ static Window g_wnd = 0;
static Screen* g_screen = 0; static Screen* g_screen = 0;
static int g_screen_num = 0; static int g_screen_num = 0;
static int g_xfixes_event_base = 0; static int g_xfixes_event_base = 0;
static int g_sck_closed = 0;
static int g_last_clip_size = 0; static int g_last_clip_size = 0;
static char* g_last_clip_data = 0; static char* g_last_clip_data = 0;
@ -55,6 +53,7 @@ static int g_got_selection = 0; /* boolean */
static Time g_selection_time = 0; static Time g_selection_time = 0;
extern int g_cliprdr_chan_id; /* in chansrv.c */ extern int g_cliprdr_chan_id; /* in chansrv.c */
extern Display* g_display;
/*****************************************************************************/ /*****************************************************************************/
/* returns time in miliseconds /* returns time in miliseconds
@ -86,13 +85,6 @@ clipboard_init(void)
return 0; return 0;
} }
rv = 0; rv = 0;
g_sleep(500);
g_display = XOpenDisplay(0);
if (g_display == 0)
{
g_writeln("xrdp-chansrv: clipboard_init: XOpenDisplay failed");
rv = 1;
}
if (rv == 0) if (rv == 0)
{ {
g_x_socket = XConnectionNumber(g_display); g_x_socket = XConnectionNumber(g_display);
@ -185,17 +177,11 @@ clipboard_deinit(void)
{ {
return 0; return 0;
} }
if (!g_sck_closed) g_delete_wait_obj_from_socket(g_x_wait_obj);
{ g_x_wait_obj = 0;
g_delete_wait_obj_from_socket(g_x_wait_obj); XDestroyWindow(g_display, g_wnd);
g_x_wait_obj = 0; g_wnd = 0;
XDestroyWindow(g_display, g_wnd); g_x_socket = 0;
g_wnd = 0;
XCloseDisplay(g_display);
g_display = 0;
g_x_socket = 0;
g_sck_closed = 1;
}
g_free(g_last_clip_data); g_free(g_last_clip_data);
g_last_clip_data = 0; g_last_clip_data = 0;
g_clip_up = 0; g_clip_up = 0;
@ -700,10 +686,6 @@ clipboard_get_wait_objs(tbus* objs, int* count, int* timeout)
{ {
return 0; return 0;
} }
if (g_sck_closed)
{
return 0;
}
lcount = *count; lcount = *count;
objs[lcount] = g_x_wait_obj; objs[lcount] = g_x_wait_obj;
lcount++; lcount++;
@ -721,17 +703,12 @@ clipboard_check_wait_objs(void)
{ {
return 0; return 0;
} }
if (g_sck_closed)
{
return 0;
}
if (g_is_wait_obj_set(g_x_wait_obj)) if (g_is_wait_obj_set(g_x_wait_obj))
{ {
if (XPending(g_display) < 1) if (XPending(g_display) < 1)
{ {
/* something is wrong, should not get here */ /* something is wrong, should not get here */
g_writeln("xrdp-chansrv: clipboard_check_wait_objs: sck closed"); g_writeln("xrdp-chansrv: clipboard_check_wait_objs: sck closed");
g_sck_closed = 1;
return 0; return 0;
} }
while (XPending(g_display) > 0) while (XPending(g_display) > 0)

Loading…
Cancel
Save