]> granicus.if.org Git - sudo/commitdiff
moved tty stuff into sudo.c
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 2 Sep 1995 02:25:17 +0000 (02:25 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 2 Sep 1995 02:25:17 +0000 (02:25 +0000)
logging.c
sudo.c

index 6ee4810682adb65d68d122df032b028cb786fd93..f37339a4858b5a24f9b36e7a4d0b847c4ada3fd7 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -123,7 +123,6 @@ void log_error(code)
     char *p;
     int count;
     time_t now;
-    char *tty;
 #if (LOGGING & SLOG_FILE)
     FILE *fp;
 #endif /* LOGGING & SLOG_FILE */
@@ -132,17 +131,6 @@ void log_error(code)
     char *tmp, save;
 #endif /* LOGGING & SLOG_SYSLOG */
 
-    /*
-     * Get our ttyname or set to "none"
-     */
-    if ((tty = (char *) ttyname(0)) == NULL)
-       tty = (char *) ttyname(1);
-
-    if (tty && (p = strrchr(tty, '/')))
-       tty = p + 1;
-    else
-       tty = "none";
-
     /*
      * Allocate enough memory for logline so we won't overflow it
      * XXX - don't use 33, use a macro!
diff --git a/sudo.c b/sudo.c
index 4a2641639772f057f3725fedab5278d5eca03b92..b185bb7bb65098c3adf7dbf848961eedf42d129b 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -132,6 +132,7 @@ char **Argv;
 char *cmnd = NULL;
 char *cmnd_args = NULL;
 char *user = NULL;
+char *tty = NULL;
 char *epasswd = NULL;
 char *prompt = PASSPROMPT;
 char *shell = NULL;
@@ -367,6 +368,20 @@ static void load_globals(sudo_mode)
     (void) tzset();            /* set the timezone if applicable */
 #endif /* HAVE_TZSET */
 
+    /*
+     * Need to get tty early since it's used for logging
+     */
+    if ((tty = (char *) ttyname(0)) || (tty = (char *) ttyname(0))) {
+       if ((p = strrchr(tty, '/')))
+           tty = p + 1;
+       if ((tty = strdup(tty)) == NULL) {
+           perror("malloc");
+           (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
+           exit(1);
+       }
+    } else
+       tty = "none";
+
     /*
      * loading the user & epasswd global variable from the passwd file
      * (must be done as root to get real passwd on some systems)