>Number:         146331
>Category:       bin
>Synopsis:       [PATCH] Grow ps(1) with "gid" and "group" keywords
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 05 14:40:04 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Jeremie Le Hen
>Release:        FreeBSD 9.0-CURRENT
>Organization:
None
>Environment:
System: FreeBSD felucia.tataz.chchile.org 9.0-CURRENT

>Description:
        ps(1) lacks "gid" and "group" keywords to inspect the effective
        group ID of processes.  This small patch implements this.
        I've also added three aliases:
            egid -> gid
            egroup -> group
            euid -> uid
>How-To-Repeat:
>Fix:

--- ps.egid.diff begins here ---
Index: extern.h
===================================================================
RCS file: /mnt/repos/freebsd-cvsroot/src/bin/ps/extern.h,v
retrieving revision 1.40
diff -u -p -u -p -r1.40 extern.h
--- extern.h    17 Mar 2010 22:57:58 -0000      1.40
+++ extern.h    5 May 2010 13:51:43 -0000
@@ -69,11 +69,13 @@ void         pmem(KINFO *, VARENT *);
 void    pri(KINFO *, VARENT *);
 void    printheader(void);
 void    priorityr(KINFO *, VARENT *);
+void    egroupname(KINFO *, VARENT *);
 void    rgroupname(KINFO *, VARENT *);
 void    runame(KINFO *, VARENT *);
 void    rvar(KINFO *, VARENT *);
 int     s_comm(KINFO *);
 int     s_label(KINFO *);
+int     s_egroupname(KINFO *);
 int     s_rgroupname(KINFO *);
 int     s_runame(KINFO *);
 int     s_uname(KINFO *);
Index: keyword.c
===================================================================
RCS file: /mnt/repos/freebsd-cvsroot/src/bin/ps/keyword.c,v
retrieving revision 1.82
diff -u -p -u -p -r1.82 keyword.c
--- keyword.c   17 Mar 2010 22:57:58 -0000      1.82
+++ keyword.c   5 May 2010 14:04:21 -0000
@@ -86,12 +86,19 @@ static VAR var[] = {
        {"cpu", "CPU", NULL, 0, kvar, NULL, 3, KOFF(ki_estcpu), UINT, "d",
                0},
        {"cputime", "", "time", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
+       {"egid", "", "gid", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
+       {"egroup", "", "group", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
+       {"euid", "", "uid", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
        {"emul", "EMUL", NULL, LJUST, emulname, NULL, EMULLEN, 0, CHAR,
                NULL, 0},
        {"etime", "ELAPSED", NULL, USER, elapsed, NULL, 12, 0, CHAR, NULL, 0},
        {"etimes", "ELAPSED", NULL, USER, elapseds, NULL, 12, 0, CHAR, NULL, 0},
        {"f", "F", NULL, 0, kvar, NULL, 7, KOFF(ki_flag), INT, "x", 0},
        {"flags", "", "f", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
+       {"gid", "GID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_groups),
+               UINT, UIDFMT, 0},
+       {"group", "GROUP", NULL, LJUST|DSIZ, egroupname, s_egroupname,
+           USERLEN, 0, CHAR, NULL, 0},
        {"ignored", "", "sigignore", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
        {"inblk", "INBLK", NULL, USER, rvar, NULL, 4, ROFF(ru_inblock), LONG,
                "ld", 0},
Index: print.c
===================================================================
RCS file: /mnt/repos/freebsd-cvsroot/src/bin/ps/print.c,v
retrieving revision 1.101
diff -u -p -u -p -r1.101 print.c
--- print.c     17 Mar 2010 22:57:58 -0000      1.101
+++ print.c     5 May 2010 13:53:24 -0000
@@ -340,6 +340,22 @@ s_uname(KINFO *k)
 }
 
 void
+egroupname(KINFO *k, VARENT *ve)
+{
+       VAR *v;
+
+       v = ve->var;
+       (void)printf("%-*s", v->width,
+           group_from_gid(k->ki_p->ki_groups[0], 0));
+}
+
+int
+s_egroupname(KINFO *k)
+{
+       return (strlen(group_from_gid(k->ki_p->ki_groups[0], 0)));
+}
+
+void
 rgroupname(KINFO *k, VARENT *ve)
 {
        VAR *v;
Index: ps.1
===================================================================
RCS file: /mnt/repos/freebsd-cvsroot/src/bin/ps/ps.1,v
retrieving revision 1.95
diff -u -p -u -p -r1.95 ps.1
--- ps.1        13 Apr 2010 08:54:53 -0000      1.95
+++ ps.1        5 May 2010 14:27:17 -0000
@@ -489,6 +489,12 @@ elapsed running time, in decimal integer
 .It Cm flags
 the process flags, in hexadecimal (alias
 .Cm f )
+.It Cm gid
+effective group ID (alias
+.Cm egid )
+.It Cm group
+group name (from egid) (alias
+.Cm egroup )
 .It Cm inblk
 total blocks read (alias
 .Cm inblock )
@@ -612,7 +618,8 @@ process pointer
 .It Cm ucomm
 name to be used for accounting
 .It Cm uid
-effective user ID
+effective user ID (alias
+.Cm euid )
 .It Cm upr
 scheduling priority on return from system call (alias
 .Cm usrpri )
--- ps.egid.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:
_______________________________________________
freebsd-bugs@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to