]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: use get_terminal_name() from ttyutils.c
authorKarel Zak <kzak@redhat.com>
Thu, 22 Nov 2012 13:42:10 +0000 (14:42 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 22 Nov 2012 13:42:10 +0000 (14:42 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/login.c

index 53df1345ae668eb628c9183d3f340ecc91a7b5c5..534da4250706d306bee394ae8b2e3be4564b6018 100644 (file)
@@ -70,6 +70,7 @@
 #include "xalloc.h"
 #include "all-io.h"
 #include "fileutils.h"
+#include "ttyutils.h"
 
 #include "logindefs.h"
 
@@ -350,13 +351,12 @@ static void chown_tty(struct login_context *cxt)
  */
 static void init_tty(struct login_context *cxt)
 {
-       const char *p;
        struct stat st;
        struct termios tt, ttt;
 
        cxt->tty_mode = (mode_t) getlogindefs_num("TTYPERM", TTY_MODE);
 
-       cxt->tty_path = ttyname(0);             /* libc calls istty() here */
+       get_terminal_name(&cxt->tty_path, &cxt->tty_name, &cxt->tty_number);
 
        /*
         * In case login is suid it was possible to use a hardlink as stdin
@@ -375,18 +375,6 @@ static void init_tty(struct login_context *cxt)
                sleepexit(EXIT_FAILURE);
        }
 
-       if (strncmp(cxt->tty_path, "/dev/", 5) == 0)
-               cxt->tty_name = cxt->tty_path + 5;
-       else
-               cxt->tty_name = cxt->tty_path;
-
-       for (p = cxt->tty_name; p && *p; p++) {
-               if (isdigit(*p)) {
-                       cxt->tty_number = p;
-                       break;
-               }
-       }
-
 #ifdef LOGIN_CHOWN_VCS
        if (cxt->tty_number) {
                /* find names of Virtual Console devices, for later mode change */