Skip to content

Commit d001abc

Browse files
committed
On AIX, psinfo.pr_ttydev is 0 when a process has no terminal.
On most other systems, psinfo.pr_ttydev is -1 for processes with no associated terminal. GitHub issue #408
1 parent ce36f01 commit d001abc

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/ttyname.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* SPDX-License-Identifier: ISC
33
*
4-
* Copyright (c) 2012-2023 Todd C. Miller <[email protected]>
4+
* Copyright (c) 2012-2024 Todd C. Miller <[email protected]>
55
*
66
* Permission to use, copy, modify, and distribute this software for any
77
* purpose with or without fee is hereby granted, provided that the above
@@ -23,7 +23,7 @@
2323

2424
#include <config.h>
2525

26-
/* Large files not supported by procfs.h on Solaris. */
26+
/* Large files may not be supported by procfs.h on Solaris. */
2727
#if defined(HAVE_STRUCT_PSINFO_PR_TTYDEV)
2828
# undef _FILE_OFFSET_BITS
2929
# undef _LARGE_FILES
@@ -175,7 +175,8 @@ get_process_ttyname(char *name, size_t namelen)
175175
if ((psinfo.pr_ttydev & DEVNO64) && sizeof(dev_t) == 4)
176176
ttydev = makedev(major64(psinfo.pr_ttydev), minor64(psinfo.pr_ttydev));
177177
#endif
178-
if (ttydev != (dev_t)-1) {
178+
/* On AIX, pr_ttydev is 0 (not -1) when no terminal is present. */
179+
if (ttydev != 0 && ttydev != (dev_t)-1) {
179180
errno = serrno;
180181
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
181182
sudo_warnx(
@@ -185,6 +186,7 @@ get_process_ttyname(char *name, size_t namelen)
185186
}
186187
goto done;
187188
}
189+
ttydev = (dev_t)-1;
188190
}
189191
} else {
190192
struct stat sb;

0 commit comments

Comments
 (0)