diff options
author | George Lebl <jirka@5z.com> | 2002-08-23 21:03:27 +0000 |
---|---|---|
committer | George Lebl <jirka@src.gnome.org> | 2002-08-23 21:03:27 +0000 |
commit | 7b7ea791668bba49c2436466a459d5893e9671f8 (patch) | |
tree | 0d4ecc8fd410d3ccd078fd651d12da52bf610b86 | |
parent | 6028ae111b90eb8da0b75b46aed73dfbc37980fd (diff) | |
download | gdm-7b7ea791668bba49c2436466a459d5893e9671f8.tar.gz |
Cleanup the exit stuff
Fri Aug 23 14:12:10 2002 George Lebl <jirka@5z.com>
* daemon/slave.c: Cleanup the exit stuff
* daemon/display.c, daemon/gdm.c: don't do setsid on -nodaemon
as that breaks running from init and do it for the slave as
that's correct.
* daemon/slave.c, daemon/display.c, daemon/gdm.c: Cleanup
killing children a bit, and session cleanup stuff. Don't
kill pids not greater then 1 to be extra anal and if we can't
fork the slave set the pid to 0 and not leave it at -1.
* daemon/server.c: kill redundant line
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | daemon/display.c | 20 | ||||
-rw-r--r-- | daemon/gdm.c | 43 | ||||
-rw-r--r-- | daemon/server.c | 1 | ||||
-rw-r--r-- | daemon/slave.c | 188 |
5 files changed, 99 insertions, 168 deletions
@@ -1,3 +1,18 @@ +Fri Aug 23 14:12:10 2002 George Lebl <jirka@5z.com> + + * daemon/slave.c: Cleanup the exit stuff + + * daemon/display.c, daemon/gdm.c: don't do setsid on -nodaemon + as that breaks running from init and do it for the slave as + that's correct. + + * daemon/slave.c, daemon/display.c, daemon/gdm.c: Cleanup + killing children a bit, and session cleanup stuff. Don't + kill pids not greater then 1 to be extra anal and if we can't + fork the slave set the pid to 0 and not leave it at -1. + + * daemon/server.c: kill redundant line + Fri Aug 23 11:04:38 2002 George Lebl <jirka@5z.com> * daemon/gdm.[ch], daemon/slave.c, gui/gdmlogin.c, diff --git a/daemon/display.c b/daemon/display.c index c21eb0f8..e8fad437 100644 --- a/daemon/display.c +++ b/daemon/display.c @@ -166,19 +166,19 @@ gdm_display_manage (GdmDisplay *d) if ( ! gdm_display_check_loop (d)) return FALSE; - gdm_sigchld_block_push (); - /* If we have an old slave process hanging around, kill it */ - if (d->slavepid > 0 && - kill (d->slavepid, SIGINT) == 0) - ve_waitpid_no_signal (d->slavepid, 0, 0); + gdm_sigchld_block_push (); + if (d->slavepid > 1 && + kill (d->slavepid, SIGTERM) == 0) + ve_waitpid_no_signal (d->slavepid, 0, 0); d->slavepid = 0; + gdm_sigchld_block_pop (); /* Fork slave process */ + gdm_sigchld_block_push (); gdm_sigterm_block_push (); pid = d->slavepid = fork (); gdm_sigterm_block_push (); - gdm_sigchld_block_pop (); switch (pid) { @@ -186,6 +186,11 @@ gdm_display_manage (GdmDisplay *d) case 0: setpgid (0, 0); + /* Make the slave it's own leader. This 1) makes killing -pid of + * the daemon work more sanely because the daemon can whack the + * slave much better itself */ + setsid (); + d->slavepid = getpid (); /* Close XDMCP fd in slave process */ @@ -238,6 +243,7 @@ gdm_display_manage (GdmDisplay *d) break; case -1: + d->slavepid = 0; gdm_error (_("gdm_display_manage: Failed forking gdm slave process for %s"), d->name); return FALSE; @@ -279,7 +285,7 @@ gdm_display_unmanage (GdmDisplay *d) /* Kill slave */ gdm_sigchld_block_push (); - if (d->slavepid > 0 && + if (d->slavepid > 1 && kill (d->slavepid, SIGTERM) == 0) ve_waitpid_no_signal (d->slavepid, 0, 0); d->slavepid = 0; diff --git a/daemon/gdm.c b/daemon/gdm.c index 7c812b30..a635a858 100644 --- a/daemon/gdm.c +++ b/daemon/gdm.c @@ -1019,26 +1019,22 @@ gdm_cleanup_children (void) gdm_debug ("gdm_cleanup_children: Slave crashed, killing it's " "children"); - if (d->sesspid > 0) { - if (kill (d->sesspid, SIGTERM) == 0) + if (d->sesspid > 1 && + kill (d->sesspid, SIGTERM) == 0) ve_waitpid_no_signal (d->sesspid, NULL, 0); - d->sesspid = 0; - } - if (d->greetpid > 0) { - if (kill (d->greetpid, SIGTERM) == 0) + d->sesspid = 0; + if (d->greetpid > 1 && + kill (d->greetpid, SIGTERM) == 0) ve_waitpid_no_signal (d->greetpid, NULL, 0); - d->greetpid = 0; - } - if (d->chooserpid > 0) { - if (kill (d->chooserpid, SIGTERM) == 0) + d->greetpid = 0; + if (d->chooserpid > 1 && + kill (d->chooserpid, SIGTERM) == 0) ve_waitpid_no_signal (d->chooserpid, NULL, 0); - d->chooserpid = 0; - } - if (d->servpid > 0) { - if (kill (d->servpid, SIGTERM) == 0) + d->chooserpid = 0; + if (d->servpid > 1 && + kill (d->servpid, SIGTERM) == 0) ve_waitpid_no_signal (d->servpid, NULL, 0); - d->servpid = 0; - } + d->servpid = 0; } /* null all these, they are not valid most definately */ @@ -1465,7 +1461,7 @@ main (int argc, char *argv[]) if (pf != NULL && fscanf (pf, "%d", &pidv) == 1 && - kill (pidv, 0) != -1 && + kill (pidv, 0) == 0 && linux_only_is_running (pidv)) { /* make sure the pid file doesn't get wiped */ GdmPidFile = NULL; @@ -1486,9 +1482,6 @@ main (int argc, char *argv[]) fclose (pf); } - /* ignore failing, it MAY fail if it is already the leader */ - setsid (); - chdir (GdmServAuthDir); umask (022); } @@ -1650,7 +1643,7 @@ send_slave_ack (GdmDisplay *d) write (d->master_notify_fd, not, 2); } gdm_sigchld_block_push (); - if (d->slavepid > 0) { + if (d->slavepid > 1) { kill (d->slavepid, SIGUSR2); } gdm_sigchld_block_pop (); @@ -1667,7 +1660,7 @@ send_slave_command (GdmDisplay *d, const char *command) g_free (cmd); } gdm_sigchld_block_push (); - if (d->slavepid > 0) { + if (d->slavepid > 1) { kill (d->slavepid, SIGUSR2); } gdm_sigchld_block_pop (); @@ -2004,7 +1997,7 @@ gdm_handle_message (GdmConnection *conn, const char *msg, gpointer data) for (li = displays; li != NULL; li = li->next) { GdmDisplay *d = li->data; gdm_sigchld_block_push (); - if (d->greetpid > 0) + if (d->greetpid > 1) kill (d->greetpid, SIGHUP); gdm_sigchld_block_pop (); } @@ -2385,7 +2378,7 @@ notify_displays_int (const char *key, int val) "%c%s %d\n", GDM_SLAVE_NOTIFY_KEY, key, val); gdm_sigchld_block_push (); - if (disp->slavepid > 0) + if (disp->slavepid > 1) kill (disp->slavepid, SIGUSR2); gdm_sigchld_block_pop (); } @@ -2403,7 +2396,7 @@ notify_displays_string (const char *key, const char *val) "%c%s %s\n", GDM_SLAVE_NOTIFY_KEY, key, val); gdm_sigchld_block_push (); - if (disp->slavepid > 0) + if (disp->slavepid > 1) kill (disp->slavepid, SIGUSR2); gdm_sigchld_block_pop (); } diff --git a/daemon/server.c b/daemon/server.c index f6bc89c3..5d9ac3ef 100644 --- a/daemon/server.c +++ b/daemon/server.c @@ -1097,7 +1097,6 @@ gdm_server_alloc (gint id, const gchar *command) d->dispnum = id; d->servpid = 0; d->servstat = SERVER_DEAD; - d->sessionid = 0; d->sesspid = 0; d->slavepid = 0; d->type = TYPE_LOCAL; diff --git a/daemon/slave.c b/daemon/slave.c index 2fc24208..96dc1652 100644 --- a/daemon/slave.c +++ b/daemon/slave.c @@ -144,7 +144,6 @@ static void gdm_slave_greeter (void); static void gdm_slave_chooser (void); static void gdm_slave_session_start (void); static void gdm_slave_session_stop (pid_t sesspid); -static void gdm_slave_session_cleanup (void); static void gdm_slave_alrm_handler (int sig); static void gdm_slave_term_handler (int sig); static void gdm_slave_child_handler (int sig); @@ -597,7 +596,6 @@ gdm_slave_run (GdmDisplay *display) /* something may have gone wrong, try xfailed, if local (non-flexi), * the toplevel loop of death will handle us */ if (d->handled && d->dsp == NULL) { - gdm_server_stop (d); if (d->type == TYPE_LOCAL) gdm_slave_quick_exit (DISPLAY_XFAILED); else @@ -2759,8 +2757,7 @@ gdm_slave_session_start (void) "is not possible to log in. Please contact\n" "your system administrator")); - gdm_slave_session_stop (0); - gdm_slave_session_cleanup (); + gdm_slave_session_stop (FALSE /* run_post_session */); gdm_slave_quick_exit (DISPLAY_REMANAGE); } @@ -2861,13 +2858,13 @@ gdm_slave_session_start (void) gdm_debug ("gdm_slave_session_start: Session ended OK"); - gdm_slave_session_stop (pid); - gdm_slave_session_cleanup (); + gdm_slave_session_stop (pid != 0); } +/* Stop any in progress sessions */ static void -gdm_slave_session_stop (pid_t sesspid) +gdm_slave_session_stop (gboolean run_post_session) { struct passwd *pwent; char *x_servers_file; @@ -2888,19 +2885,22 @@ gdm_slave_session_stop (pid_t sesspid) * FIXME: Maybe we should waitpid here, note make sure this will * not create a hang! */ gdm_sigchld_block_push (); - if (d->sesspid > 0) + if (d->sesspid > 1) kill (- (d->sesspid), SIGTERM); gdm_sigchld_block_pop (); gdm_verify_cleanup (d); - pwent = getpwnam (local_login); /* PAM overwrites our pwent */ + if (local_login == NULL) + pwent = NULL; + else + pwent = getpwnam (local_login); /* PAM overwrites our pwent */ x_servers_file = g_strconcat (GdmServAuthDir, "/", d->name, ".Xservers", NULL); /* if there was a session that ran, run the PostSession script */ - if (sesspid > 0) { + if (run_post_session) { /* setup some env for PostSession script */ gnome_setenv ("DISPLAY", d->name, TRUE); gnome_setenv ("XAUTHORITY", d->authfile, TRUE); @@ -2910,7 +2910,7 @@ gdm_slave_session_stop (pid_t sesspid) gnome_setenv ("REMOTE_HOST", d->hostname, TRUE); /* Execute post session script */ - gdm_debug ("gdm_slave_session_cleanup: Running post session script"); + gdm_debug ("gdm_slave_session_stop: Running post session script"); gdm_slave_exec_script (d, GdmPostSession, local_login, pwent, FALSE /* pass_stdout */, TRUE /* set_parent */); @@ -2923,36 +2923,24 @@ gdm_slave_session_stop (pid_t sesspid) unlink (x_servers_file); g_free (x_servers_file); - if (pwent == NULL) { - return; - } - g_free (local_login); - - /* Remove display from ~user/.Xauthority */ - setegid (pwent->pw_gid); - seteuid (pwent->pw_uid); - gdm_auth_user_remove (d, pwent->pw_uid); + if (pwent != NULL) { + /* Remove display from ~user/.Xauthority */ + setegid (pwent->pw_gid); + seteuid (pwent->pw_uid); - seteuid (0); - setegid (0); -} + gdm_auth_user_remove (d, pwent->pw_uid); -static void -gdm_slave_session_cleanup (void) -{ - gdm_debug ("gdm_slave_session_cleanup: on %s", d->name); + seteuid (0); + setegid (0); + } - /* kill login if it still exists */ - g_free (login); - login = NULL; - /* things are going to be killed, so ignore errors */ XSetErrorHandler (ignore_xerror_handler); /* Cleanup */ - gdm_debug ("gdm_slave_session_cleanup: Severing connection"); + gdm_debug ("gdm_slave_session_stop: Severing connection"); if (d->dsp != NULL) { XCloseDisplay (d->dsp); d->dsp = NULL; @@ -2966,48 +2954,9 @@ gdm_slave_term_handler (int sig) gdm_debug ("gdm_slave_term_handler: %s got TERM/INT signal", d->name); - /* just for paranoia's sake */ - seteuid (0); - setegid (0); - - gdm_sigchld_block_push (); - - if (extra_process > 1) { - /* we sigterm extra processes, and we - * don't wait */ - kill (extra_process, SIGTERM); - extra_process = 0; - } - - gdm_sigchld_block_pop (); - - if (d->greetpid > 0) { - pid_t pid = d->greetpid; - gdm_sigchld_block_push (); - d->greetpid = 0; - greet = FALSE; - gdm_debug ("gdm_slave_term_handler: Whacking greeter"); - if (pid > 0 && - kill (pid, sig) == 0) - ve_waitpid_no_signal (pid, 0, 0); - gdm_sigchld_block_pop (); - } else if (login != NULL) { - gdm_slave_session_stop (d->sesspid); - gdm_slave_session_cleanup (); - } + gdm_slave_session_stop (d->logged_in && login != NULL); - if (d->chooserpid > 0) { - pid_t pid = d->chooserpid; - gdm_sigchld_block_push (); - d->chooserpid = 0; - gdm_debug ("gdm_slave_term_handler: Whacking chooser"); - if (pid > 0 && - kill (pid, sig) == 0) - ve_waitpid_no_signal (pid, 0, 0); - gdm_sigchld_block_pop (); - } - - gdm_debug ("gdm_slave_term_handler: Whacking server"); + gdm_debug ("gdm_slave_term_handler: Final cleanup"); gdm_slave_quick_exit (DISPLAY_ABORT); } @@ -3031,11 +2980,7 @@ gdm_slave_alrm_handler (int sig) if (in_ping) { /* darn, the last ping didn't succeed, wipe this display */ - - if (login != NULL) { - gdm_slave_session_stop (d->sesspid); - gdm_slave_session_cleanup (); - } + gdm_slave_session_stop (d->logged_in && login != NULL); gdm_slave_exit (DISPLAY_REMANAGE, _("Ping to %s failed, whacking display!"), @@ -3096,24 +3041,11 @@ gdm_slave_child_handler (int sig) return; } - /* Well now we're just going to kill - * everything including the X server, - * so no need doing XCloseDisplay which - * may just get us an XIOError */ - d->dsp = NULL; - whack_greeter_fds (); - /* just for paranoia's sake */ - seteuid (0); - setegid (0); - /* if greet is TRUE, then the greeter died outside of our - * control really, so clean up and die, something is wrong */ - gdm_server_stop (d); - gdm_verify_cleanup (d); - - /* The greeter is only allowed to pass back these + * control really, so clean up and die, something is wrong + * The greeter is only allowed to pass back these * exit codes, else we'll just remanage */ if (WIFEXITED (status) && (WEXITSTATUS (status) == DISPLAY_ABORT || @@ -3135,14 +3067,26 @@ gdm_slave_child_handler (int sig) gdm_server_wipe_cookies (d); gdm_slave_whack_temp_auth_file (); - /* whack the session good */ - if (d->sesspid > 0) - kill (- (d->sesspid), SIGTERM); - /* if not handled there is no need for further formalities, * we just have to die */ if ( ! d->handled) gdm_slave_quick_exit (DISPLAY_REMANAGE); + + gdm_slave_send_num (GDM_SOP_XPID, 0); + + /* whack the session good */ + if (d->sesspid > 1) { + gdm_slave_send_num (GDM_SOP_SESSPID, 0); + kill (- (d->sesspid), SIGTERM); + } + if (d->greetpid > 1) { + gdm_slave_send_num (GDM_SOP_GREETPID, 0); + kill (d->greetpid, SIGTERM); + } + if (d->chooserpid > 1) { + gdm_slave_send_num (GDM_SOP_CHOOSERPID, 0); + kill (d->chooserpid, SIGTERM); + } } else if (pid == extra_process) { /* an extra process died, yay! */ extra_process = 0; @@ -3237,39 +3181,10 @@ gdm_slave_xioerror_handler (Display *disp) gdm_debug ("gdm_slave_xioerror_handler: I/O error for display %s", d->name); - /* just for paranoia's sake */ - seteuid (0); - setegid (0); + gdm_slave_session_stop (d->logged_in && login != NULL); - if (d->greetpid > 0) { - pid_t pid = d->greetpid; - gdm_sigchld_block_push (); - d->greetpid = 0; - greet = FALSE; - if (pid > 0 && - kill (pid, SIGINT) == 0) - ve_waitpid_no_signal (pid, 0, 0); - gdm_sigchld_block_pop (); - } else if (login != NULL) { - gdm_slave_session_stop (d->sesspid); - gdm_slave_session_cleanup (); - } - - if (d->chooserpid > 0) { - pid_t pid = d->chooserpid; - gdm_sigchld_block_push (); - d->chooserpid = 0; - if (pid > 0 && - kill (pid, SIGINT) == 0) - ve_waitpid_no_signal (pid, 0, 0); - gdm_sigchld_block_pop (); - } - gdm_error (_("gdm_slave_xioerror_handler: Fatal X error - Restarting %s"), d->name); - gdm_server_stop (d); - gdm_verify_cleanup (d); - if ((d->type == TYPE_LOCAL || d->type == TYPE_FLEXI) && (do_xfailed_on_xio_error || @@ -3395,30 +3310,33 @@ gdm_slave_quick_exit (gint status) * may just get us an XIOError */ d->dsp = NULL; + /* No need to send the PIDS to the daemon + * since we'll just exit cleanly */ + /* Push and never pop */ gdm_sigchld_block_push (); /* Kill children where applicable */ - if (d->greetpid > 0) + if (d->greetpid > 1) kill (d->greetpid, SIGTERM); d->greetpid = 0; - if (d->chooserpid > 0) + if (d->chooserpid > 1) kill (d->chooserpid, SIGTERM); d->chooserpid = 0; - if (d->sesspid > 0) + if (d->sesspid > 1) kill (-(d->sesspid), SIGTERM); d->sesspid = 0; gdm_server_stop (d); gdm_verify_cleanup (d); - if (d->servpid > 0) + if (d->servpid > 1) kill (d->servpid, SIGTERM); d->servpid = 0; - if (extra_process > 0) + if (extra_process > 1) kill (extra_process, SIGTERM); extra_process = 0; } @@ -3806,11 +3724,11 @@ gdm_slave_handle_notify (const char *msg) GdmAllowRemoteAutoLogin = val; } else if (sscanf (msg, GDM_NOTIFY_SYSMENU " %d", &val) == 1) { GdmSystemMenu = val; - if (d->greetpid > 0) + if (d->greetpid > 1) kill (d->greetpid, SIGHUP); } else if (sscanf (msg, GDM_NOTIFY_CONFIG_AVAILABLE " %d", &val) == 1) { GdmConfigAvailable = val; - if (d->greetpid > 0) + if (d->greetpid > 1) kill (d->greetpid, SIGHUP); } else if (sscanf (msg, GDM_NOTIFY_RETRYDELAY " %d", &val) == 1) { GdmRetryDelay = val; @@ -3863,7 +3781,7 @@ gdm_slave_handle_notify (const char *msg) } } else if (sscanf (msg, GDM_NOTIFY_TIMED_LOGIN_DELAY " %d", &val) == 1) { GdmTimedLoginDelay = val; - if (d->greetpid > 0) + if (d->greetpid > 1) kill (d->greetpid, SIGHUP); } } |