exiting to shell should block signals first, to avoid the child getting them. Also, sulogin seems to work without specifying the terminal now.

This commit is contained in:
Roy Marples 2008-02-04 22:19:40 +00:00
parent b1771be2d1
commit 483a19a0e3

@ -281,6 +281,11 @@ static void mark_interactive (void)
static void sulogin (bool cont) static void sulogin (bool cont)
{ {
int status = 0;
struct sigaction sa;
sigset_t full;
sigset_t old;
pid_t pid;
#ifdef __linux__ #ifdef __linux__
char *e = getenv ("RC_SYS"); char *e = getenv ("RC_SYS");
@ -293,23 +298,44 @@ static void sulogin (bool cont)
newenv = env_filter (); newenv = env_filter ();
if (cont) { if (! cont) {
int status = 0; rc_logger_close ();
#ifdef __linux__ #ifdef __linux__
char *tty = ttyname (STDOUT_FILENO); execle ("/sbin/sulogin", "/sbin/sulogin", (char *) NULL, newenv);
eerrorx ("%s: unable to exec `/sbin/sulogin': %s", applet, strerror (errno));
#else
exit (EXIT_SUCCESS);
#endif #endif
}
pid_t pid = vfork (); /* We need to block signals until we have forked */
memset (&sa, 0, sizeof (sa));
sa.sa_handler = SIG_DFL;
sigemptyset (&sa.sa_mask);
sigfillset (&full);
sigprocmask (SIG_SETMASK, &full, &old);
pid = vfork ();
if (pid == -1) if (pid == -1)
eerrorx ("%s: vfork: %s", applet, strerror (errno)); eerrorx ("%s: fork: %s", applet, strerror (errno));
if (pid == 0) { if (pid == 0) {
#ifdef __linux__ /* Restore default handlers */
if (tty) sigaction (SIGCHLD, &sa, NULL);
execle (SULOGIN, SULOGIN, tty, (char *) NULL, newenv); sigaction (SIGHUP, &sa, NULL);
else sigaction (SIGINT, &sa, NULL);
execle (SULOGIN, SULOGIN, (char *) NULL, newenv); sigaction (SIGQUIT, &sa, NULL);
sigaction (SIGTERM, &sa, NULL);
sigaction (SIGUSR1, &sa, NULL);
sigaction (SIGWINCH, &sa, NULL);
/* Unmask signals */
sigprocmask (SIG_SETMASK, &old, NULL);
if (termios_orig)
tcsetattr (fileno (stdin), TCSANOW, termios_orig);
#ifdef __linux__
execle (SULOGIN, SULOGIN, (char *) NULL, newenv);
eerror ("%s: unable to exec `%s': %s", applet, SULOGIN, eerror ("%s: unable to exec `%s': %s", applet, SULOGIN,
strerror (errno)); strerror (errno));
#else #else
@ -319,17 +345,10 @@ static void sulogin (bool cont)
#endif #endif
_exit (EXIT_FAILURE); _exit (EXIT_FAILURE);
} }
waitpid (pid, &status, 0);
} else {
rc_logger_close ();
#ifdef __linux__ /* Unmask signals and wait for child */
execle ("/sbin/sulogin", "/sbin/sulogin", (char *) NULL, newenv); sigprocmask (SIG_SETMASK, &old, NULL);
eerrorx ("%s: unable to exec `/sbin/sulogin': %s", applet, strerror (errno)); waitpid (pid, &status, 0);
#else
exit (EXIT_SUCCESS);
#endif
}
} }
static void single_user (void) static void single_user (void)