]> granicus.if.org Git - sudo/commitdiff
Use /proc/self consistently on Linux. As far as I know, only AIX
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 30 May 2017 16:44:11 +0000 (10:44 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 30 May 2017 16:44:11 +0000 (10:44 -0600)
doesn't support /proc/self.

--HG--
branch : 1.8

src/ttyname.c

index 355c886068ac23a45577c274c1f1b3359dbc5cbe..ac632a1857b523c4fb49c839b60f61f405cc204e 100644 (file)
@@ -451,7 +451,8 @@ done:
 char *
 get_process_ttyname(char *name, size_t namelen)
 {
-    char path[PATH_MAX], *line = NULL;
+    const char path[] = "/proc/self/stat";
+    char *line = NULL;
     char *ret = NULL;
     size_t linesize = 0;
     int serrno = errno;
@@ -459,8 +460,7 @@ get_process_ttyname(char *name, size_t namelen)
     FILE *fp;
     debug_decl(get_process_ttyname, SUDO_DEBUG_UTIL)
 
-    /* Try to determine the tty from tty_nr in /proc/pid/stat. */
-    snprintf(path, sizeof(path), "/proc/%u/stat", (unsigned int)getpid());
+    /* Try to determine the tty from tty_nr in /proc/self/stat. */
     if ((fp = fopen(path, "r")) != NULL) {
        len = getline(&line, &linesize, fp);
        fclose(fp);