From 8384a1bbb8d0cbb47fe65b9267afeff917b55d2a Mon Sep 17 00:00:00 2001 From: simonb Date: Sat, 15 Apr 2000 04:40:46 +0000 Subject: [PATCH] Use tty "?" to select processes with no controlling tty and tty "-" to select processes with a revoked controlling tty. Idea from SunOS/Solaris, suggested by Alexis Rosen. --- bin/ps/ps.1 | 6 ++++-- bin/ps/ps.c | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 41ebb598006a..6b9b6e58809b 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: ps.1,v 1.35 2000/04/10 06:37:37 chs Exp $ +.\" $NetBSD: ps.1,v 1.36 2000/04/15 04:40:46 simonb Exp $ .\" .\" Copyright (c) 1980, 1990, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -165,7 +165,9 @@ Display information about processes attached to the device associated with the standard input. .It Fl t Display information about processes attached to the specified terminal -device. +device. Use an question mark (``?'') for processes not attached to a +terminal device and a minus sign (``-'') for processes that have +been revoked from their terminal device. .It Fl U Displays processes belonging to the user whose username or uid has been given to the diff --git a/bin/ps/ps.c b/bin/ps/ps.c index ae811f9bc1ae..6f4591d07c5f 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -1,4 +1,4 @@ -/* $NetBSD: ps.c,v 1.35 2000/04/10 06:37:37 chs Exp $ */ +/* $NetBSD: ps.c,v 1.36 2000/04/15 04:40:46 simonb Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\n\ #if 0 static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; #else -__RCSID("$NetBSD: ps.c,v 1.35 2000/04/10 06:37:37 chs Exp $"); +__RCSID("$NetBSD: ps.c,v 1.36 2000/04/15 04:40:46 simonb Exp $"); #endif #endif /* not lint */ @@ -218,19 +218,26 @@ main(argc, argv) struct stat sb; char *ttypath, pathbuf[MAXPATHLEN]; - if (strcmp(ttname, "co") == 0) + flag = 0; + if (strcmp(ttname, "?") == 0) + flag = KERN_PROC_TTY_NODEV; + else if (strcmp(ttname, "-") == 0) + flag = KERN_PROC_TTY_REVOKE; + else if (strcmp(ttname, "co") == 0) ttypath = _PATH_CONSOLE; else if (*ttname != '/') (void)snprintf(ttypath = pathbuf, sizeof(pathbuf), "%s%s", _PATH_TTY, ttname); else ttypath = ttname; - if (stat(ttypath, &sb) == -1) - err(1, "%s", ttypath); - if (!S_ISCHR(sb.st_mode)) - errx(1, "%s: not a terminal", ttypath); what = KERN_PROC_TTY; - flag = sb.st_rdev; + if (flag == 0) { + if (stat(ttypath, &sb) == -1) + err(1, "%s", ttypath); + if (!S_ISCHR(sb.st_mode)) + errx(1, "%s: not a terminal", ttypath); + flag = sb.st_rdev; + } break; } case 'U':