4 * This program gives Linux machines a reasonable secure way to boot single
5 * user. It forces the user to supply the root password before a shell is
6 * started. If there is a shadow password file and the encrypted root password
7 * is "x" the shadow password will be used.
9 * Copyright (C) 1998-2003 Miquel van Smoorenburg.
10 * Copyright (C) 2012 Karel Zak <kzak@redhat.com>
11 * Copyright (C) 2012 Werner Fink <werner@suse.de>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <sys/types.h>
42 #include <sys/ioctl.h>
47 #ifdef HAVE_LIBSELINUX
48 # include <selinux/selinux.h>
49 # include <selinux/get_context_list.h>
54 # include <sys/param.h>
58 #include "closestream.h"
60 #include "pathnames.h"
61 #ifdef USE_PLYMOUTH_SUPPORT
62 # include "plymouth-ctrl.h"
66 #include "sulogin-consoles.h"
69 static unsigned int timeout
;
71 static volatile uint32_t openfd
; /* Remember higher file descriptors */
73 struct sigaction saved_sigint
;
74 struct sigaction saved_sigtstp
;
75 struct sigaction saved_sigquit
;
76 struct sigaction saved_sighup
;
77 struct sigaction saved_sigchld
;
79 static volatile sig_atomic_t alarm_rised
;
80 static volatile sig_atomic_t sigchild
;
87 # warning "WEXITED is missing, sulogin may not work as expected"
91 static int locked_account_password(const char *passwd
)
93 if (passwd
&& (*passwd
== '*' || *passwd
== '!'))
99 * Fix the tty modes and set reasonable defaults.
101 static void tcinit(struct console
*con
)
103 int mode
= 0, flags
= 0;
104 struct termios
*tio
= &con
->tio
;
106 #ifdef USE_PLYMOUTH_SUPPORT
108 int i
= (plymouth_command(MAGIC_PING
)) ? PLYMOUTH_TERMIOS_FLAGS_DELAY
: 0;
110 plymouth_command(MAGIC_QUIT
);
113 * With plymouth the termios flags become changed after this
114 * function had changed the termios.
116 memset(&lock
, 0, sizeof(struct termios
));
117 if (ioctl(fd
, TIOCGLCKTRMIOS
, &lock
) < 0)
119 if (!lock
.c_iflag
&& !lock
.c_oflag
&& !lock
.c_cflag
&& !lock
.c_lflag
)
123 memset(&lock
, 0, sizeof(struct termios
));
124 ioctl(fd
, TIOCSLCKTRMIOS
, &lock
);
128 if (tcgetattr(fd
, tio
) < 0) {
129 warn(_("tcgetattr failed"));
130 con
->flags
|= CON_NOTTY
;
134 /* Handle lines other than virtual consoles here */
135 #if defined(KDGKBMODE)
136 if (ioctl(fd
, KDGKBMODE
, &mode
) < 0)
139 speed_t ispeed
, ospeed
;
143 /* this is a modem line */
144 con
->flags
|= CON_SERIAL
;
146 /* Flush input and output queues on modem lines */
147 tcflush(fd
, TCIOFLUSH
);
149 ispeed
= cfgetispeed(tio
);
150 ospeed
= cfgetospeed(tio
);
152 if (!ispeed
) ispeed
= TTYDEF_SPEED
;
153 if (!ospeed
) ospeed
= TTYDEF_SPEED
;
155 tio
->c_cflag
= CREAD
| CS8
| HUPCL
| (tio
->c_cflag
& CLOCAL
);
158 tio
->c_oflag
&= OPOST
| ONLCR
;
160 cfsetispeed(tio
, ispeed
);
161 cfsetospeed(tio
, ospeed
);
163 #ifdef HAVE_STRUCT_TERMIOS_C_LINE
166 tio
->c_cc
[VTIME
] = 0;
169 if (ioctl(fd
, TIOCGWINSZ
, &ws
) == 0) {
171 if (ws
.ws_row
== 0) {
175 if (ws
.ws_col
== 0) {
180 ignore_result( ioctl(fd
, TIOCSWINSZ
, &ws
) );
183 setlocale(LC_CTYPE
, "POSIX");
186 #if defined(IUTF8) && defined(KDGKBMODE)
187 /* Handle mode of current keyboard setup, e.g. for UTF-8 */
190 setlocale(LC_CTYPE
, "C.UTF-8");
191 flags
|= UL_TTY_UTF8
;
197 setlocale(LC_CTYPE
, "POSIX");
201 setlocale(LC_CTYPE
, "POSIX");
203 reset_virtual_console(tio
, flags
);
205 if (tcsetattr(fd
, TCSANOW
, tio
))
206 warn(_("tcsetattr failed"));
208 /* Enable blocking mode for read and write */
209 if ((flags
= fcntl(fd
, F_GETFL
, 0)) != -1)
210 ignore_result( fcntl(fd
, F_SETFL
, flags
& ~O_NONBLOCK
) );
214 * Finalize the tty modes on modem lines.
216 static void tcfinal(struct console
*con
)
221 if ((con
->flags
& CON_SERIAL
) == 0) {
222 setenv("TERM", "linux", 1);
225 if (con
->flags
& CON_NOTTY
) {
226 setenv("TERM", "dumb", 1);
230 #if defined (__s390__) || defined (__s390x__)
231 setenv("TERM", "dumb", 1);
233 setenv("TERM", "vt102", 1);
238 tio
->c_iflag
|= (IXON
| IXOFF
);
239 tio
->c_lflag
|= (ICANON
| ISIG
| ECHO
|ECHOE
|ECHOK
|ECHOKE
);
240 tio
->c_oflag
|= OPOST
;
242 tio
->c_cc
[VINTR
] = CINTR
;
243 tio
->c_cc
[VQUIT
] = CQUIT
;
244 tio
->c_cc
[VERASE
] = con
->cp
.erase
;
245 tio
->c_cc
[VKILL
] = con
->cp
.kill
;
246 tio
->c_cc
[VEOF
] = CEOF
;
248 tio
->c_cc
[VSWTC
] = _POSIX_VDISABLE
;
249 #elif defined(VSWTCH)
250 tio
->c_cc
[VSWTCH
] = _POSIX_VDISABLE
;
252 tio
->c_cc
[VSTART
] = CSTART
;
253 tio
->c_cc
[VSTOP
] = CSTOP
;
254 tio
->c_cc
[VSUSP
] = CSUSP
;
255 tio
->c_cc
[VEOL
] = _POSIX_VDISABLE
;
257 if (con
->cp
.eol
== CR
) {
258 tio
->c_iflag
|= ICRNL
;
259 tio
->c_iflag
&= ~(INLCR
|IGNCR
);
260 tio
->c_oflag
|= ONLCR
;
261 tio
->c_oflag
&= ~(OCRNL
|ONLRET
);
264 switch (con
->cp
.parity
) {
267 tio
->c_cflag
&= ~(PARODD
| PARENB
);
268 tio
->c_iflag
&= ~(INPCK
| ISTRIP
);
270 case 1: /* odd parity */
271 tio
->c_cflag
|= PARODD
;
273 case 2: /* even parity */
274 tio
->c_cflag
|= PARENB
;
275 tio
->c_iflag
|= (INPCK
| ISTRIP
);
277 case (1 | 2): /* no parity bit */
278 tio
->c_cflag
&= ~CSIZE
;
283 /* Set line attributes */
284 tcsetattr(fd
, TCSANOW
, tio
);
290 static void alrm_handler(int sig
__attribute__((unused
)))
292 /* Timeout expired */
296 static void chld_handler(int sig
__attribute__((unused
)))
301 static void mask_signal(int signal
, void (*handler
)(int),
302 struct sigaction
*origaction
)
304 struct sigaction newaction
;
306 newaction
.sa_handler
= handler
;
307 sigemptyset(&newaction
.sa_mask
);
308 newaction
.sa_flags
= 0;
310 sigaction(signal
, &newaction
, origaction
);
313 static void unmask_signal(int signal
, struct sigaction
*sa
)
315 sigaction(signal
, sa
, NULL
);
319 * See if an encrypted password is valid. The encrypted password is checked for
320 * traditional-style DES and FreeBSD-style MD5 encryption.
322 static int valid(const char *pass
)
335 * up to 4 bytes for the signature e.g. $1$
337 for (s
= pass
+1; *s
&& *s
!= '$'; s
++);
342 if ((off
= (off_t
)(s
-pass
)) > 4 || off
< 3)
345 memset(id
, '\0', sizeof(id
));
346 strncpy(id
, pass
, off
);
349 * up to 16 bytes for the salt
351 for (; *s
&& *s
!= '$'; s
++);
356 if ((off_t
)(s
-pass
) > 16)
362 * the MD5 hash (128 bits or 16 bytes) encoded in base64 = 22 bytes
364 if ((strcmp(id
, "$1$") == 0) && (len
< 22 || len
> 24))
368 * the SHA-256 hash 43 bytes
370 if ((strcmp(id
, "$5$") == 0) && (len
< 42 || len
> 44))
374 * the SHA-512 hash 86 bytes
376 if ((strcmp(id
, "$6$") == 0) && (len
< 85 || len
> 87))
384 if (strlen(pass
) != 13)
387 for (s
= pass
; *s
; s
++) {
388 if ((*s
< '0' || *s
> '9') &&
389 (*s
< 'a' || *s
> 'z') &&
390 (*s
< 'A' || *s
> 'Z') &&
391 *s
!= '.' && *s
!= '/')
398 * Set a variable if the value is not NULL.
400 static inline void set(char **var
, char *val
)
407 * Get the root password entry.
409 static struct passwd
*getrootpwent(int try_manually
)
411 static struct passwd pwd
;
415 static char line
[2 * BUFSIZ
];
416 static char sline
[2 * BUFSIZ
];
420 * First, we try to get the password the standard way using normal
423 if ((pw
= getpwnam("root")) &&
424 !strcmp(pw
->pw_passwd
, "x") &&
425 (spw
= getspnam("root")))
426 pw
->pw_passwd
= spw
->sp_pwdp
;
428 if (pw
|| !try_manually
)
432 * If we come here, we could not retrieve the root password through
433 * library calls and we try to read the password and shadow files
436 pwd
.pw_name
= "root";
438 pwd
.pw_gecos
= "Super User";
444 if ((fp
= fopen(_PATH_PASSWD
, "r")) == NULL
) {
445 warn(_("cannot open %s"), _PATH_PASSWD
);
450 * Find root in the password file.
452 while ((p
= fgets(line
, sizeof(line
), fp
)) != NULL
) {
453 if (strncmp(line
, "root:", 5) != 0)
456 set(&pwd
.pw_passwd
, strsep(&p
, ":"));
459 set(&pwd
.pw_gecos
, strsep(&p
, ":"));
460 set(&pwd
.pw_dir
, strsep(&p
, ":"));
461 set(&pwd
.pw_shell
, strsep(&p
, "\n"));
468 * If the encrypted password is valid or not found, return.
471 warnx(_("%s: no entry for root\n"), _PATH_PASSWD
);
474 if (valid(pwd
.pw_passwd
))
478 * The password is invalid. If there is a shadow password, try it.
480 *pwd
.pw_passwd
= '\0';
481 if ((fp
= fopen(_PATH_SHADOW_PASSWD
, "r")) == NULL
) {
482 warn(_("cannot open %s"), _PATH_PASSWD
);
485 while ((p
= fgets(sline
, sizeof(sline
), fp
)) != NULL
) {
486 if (strncmp(sline
, "root:", 5) != 0)
489 set(&pwd
.pw_passwd
, strsep(&p
, ":"));
495 * If the password is still invalid, NULL it, and return.
498 warnx(_("%s: no entry for root"), _PATH_SHADOW_PASSWD
);
499 *pwd
.pw_passwd
= '\0';
501 /* locked account passwords are valid too */
502 if (!locked_account_password(pwd
.pw_passwd
) && !valid(pwd
.pw_passwd
)) {
503 warnx(_("%s: root password garbled"), _PATH_SHADOW_PASSWD
);
504 *pwd
.pw_passwd
= '\0';
510 * Ask by prompt for the password.
512 static void doprompt(const char *crypted
, struct console
*con
, int deny
)
516 if (con
->flags
& CON_SERIAL
) {
519 * For prompting: map NL in output to CR-NL
520 * otherwise we may see stairs in the output.
522 tty
.c_oflag
|= (ONLCR
| OPOST
);
523 tcsetattr(con
->fd
, TCSADRAIN
, &tty
);
525 if (con
->file
== (FILE*)0) {
526 if ((con
->file
= fdopen(con
->fd
, "r+")) == (FILE*)0)
531 fprintf(con
->file
, _("\nCannot open access to console, the root account is locked.\n"
532 "See sulogin(8) man page for more details.\n\n"
533 "Press Enter to continue.\n"));
535 #if defined(USE_ONELINE)
536 if (crypted
[0] && !locked_account_password(crypted
))
537 fprintf(con
->file
, _("Give root password for login: "));
539 fprintf(con
->file
, _("Press Enter for login: "));
541 if (crypted
[0] && !locked_account_password(crypted
))
542 fprintf(con
->file
, _("Give root password for maintenance\n"));
544 fprintf(con
->file
, _("Press Enter for maintenance\n"));
545 fprintf(con
->file
, _("(or press Control-D to continue): "));
550 if (con
->flags
& CON_SERIAL
)
551 tcsetattr(con
->fd
, TCSADRAIN
, &con
->tio
);
555 * Make sure to have an own session and controlling terminal
557 static void setup(struct console
*con
)
559 pid_t pid
, pgrp
, ppgrp
, ttypgrp
;
562 if (con
->flags
& CON_NOTTY
)
567 * Only go through this trouble if the new
568 * tty doesn't fall in this process group.
572 ppgrp
= getpgid(getppid());
573 ttypgrp
= tcgetpgrp(fd
);
575 if (pgrp
!= ttypgrp
&& ppgrp
!= ttypgrp
) {
576 if (pid
!= getsid(0)) {
577 if (pid
== getpgid(0))
578 setpgid(0, getpgid(getppid()));
582 mask_signal(SIGHUP
, SIG_IGN
, &saved_sighup
);
584 ioctl(STDIN_FILENO
, TIOCNOTTY
, (char *)1);
585 unmask_signal(SIGHUP
, &saved_sighup
);
586 if (fd
> STDIN_FILENO
) close(STDIN_FILENO
);
587 if (fd
> STDOUT_FILENO
) close(STDOUT_FILENO
);
588 if (fd
> STDERR_FILENO
) close(STDERR_FILENO
);
590 ioctl(fd
, TIOCSCTTY
, (char *)1);
591 tcsetpgrp(fd
, ppgrp
);
593 dup2(fd
, STDIN_FILENO
);
594 dup2(fd
, STDOUT_FILENO
);
595 dup2(fd
, STDERR_FILENO
);
596 con
->fd
= STDIN_FILENO
;
598 for (fd
= STDERR_FILENO
+1; fd
< 32; fd
++) {
599 if (openfd
& (1<<fd
)) {
607 * Ask for the password. Note that there is no default timeout as we normally
608 * skip this during boot.
610 static char *getpasswd(struct console
*con
)
614 static char pass
[128], *ptr
;
622 if (con
->flags
& CON_NOTTY
)
628 tty
.c_iflag
&= ~(IUCLC
|IXON
|IXOFF
|IXANY
);
629 tty
.c_lflag
&= ~(ECHO
|ECHOE
|ECHOK
|ECHONL
|TOSTOP
|ISIG
);
630 tc
= (tcsetattr(fd
, TCSAFLUSH
, &tty
) == 0);
632 sigemptyset(&sa
.sa_mask
);
633 sa
.sa_handler
= alrm_handler
;
635 sigaction(SIGALRM
, &sa
, NULL
);
641 cp
->eol
= *ptr
= '\0';
643 eightbit
= ((con
->flags
& CON_SERIAL
) == 0 || (tty
.c_cflag
& (PARODD
|PARENB
)) == 0);
644 while (cp
->eol
== '\0') {
645 if (read(fd
, &c
, 1) < 1) {
646 if (errno
== EINTR
|| errno
== EAGAIN
) {
659 warn(_("cannot read %s"), con
->tty
);
667 else if (c
!= (ascval
= (c
& 0177))) {
669 for (bits
= 1, mask
= 1; mask
& 0177; mask
<<= 1) {
673 cp
->parity
|= ((bits
& 1) ? 1 : 2);
693 while (ptr
> &pass
[0])
699 if ((size_t)(ptr
- &pass
[0]) >= (sizeof(pass
) -1 )) {
700 fprintf(stderr
, "sulogin: input overrun at %s\n\r", con
->tty
);
711 tcsetattr(fd
, TCSAFLUSH
, &con
->tio
);
719 * Password was OK, execute a shell.
721 static void sushell(struct passwd
*pwd
)
723 char shell
[PATH_MAX
];
729 * Set directory and shell.
731 if (chdir(pwd
->pw_dir
) != 0) {
732 warn(_("%s: change directory failed"), pwd
->pw_dir
);
733 printf(_("Logging in with home = \"/\".\n"));
736 warn(_("change directory to system root failed"));
739 if ((p
= getenv("SUSHELL")) != NULL
)
741 else if ((p
= getenv("sushell")) != NULL
)
744 if (pwd
->pw_shell
[0])
745 su_shell
= pwd
->pw_shell
;
747 su_shell
= "/bin/sh";
749 if ((p
= strrchr(su_shell
, '/')) == NULL
)
754 snprintf(shell
, sizeof(shell
), profile
? "-%s" : "%s", p
);
757 * Set some important environment variables.
759 if (getcwd(home
, sizeof(home
)) == NULL
)
762 setenv("HOME", home
, 1);
763 setenv("LOGNAME", "root", 1);
764 setenv("USER", "root", 1);
766 setenv("SHLVL","0",1);
769 * Try to execute a shell.
771 setenv("SHELL", su_shell
, 1);
772 unmask_signal(SIGINT
, &saved_sigint
);
773 unmask_signal(SIGTSTP
, &saved_sigtstp
);
774 unmask_signal(SIGQUIT
, &saved_sigquit
);
775 mask_signal(SIGHUP
, SIG_DFL
, NULL
);
777 #ifdef HAVE_LIBSELINUX
778 if (is_selinux_enabled() > 0) {
779 security_context_t scon
=NULL
;
782 if (getseuserbyname("root", &seuser
, &level
) == 0) {
783 if (get_default_context_with_level(seuser
, level
, 0, &scon
) == 0) {
784 if (setexeccon(scon
) != 0)
785 warnx(_("setexeccon failed"));
793 execl(su_shell
, shell
, NULL
);
794 warn(_("failed to execute %s"), su_shell
);
796 setenv("SHELL", "/bin/sh", 1);
797 execl("/bin/sh", profile
? "-sh" : "sh", NULL
);
798 warn(_("failed to execute %s"), "/bin/sh");
801 static void usage(FILE *out
)
803 fputs(USAGE_HEADER
, out
);
805 " %s [options] [tty device]\n"), program_invocation_short_name
);
807 fputs(USAGE_SEPARATOR
, out
);
808 fputs(_("Single-user login.\n"), out
);
810 fputs(USAGE_OPTIONS
, out
);
811 fputs(_(" -p, --login-shell start a login shell\n"
812 " -t, --timeout <seconds> max time to wait for a password (default: no limit)\n"
813 " -e, --force examine password files directly if getpwnam(3) fails\n"),
816 fputs(USAGE_SEPARATOR
, out
);
817 fputs(USAGE_HELP
, out
);
818 fputs(USAGE_VERSION
, out
);
819 fprintf(out
, USAGE_MAN_TAIL("sulogin(8)"));
822 int main(int argc
, char **argv
)
825 struct list_head
*ptr
;
829 struct timespec sigwait
= { .tv_sec
= 0, .tv_nsec
= 50000000 };
830 siginfo_t status
= {};
832 int c
, reconnect
= 0;
837 static const struct option longopts
[] = {
838 { "login-shell", 0, 0, 'p' },
839 { "timeout", 1, 0, 't' },
840 { "force", 0, 0, 'e' },
841 { "help", 0, 0, 'h' },
842 { "version", 0, 0, 'V' },
847 * If we are init we need to set up a own session.
849 if ((pid
= getpid()) == 1) {
851 ignore_result( ioctl(STDIN_FILENO
, TIOCSCTTY
, (char *) 1) );
854 setlocale(LC_ALL
, "");
855 bindtextdomain(PACKAGE
, LOCALEDIR
);
857 atexit(close_stdout
); /* XXX */
860 * See if we have a timeout flag.
862 while ((c
= getopt_long(argc
, argv
, "ehpt:V", longopts
, NULL
)) != -1) {
865 timeout
= strtou32_or_err(optarg
, _("invalid timeout argument"));
874 printf(UTIL_LINUX_VERSION
);
887 errx(EXIT_FAILURE
, _("only superuser can run this program"));
889 mask_signal(SIGQUIT
, SIG_IGN
, &saved_sigquit
);
890 mask_signal(SIGTSTP
, SIG_IGN
, &saved_sigtstp
);
891 mask_signal(SIGINT
, SIG_IGN
, &saved_sigint
);
892 mask_signal(SIGHUP
, SIG_IGN
, &saved_sighup
);
895 emergency_do_mounts();
896 atexit( emergency_do_umounts
);
899 * See if we need to open an other tty device.
904 if (!tty
|| *tty
== '\0')
905 tty
= getenv("CONSOLE");
908 * Detect possible consoles, use stdin as fallback.
909 * If an optional tty is given, reconnect it to stdin.
911 reconnect
= detect_consoles(tty
, STDIN_FILENO
, &consoles
);
914 * If previous stdin was not the specified tty and therefore reconnected
915 * to the specified tty also reconnect stdout and stderr.
918 if (isatty(STDOUT_FILENO
) == 0)
919 dup2(STDOUT_FILENO
, STDIN_FILENO
);
920 if (isatty(STDERR_FILENO
) == 0)
921 dup2(STDOUT_FILENO
, STDERR_FILENO
);
927 if (list_empty(&consoles
)) {
930 err(EXIT_FAILURE
, _("cannot open console"));
934 * Get the root password.
936 if ((pwd
= getrootpwent(opt_e
)) == NULL
) {
937 warnx(_("cannot open password database"));
943 * Ask for the password on the consoles.
945 list_for_each(ptr
, &consoles
) {
946 con
= list_entry(ptr
, struct console
, entry
);
947 if (con
->id
>= CONMAX
)
950 openfd
|= (1 << con
->fd
);
954 if ((con
->fd
= open(con
->tty
, O_RDWR
| O_NOCTTY
| O_NONBLOCK
)) < 0)
956 openfd
|= (1 << con
->fd
);
959 ptr
= (&consoles
)->next
;
961 if (ptr
->next
== &consoles
) {
962 con
= list_entry(ptr
, struct console
, entry
);
967 mask_signal(SIGCHLD
, chld_handler
, &saved_sigchld
);
969 con
= list_entry(ptr
, struct console
, entry
);
970 if (con
->id
>= CONMAX
)
973 switch ((con
->pid
= fork())) {
975 mask_signal(SIGCHLD
, SIG_DFL
, NULL
);
980 const char *passwd
= pwd
->pw_passwd
;
982 int failed
= 0, doshell
= 0;
983 int deny
= !opt_e
&& locked_account_password(pwd
->pw_passwd
);
985 doprompt(passwd
, con
, deny
);
987 if ((answer
= getpasswd(con
)) == NULL
)
992 /* no password or locked account */
993 if (!passwd
[0] || locked_account_password(passwd
))
996 const char *cryptbuf
;
997 cryptbuf
= crypt(answer
, passwd
);
998 if (cryptbuf
== NULL
)
999 warn(_("crypt failed"));
1000 else if (strcmp(cryptbuf
, pwd
->pw_passwd
) == 0)
1009 mask_signal(SIGQUIT
, SIG_IGN
, &saved_sigquit
);
1010 mask_signal(SIGTSTP
, SIG_IGN
, &saved_sigtstp
);
1011 mask_signal(SIGINT
, SIG_IGN
, &saved_sigint
);
1014 fprintf(stderr
, _("Can not execute su shell\n\n"));
1017 fprintf(stderr
, _("Login incorrect\n\n"));
1021 warnx(_("Timed out\n\n"));
1024 * User pressed Control-D.
1028 warn(_("fork failed"));
1036 } while (ptr
!= &consoles
);
1042 ret
= waitid(P_ALL
, 0, &status
, WEXITED
);
1047 if (errno
== ECHILD
)
1053 errx(EXIT_FAILURE
, _("Can not wait on su shell\n\n"));
1057 list_for_each(ptr
, &consoles
) {
1058 con
= list_entry(ptr
, struct console
, entry
);
1064 if (con
->pid
== status
.si_pid
)
1067 kill(con
->pid
, SIGTERM
);
1073 sigaddset(&set
, SIGCHLD
);
1082 ret
= waitid(P_ALL
, 0, &status
, WEXITED
|WNOHANG
);
1085 if (errno
== ECHILD
)
1091 if (!ret
&& status
.si_pid
> 0) {
1092 list_for_each(ptr
, &consoles
) {
1093 con
= list_entry(ptr
, struct console
, entry
);
1099 if (con
->pid
== status
.si_pid
) {
1107 signum
= sigtimedwait(&set
, NULL
, &sigwait
);
1108 if (signum
!= SIGCHLD
&& signum
< 0 && errno
== EAGAIN
)
1113 mask_signal(SIGCHLD
, SIG_DFL
, NULL
);
1114 return EXIT_SUCCESS
;