From: Todd C. Miller Date: Tue, 30 May 2017 16:44:11 +0000 (-0600) Subject: Use /proc/self consistently on Linux. As far as I know, only AIX X-Git-Tag: SUDO_1_8_21^2~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15901c94871903f01dcade897106a6920b9d8167;p=sudo Use /proc/self consistently on Linux. As far as I know, only AIX doesn't support /proc/self. --- diff --git a/src/ttyname.c b/src/ttyname.c index f21d4411c..7503c4eef 100644 --- a/src/ttyname.c +++ b/src/ttyname.c @@ -455,7 +455,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; @@ -463,8 +464,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);