Skip to content

Commit

Permalink
On AIX, psinfo.pr_ttydev is 0 when a process has no terminal.
Browse files Browse the repository at this point in the history
On most other systems, psinfo.pr_ttydev is -1 for processes
with no associated terminal.  GitHub issue #408
  • Loading branch information
millert committed Sep 11, 2024
1 parent ce36f01 commit d001abc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ttyname.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2012-2023 Todd C. Miller <Todd.Miller@sudo.ws>
* Copyright (c) 2012-2024 Todd C. Miller <Todd.Miller@sudo.ws>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand All @@ -23,7 +23,7 @@

#include <config.h>

/* Large files not supported by procfs.h on Solaris. */
/* Large files may not be supported by procfs.h on Solaris. */
#if defined(HAVE_STRUCT_PSINFO_PR_TTYDEV)
# undef _FILE_OFFSET_BITS
# undef _LARGE_FILES
Expand Down Expand Up @@ -175,7 +175,8 @@ get_process_ttyname(char *name, size_t namelen)
if ((psinfo.pr_ttydev & DEVNO64) && sizeof(dev_t) == 4)
ttydev = makedev(major64(psinfo.pr_ttydev), minor64(psinfo.pr_ttydev));
#endif
if (ttydev != (dev_t)-1) {
/* On AIX, pr_ttydev is 0 (not -1) when no terminal is present. */
if (ttydev != 0 && ttydev != (dev_t)-1) {
errno = serrno;
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
sudo_warnx(
Expand All @@ -185,6 +186,7 @@ get_process_ttyname(char *name, size_t namelen)
}
goto done;
}
ttydev = (dev_t)-1;
}
} else {
struct stat sb;
Expand Down

0 comments on commit d001abc

Please sign in to comment.