lineedit: do not hang on error, but return error indicator.
[oweals/busybox.git] / loginutils / login.c
index 4a820379d27633ce20fd8b7e748a25285c3f9d36..e104fbb932d7e59beae2fdece0bbcc21e61fee5a 100644 (file)
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 #include "libbb.h"
 #include <syslog.h>
@@ -201,7 +201,7 @@ int login_main(int argc UNUSED_PARAM, char **argv)
        };
        char *fromhost;
        char username[USERNAME_SIZE];
-       const char *tmp;
+       const char *shell;
        int run_by_root;
        unsigned opt;
        int count = 0;
@@ -249,9 +249,7 @@ int login_main(int argc UNUSED_PARAM, char **argv)
        full_tty = xmalloc_ttyname(STDIN_FILENO);
        if (!full_tty)
                full_tty = xstrdup("UNKNOWN");
-       short_tty = full_tty;
-       if (strncmp(full_tty, "/dev/", 5) == 0)
-               short_tty += 5;
+       short_tty = skip_dev_pfx(full_tty);
 
        if (opt_host) {
                fromhost = xasprintf(" on '%s' from '%s'", short_tty, opt_host);
@@ -266,7 +264,7 @@ int login_main(int argc UNUSED_PARAM, char **argv)
 
        while (1) {
                /* flush away any type-ahead (as getty does) */
-               ioctl(0, TCFLSH, TCIFLUSH);
+               tcflush(0, TCIFLUSH);
 
                if (!username[0])
                        get_username_or_die(username, sizeof(username));
@@ -384,17 +382,17 @@ int login_main(int argc UNUSED_PARAM, char **argv)
        fchown(0, pw->pw_uid, pw->pw_gid);
        fchmod(0, 0600);
 
-       update_utmp(USER_PROCESS, short_tty, username, run_by_root ? opt_host : NULL);
+       update_utmp(getpid(), USER_PROCESS, short_tty, username, run_by_root ? opt_host : NULL);
 
        /* We trust environment only if we run by root */
        if (ENABLE_LOGIN_SCRIPTS && run_by_root)
                run_login_script(pw, full_tty);
 
        change_identity(pw);
-       tmp = pw->pw_shell;
-       if (!tmp || !*tmp)
-               tmp = DEFAULT_SHELL;
-       setup_environment(tmp,
+       shell = pw->pw_shell;
+       if (!shell || !shell[0])
+               shell = DEFAULT_SHELL;
+       setup_environment(shell,
                        (!(opt & LOGIN_OPT_p) * SETUP_ENV_CLEARENV) + SETUP_ENV_CHANGEENV,
                        pw);
 
@@ -429,7 +427,7 @@ int login_main(int argc UNUSED_PARAM, char **argv)
        signal(SIGINT, SIG_DFL);
 
        /* Exec login shell with no additional parameters */
-       run_shell(tmp, 1, NULL, NULL);
+       run_shell(shell, 1, NULL, NULL);
 
        /* return EXIT_FAILURE; - not reached */
 }