]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - login-utils/sulogin.c
Merge branch 'mps_losetup_has_device_inline' of https://github.com/marcosps/util...
[thirdparty/util-linux.git] / login-utils / sulogin.c
index 72bba623a292414b4fee241796076d7f3166ca44..5f09bd48e4ab9ddc8b7ab7deb703f25d24a3bd89 100644 (file)
@@ -520,8 +520,9 @@ static void doprompt(const char *crypted, struct console *con, int deny)
                tty.c_oflag |= (ONLCR | OPOST);
                tcsetattr(con->fd, TCSADRAIN, &tty);
        }
-       if (con->file == (FILE*)0) {
-               if  ((con->file = fdopen(con->fd, "r+")) == (FILE*)0)
+       if (!con->file) {
+               con->file = fdopen(con->fd, "r+");
+               if (!con->file)
                        goto err;
        }
 
@@ -643,7 +644,7 @@ static const char *getpasswd(struct console *con)
                                xusleep(250000);
                                continue;
                        }
-                       ret = (char*)0;
+                       ret = NULL;
                        switch (errno) {
                        case 0:
                        case EIO:
@@ -695,7 +696,7 @@ static const char *getpasswd(struct console *con)
                default:
                        if ((size_t)(ptr - &pass[0]) >= (sizeof(pass) -1 )) {
                                 fprintf(stderr, "sulogin: input overrun at %s\n\r", con->tty);
-                                ret = (char*)0;
+                                ret = NULL;
                                 goto quit;
                        }
                        *ptr++ = ascval;
@@ -795,8 +796,9 @@ static void sushell(struct passwd *pwd)
        warn(_("failed to execute %s"), "/bin/sh");
 }
 
-static void usage(FILE *out)
+static void usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(
                " %s [options] [tty device]\n"), program_invocation_short_name);
@@ -811,9 +813,8 @@ static void usage(FILE *out)
                out);
 
        fputs(USAGE_SEPARATOR, out);
-       fputs(USAGE_HELP, out);
-       fputs(USAGE_VERSION, out);
-       fprintf(out, USAGE_MAN_TAIL("sulogin(8)"));
+       printf(USAGE_HELP_OPTIONS(26));
+       printf(USAGE_MAN_TAIL("sulogin(8)"));
 }
 
 int main(int argc, char **argv)
@@ -872,11 +873,10 @@ int main(int argc, char **argv)
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
                case 'h':
-                       usage(stdout);
+                       usage();
                        return EXIT_SUCCESS;
                default:
-                       usage(stderr);
-                       /* Do not exit! */
+                       /* Do not exit! getopt prints a warning. */
                        break;
                }
        }
@@ -976,7 +976,7 @@ int main(int argc, char **argv)
                        while (1) {
                                const char *passwd = pwd->pw_passwd;
                                const char *answer;
-                               int failed = 0, doshell = 0;
+                               int doshell = 0;
                                int deny = !opt_e && locked_account_password(pwd->pw_passwd);
 
                                doprompt(passwd, con, deny);
@@ -999,15 +999,13 @@ int main(int argc, char **argv)
                                }
 
                                if (doshell) {
+                                       /* sushell() unmask signals */
                                        sushell(pwd);
-                                       failed++;
-                               }
 
-                               mask_signal(SIGQUIT, SIG_IGN, &saved_sigquit);
-                               mask_signal(SIGTSTP, SIG_IGN, &saved_sigtstp);
-                               mask_signal(SIGINT,  SIG_IGN, &saved_sigint);
+                                       mask_signal(SIGQUIT, SIG_IGN, &saved_sigquit);
+                                       mask_signal(SIGTSTP, SIG_IGN, &saved_sigtstp);
+                                       mask_signal(SIGINT,  SIG_IGN, &saved_sigint);
 
-                               if (failed) {
                                        fprintf(stderr, _("cannot execute su shell\n\n"));
                                        break;
                                }