From: Todd C. Miller Date: Thu, 31 Jan 2013 16:05:56 +0000 (-0500) Subject: Remove ttyname() fall back code on systems where we can query the X-Git-Tag: SUDO_1_8_7~1^2~260 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=23649bef16845f21f5d15eae5e23e1d248d08903;p=sudo Remove ttyname() fall back code on systems where we can query the kernel for the tty device via /proc or sysctl(). If there is no controlling tty, it is better to just treat the tty as unknown rather than to blindly use what is hooked up to std{in,out,err}. --- diff --git a/src/ttyname.c b/src/ttyname.c index 9176cbb76..40b3ff797 100644 --- a/src/ttyname.c +++ b/src/ttyname.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Todd C. Miller + * Copyright (c) 2012-2013 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -378,14 +378,6 @@ get_process_ttyname(void) } efree(ki_proc); - /* If all else fails, fall back on ttyname(). */ - if (tty == NULL) { - if ((tty = ttyname(STDIN_FILENO)) != NULL || - (tty = ttyname(STDOUT_FILENO)) != NULL || - (tty = ttyname(STDERR_FILENO)) != NULL) - tty = estrdup(tty); - } - debug_return_str(tty); } #elif defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) @@ -417,14 +409,6 @@ get_process_ttyname(void) } } - /* If all else fails, fall back on ttyname(). */ - if (tty == NULL) { - if ((tty = ttyname(STDIN_FILENO)) != NULL || - (tty = ttyname(STDOUT_FILENO)) != NULL || - (tty = ttyname(STDERR_FILENO)) != NULL) - tty = estrdup(tty); - } - debug_return_str(tty); } #elif defined(__linux__) @@ -443,7 +427,7 @@ get_process_ttyname(void) int i; debug_decl(get_process_ttyname, SUDO_DEBUG_UTIL) - /* Try to determine the tty from pr_ttydev in /proc/pid/psinfo. */ + /* Try to determine the tty from tty_nr in /proc/pid/stat. */ for (i = 0; tty == NULL && i < 2; i++) { FILE *fp; char path[PATH_MAX]; @@ -471,14 +455,6 @@ get_process_ttyname(void) } efree(line); - /* If all else fails, fall back on ttyname(). */ - if (tty == NULL) { - if ((tty = ttyname(STDIN_FILENO)) != NULL || - (tty = ttyname(STDOUT_FILENO)) != NULL || - (tty = ttyname(STDERR_FILENO)) != NULL) - tty = estrdup(tty); - } - debug_return_str(tty); } #else