Skip to content

Commit

Permalink
Keep a connection open when the X server is started
Browse files Browse the repository at this point in the history
  • Loading branch information
spanezz committed Jul 9, 2011
1 parent 1e42ea5 commit 2ebe57e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 0 additions & 2 deletions test-xstart.c
Expand Up @@ -48,8 +48,6 @@ int main(int argc, char* argv[])
return res;
}

sleep(3);

res = nodm_xserver_stop(&srv);
if (res != E_SUCCESS)
{
Expand Down
21 changes: 20 additions & 1 deletion xserver.c
Expand Up @@ -62,6 +62,7 @@
#include <X11/Xatom.h>
#include <stdint.h>
#include <stdio.h>
#include <setjmp.h>


// Signal handlers
Expand Down Expand Up @@ -233,6 +234,9 @@ int nodm_xserver_start(struct nodm_xserver* srv)

log_verb("X is ready to accept connections");

return_code = nodm_xserver_connect(srv);
if (return_code != E_SUCCESS) goto cleanup;

cleanup:
// Restore signal mask
if (signal_mask_altered)
Expand All @@ -251,6 +255,8 @@ int nodm_xserver_start(struct nodm_xserver* srv)

int nodm_xserver_stop(struct nodm_xserver* srv)
{
nodm_xserver_disconnect(srv);

int res = child_must_exit(srv->pid, "X server");
srv->pid = -1;

Expand Down Expand Up @@ -304,13 +310,26 @@ int nodm_xserver_connect(struct nodm_xserver* srv)
return srv->dpy == NULL ? E_X_SERVER_CONNECT : E_SUCCESS;
}

static jmp_buf close_env;
static int ignorexio(Display *dpy)
{
longjmp(close_env, 1);
// Not reached
return 0;
}

int nodm_xserver_disconnect(struct nodm_xserver* srv)
{
log_verb("disconnecting from X server");
// TODO: get/check pending errors (how?)
if (srv->dpy != NULL)
{
XCloseDisplay(srv->dpy);
XSetIOErrorHandler(ignorexio);
if (! setjmp(close_env))
XCloseDisplay(srv->dpy);
else
log_warn("I/O error on display close");
XSetIOErrorHandler(NULL);
srv->dpy = NULL;
}
return E_SUCCESS;
Expand Down

0 comments on commit 2ebe57e

Please sign in to comment.