Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/ps PR standards/11223



details:   https://anonhg.NetBSD.org/src/rev/419d6b2b22d0
branches:  trunk
changeset: 983734:419d6b2b22d0
user:      cjep <cjep%NetBSD.org@localhost>
date:      Fri Jun 04 06:28:42 2021 +0000

description:
PR standards/11223

Add -G to take a single group argument heading towards POSIX.2 compliance.
Patch from jperkin and reviewed by simonb.

diffstat:

 bin/ps/ps.1 |  10 +++++++++-
 bin/ps/ps.c |  31 ++++++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 6 deletions(-)

diffs (108 lines):

diff -r febf64285833 -r 419d6b2b22d0 bin/ps/ps.1
--- a/bin/ps/ps.1       Fri Jun 04 01:58:02 2021 +0000
+++ b/bin/ps/ps.1       Fri Jun 04 06:28:42 2021 +0000
@@ -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 @@
 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 @@
 .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.
diff -r febf64285833 -r 419d6b2b22d0 bin/ps/ps.c
--- a/bin/ps/ps.c       Fri Jun 04 01:58:02 2021 +0000
+++ b/bin/ps/ps.c       Fri Jun 04 06:28:42 2021 +0000
@@ -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 @@
 #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 @@
 #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 @@
  * 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 @@
                        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 @@
        (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 */



Home | Main Index | Thread Index | Old Index