diff options
author | jhb <jhb@FreeBSD.org> | 2007-11-08 22:31:28 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2007-11-08 22:31:28 +0000 |
commit | 4885bf6afbfea194213f2406f6dff7811f27dba7 (patch) | |
tree | 769b9c8a0098bcfd48c6a7813ecfe4e4d3449f5c | |
parent | f9553858df254346c6309df6e055deb5d4c1901e (diff) | |
download | FreeBSD-src-4885bf6afbfea194213f2406f6dff7811f27dba7.zip FreeBSD-src-4885bf6afbfea194213f2406f6dff7811f27dba7.tar.gz |
Teach ps(1) to parse pts TT values (i.e. '0', '1') for the -t flag.
MFC after: 1 week
Reported by: kris
-rw-r--r-- | bin/ps/ps.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 7ced4f4..dc5f08d 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -74,6 +74,8 @@ __FBSDID("$FreeBSD$"); #include "ps.h" +#define _PATH_PTS "/dev/pts/" + #define W_SEP " \t" /* "Whitespace" list separators */ #define T_SEP "," /* "Terminate-element" list separators */ @@ -706,9 +708,9 @@ addelem_pid(struct listinfo *inf, const char *elem) /*- * The user can specify a device via one of three formats: - * 1) fully qualified, e.g.: /dev/ttyp0 /dev/console - * 2) missing "/dev", e.g.: ttyp0 console - * 3) two-letters, e.g.: p0 co + * 1) fully qualified, e.g.: /dev/ttyp0 /dev/console /dev/pts/0 + * 2) missing "/dev", e.g.: ttyp0 console pts/0 + * 3) two-letters, e.g.: p0 co 0 * (matching letters that would be seen in the "TT" column) */ static int @@ -716,10 +718,11 @@ addelem_tty(struct listinfo *inf, const char *elem) { const char *ttypath; struct stat sb; - char pathbuf[PATH_MAX], pathbuf2[PATH_MAX]; + char pathbuf[PATH_MAX], pathbuf2[PATH_MAX], pathbuf3[PATH_MAX]; ttypath = NULL; pathbuf2[0] = '\0'; + pathbuf3[0] = '\0'; switch (*elem) { case '/': ttypath = elem; @@ -736,6 +739,8 @@ addelem_tty(struct listinfo *inf, const char *elem) ttypath = pathbuf; if (strncmp(pathbuf, _PATH_TTY, strlen(_PATH_TTY)) == 0) break; + if (strncmp(pathbuf, _PATH_PTS, strlen(_PATH_PTS)) == 0) + break; if (strcmp(pathbuf, _PATH_CONSOLE) == 0) break; /* Check to see if /dev/tty${elem} exists */ @@ -746,21 +751,30 @@ addelem_tty(struct listinfo *inf, const char *elem) ttypath = NULL; break; } + /* Check to see if /dev/pts/${elem} exists */ + strlcpy(pathbuf3, _PATH_PTS, sizeof(pathbuf3)); + strlcat(pathbuf3, elem, sizeof(pathbuf3)); + if (stat(pathbuf3, &sb) == 0 && S_ISCHR(sb.st_mode)) { + /* No need to repeat stat() && S_ISCHR() checks */ + ttypath = NULL; + break; + } break; } if (ttypath) { if (stat(ttypath, &sb) == -1) { - if (pathbuf2[0] != '\0') - warn("%s and %s", pathbuf2, ttypath); + if (pathbuf3[0] != '\0') + warn("%s, %s, and %s", pathbuf3, pathbuf2, + ttypath); else warn("%s", ttypath); optfatal = 1; return (0); } if (!S_ISCHR(sb.st_mode)) { - if (pathbuf2[0] != '\0') - warnx("%s and %s: Not a terminal", pathbuf2, - ttypath); + if (pathbuf3[0] != '\0') + warnx("%s, %s, and %s: Not a terminal", + pathbuf3, pathbuf2, ttypath); else warnx("%s: Not a terminal", ttypath); optfatal = 1; |