Use pstat() on HP-UX to determine the tty device.
This commit is contained in:
@@ -82,6 +82,10 @@
|
||||
#elif defined(HAVE_SYS_PROCFS_H)
|
||||
# include <sys/procfs.h>
|
||||
#endif
|
||||
#ifdef HAVE_PSTAT_GETPROC
|
||||
# include <sys/param.h>
|
||||
# include <sys/pstat.h>
|
||||
#endif
|
||||
|
||||
#include "sudo.h"
|
||||
|
||||
@@ -156,7 +160,7 @@ sudo_ttyname_dev(dev_t tdev)
|
||||
|
||||
debug_return_str(estrdup(tty));
|
||||
}
|
||||
#elif defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(__linux__)
|
||||
#elif defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC) || defined(__linux__)
|
||||
/*
|
||||
* Devices to search before doing a breadth-first scan.
|
||||
*/
|
||||
@@ -335,7 +339,6 @@ sudo_ttyname_dev(dev_t rdev)
|
||||
* Return a string from ttyname() containing the tty to which the process is
|
||||
* attached or NULL if there is no tty associated with the process (or its
|
||||
* parent). First tries sysctl using the current pid, then the parent's pid.
|
||||
* Falls back on ttyname of std{in,out,err} if that fails.
|
||||
*/
|
||||
char *
|
||||
get_process_ttyname(void)
|
||||
@@ -385,7 +388,6 @@ get_process_ttyname(void)
|
||||
* Return a string from ttyname() containing the tty to which the process is
|
||||
* attached or NULL if there is no tty associated with the process (or its
|
||||
* parent). First tries /proc/pid/psinfo, then /proc/ppid/psinfo.
|
||||
* Falls back on ttyname of std{in,out,err} if that fails.
|
||||
*/
|
||||
char *
|
||||
get_process_ttyname(void)
|
||||
@@ -416,7 +418,6 @@ get_process_ttyname(void)
|
||||
* Return a string from ttyname() containing the tty to which the process is
|
||||
* attached or NULL if there is no tty associated with the process (or its
|
||||
* parent). First tries field 7 in /proc/pid/stat, then /proc/ppid/stat.
|
||||
* Falls back on ttyname of std{in,out,err} if that fails.
|
||||
*/
|
||||
char *
|
||||
get_process_ttyname(void)
|
||||
@@ -457,6 +458,32 @@ get_process_ttyname(void)
|
||||
|
||||
debug_return_str(tty);
|
||||
}
|
||||
#elif HAVE_PSTAT_GETPROC
|
||||
/*
|
||||
* Return a string from ttyname() containing the tty to which the process is
|
||||
* attached or NULL if there is no tty associated with the process (or its
|
||||
* parent).
|
||||
*/
|
||||
char *
|
||||
get_process_ttyname(void)
|
||||
{
|
||||
struct pst_status pstat;
|
||||
char *tty = NULL;
|
||||
int i;
|
||||
debug_decl(get_process_ttyname, SUDO_DEBUG_UTIL)
|
||||
|
||||
/* Try to determine the tty from psdev in struct pst_status. */
|
||||
for (i = 0; tty == NULL && i < 2; i++) {
|
||||
const int pid = i ? (int)getppid() : (int)getpid();
|
||||
if (pstat_getproc(&pstat, sizeof(pstat), 0, pid) != -1) {
|
||||
if (pstat.pst_term.psd_major != -1 && pstat.pst_term.psd_minor != -1) {
|
||||
tty = sudo_ttyname_dev(makedev(pstat.pst_term.psd_major,
|
||||
pstat.pst_term.psd_minor));
|
||||
}
|
||||
}
|
||||
}
|
||||
debug_return_str(tty);
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* Return a string from ttyname() containing the tty to which the process is
|
||||
|
Reference in New Issue
Block a user