Index: ps.c =================================================================== RCS file: /usr/cvs/src/bin/ps/ps.c,v retrieving revision 1.111 diff -u -r1.111 ps.c --- ps.c 17 Sep 2007 05:27:18 -0000 1.111 +++ ps.c 16 Oct 2007 19:51:54 -0000 @@ -74,6 +74,8 @@ #include "ps.h" +#define _PATH_PTS "/dev/pts/" + #define W_SEP " \t" /* "Whitespace" list separators */ #define T_SEP "," /* "Terminate-element" list separators */ @@ -705,9 +707,9 @@ /*- * 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/01 + * 2) missing "/dev", e.g.: ttyp0 console pts/01 + * 3) two-letters, e.g.: p0 co 01 * (matching letters that would be seen in the "TT" column) */ static int @@ -715,10 +717,11 @@ { 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; @@ -735,6 +738,8 @@ 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 */ @@ -745,21 +750,30 @@ 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;