summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Lebl <jirka@5z.com>2002-08-23 22:19:04 +0000
committerGeorge Lebl <jirka@src.gnome.org>2002-08-23 22:19:04 +0000
commit21f2a4f254fcc2a3f16ceafba5ee4bb8a94e9354 (patch)
tree32dd61a77ec6b0db7d4caeeec6f600369d059d69
parent7b7ea791668bba49c2436466a459d5893e9671f8 (diff)
downloadgdm-21f2a4f254fcc2a3f16ceafba5ee4bb8a94e9354.tar.gz
do a cool hack to figure out when the server restarts. Fork a process,
Fri Aug 23 15:27:55 2002 George Lebl <jirka@5z.com> * daemon/server.c: do a cool hack to figure out when the server restarts. Fork a process, open the display, HUP the server and have the process wait for an xioerror and die. * daemon/display.c: add some debugging
-rw-r--r--ChangeLog8
-rw-r--r--daemon/display.c3
-rw-r--r--daemon/server.c91
3 files changed, 84 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 7cf75687..e903076b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Aug 23 15:27:55 2002 George Lebl <jirka@5z.com>
+
+ * daemon/server.c: do a cool hack to figure out when the server
+ restarts. Fork a process, open the display, HUP the server and
+ have the process wait for an xioerror and die.
+
+ * daemon/display.c: add some debugging
+
Fri Aug 23 14:12:10 2002 George Lebl <jirka@5z.com>
* daemon/slave.c: Cleanup the exit stuff
diff --git a/daemon/display.c b/daemon/display.c
index e8fad437..04808f51 100644
--- a/daemon/display.c
+++ b/daemon/display.c
@@ -166,6 +166,9 @@ gdm_display_manage (GdmDisplay *d)
if ( ! gdm_display_check_loop (d))
return FALSE;
+ if (d->slavepid != 0)
+ gdm_debug ("gdm_display_manage: Old slave pid is %d", (int)d->slavepid);
+
/* If we have an old slave process hanging around, kill it */
gdm_sigchld_block_push ();
if (d->slavepid > 1 &&
diff --git a/daemon/server.c b/daemon/server.c
index 5d9ac3ef..e2a2bb13 100644
--- a/daemon/server.c
+++ b/daemon/server.c
@@ -88,6 +88,19 @@ gdm_server_wipe_cookies (GdmDisplay *disp)
disp->authfile_gdm = NULL;
}
+/* ignore handlers */
+static int
+ignore_xerror_handler (Display *disp, XErrorEvent *evt)
+{
+ return 0;
+}
+
+static int
+exit_xioerror_handler (Display *disp)
+{
+ _exit (1);
+}
+
/**
* gdm_server_reinit:
* @disp: Pointer to a GdmDisplay structure
@@ -99,6 +112,8 @@ gdm_server_wipe_cookies (GdmDisplay *disp)
void
gdm_server_reinit (GdmDisplay *disp)
{
+ pid_t pid;
+
if (disp == NULL)
return;
@@ -113,18 +128,65 @@ gdm_server_reinit (GdmDisplay *disp)
gdm_debug ("gdm_server_reinit: Server for %s is about to be reinitialized!", disp->name);
+ /* This hack below is beautiful BTW */
+
gdm_sigchld_block_push ();
- if (disp->servpid > 0)
- kill (disp->servpid, SIGHUP);
- gdm_sigchld_block_pop ();
-
- /* HACK! the Xserver can't really tell us when it got the hup signal,
- * so we are really stuck just going to sleep for a bit hoping that
- * the kernel will tell the X server and that will run, else we will
- * get whacked ourselves after we open the connection and we'll think
- * it's an X screwup, which is really OK to happen and will just
- * restart the Xserver, it's just more nasty. Oh how fun */
- sleep (1);
+
+ pid = gdm_fork_extra ();
+ if (pid < 1) {
+ /* So much work just because we can't fork */
+ if (disp->servpid > 0)
+ kill (disp->servpid, SIGHUP);
+
+ gdm_sigchld_block_push ();
+
+ /* HACK! the Xserver can't really tell us when it got the hup signal,
+ * so we are really stuck just going to sleep for a bit hoping that
+ * the kernel will tell the X server and that will run, else we will
+ * get whacked ourselves after we open the connection and we'll think
+ * it's an X screwup, which is really OK to happen and will just
+ * restart the Xserver, it's just more nasty. Oh how fun */
+ sleep (1);
+ } else if (pid == 0) {
+ Display *dsp;
+
+ closelog ();
+
+ /* close things */
+ gdm_close_all_descriptors (0 /* from */, -1 /* except */);
+
+ gdm_open_dev_null (O_RDONLY); /* open stdin - fd 0 */
+ gdm_open_dev_null (O_RDWR); /* open stdout - fd 1 */
+ gdm_open_dev_null (O_RDWR); /* open stderr - fd 2 */
+
+ XSetErrorHandler (ignore_xerror_handler);
+ XSetIOErrorHandler (exit_xioerror_handler);
+
+ gnome_setenv ("XAUTHORITY", d->authfile, TRUE);
+ dsp = XOpenDisplay (d->name);
+
+ /* Now whack the server with a SIGHUP */
+ if (disp->servpid > 0)
+ kill (disp->servpid, SIGHUP);
+
+ if (dsp == NULL) {
+ /* HACK, see note above */
+ sleep (1);
+ _exit (0);
+ } else {
+ /* Wait for an xioerror */
+ for (;;) {
+ XEvent event;
+ XNextEvent (dsp, &event);
+ }
+ }
+ /* anality */
+ _exit (0);
+ } else if (pid > 0) {
+ gdm_sigchld_block_pop ();
+
+ gdm_wait_for_extra (NULL);
+ }
}
/**
@@ -1127,13 +1189,6 @@ gdm_server_alloc (gint id, const gchar *command)
return d;
}
-/* ignore handlers */
-static int
-ignore_xerror_handler (Display *disp, XErrorEvent *evt)
-{
- return 0;
-}
-
void
gdm_server_whack_clients (GdmDisplay *disp)
{