PR standards/11223

Add -G to take a single group argument heading towards POSIX.2 compliance.
Patch from jperkin and reviewed by simonb.
This commit is contained in:
cjep 2021-06-04 06:28:42 +00:00
parent 35fff04939
commit e31566ddc3
2 changed files with 35 additions and 6 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ps.1,v 1.110 2019/08/06 18:07:51 kamil Exp $
.\" $NetBSD: ps.1,v 1.111 2021/06/04 06:28:42 cjep Exp $
.\"
.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@ -46,6 +46,7 @@
.Op Fl p Ar pid
.Op Fl t Ar tty
.Op Fl U Ar user
.Op Fl G Ar group
.Op Fl W Ar swap
.Nm
.Fl L
@ -110,6 +111,9 @@ relative to each other.
Display the environment as well.
The environment for other
users' processes can only be displayed by the super-user.
.It Fl G Ar group
Display processes belonging to the users belonging to the specified group,
given either as a group name or a gid.
.It Fl h
Repeat the information header as often as necessary to guarantee one
header per page of information.
@ -714,3 +718,7 @@ Since
.Nm
cannot run faster than the system and is run as any other scheduled
process, the information it displays can never be exact.
.Pp
The
.Fl G
option should ideally take a list instead of a single group.

View File

@ -1,4 +1,4 @@
/* $NetBSD: ps.c,v 1.93 2019/09/15 15:27:50 kamil Exp $ */
/* $NetBSD: ps.c,v 1.94 2021/06/04 06:28:42 cjep Exp $ */
/*
* Copyright (c) 2000-2008 The NetBSD Foundation, Inc.
@ -68,7 +68,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\
#if 0
static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: ps.c,v 1.93 2019/09/15 15:27:50 kamil Exp $");
__RCSID("$NetBSD: ps.c,v 1.94 2021/06/04 06:28:42 cjep Exp $");
#endif
#endif /* not lint */
@ -86,6 +86,7 @@ __RCSID("$NetBSD: ps.c,v 1.93 2019/09/15 15:27:50 kamil Exp $");
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <kvm.h>
#include <limits.h>
#include <locale.h>
@ -104,8 +105,8 @@ __RCSID("$NetBSD: ps.c,v 1.93 2019/09/15 15:27:50 kamil Exp $");
* ARGOPTS must contain all option characters that take arguments
* (except for 't'!) - it is used in kludge_oldps_options()
*/
#define GETOPTSTR "aAcCdeghjk:LlM:mN:O:o:p:rSsTt:U:uvW:wx"
#define ARGOPTS "kMNOopUW"
#define GETOPTSTR "aAcCdegG:hjk:LlM:mN:O:o:p:rSsTt:U:uvW:wx"
#define ARGOPTS "GkMNOopUW"
struct varlist displaylist = SIMPLEQ_HEAD_INITIALIZER(displaylist);
struct varlist sortlist = SIMPLEQ_HEAD_INITIALIZER(sortlist);
@ -253,6 +254,26 @@ main(int argc, char *argv[])
break;
case 'g':
break; /* no-op */
case 'G':
if (*optarg != '\0') {
struct group *gr;
char *ep;
what = KERN_PROC_GID;
gr = getgrnam(optarg);
if (gr == NULL) {
errno = 0;
flag = strtoul(optarg, &ep, 10);
if (errno)
err(1, "%s", optarg);
if (*ep != '\0')
errx(1, "%s: illegal group",
optarg);
} else
flag = gr->gr_gid;
}
break;
case 'h':
prtheader = ws.ws_row > 5 ? ws.ws_row : 22;
break;
@ -945,7 +966,7 @@ usage(void)
(void)fprintf(stderr,
"usage:\t%s\n\t %s\n\t%s\n",
"ps [-AaCcdehjlmrSsTuvwx] [-k key] [-M core] [-N system] [-O fmt]",
"[-o fmt] [-p pid] [-t tty] [-U user] [-W swap]",
"[-o fmt] [-p pid] [-t tty] [-U user] [-G group] [-W swap]",
"ps -L");
exit(1);
/* NOTREACHED */