diff options
| author | Menno Lageman <Menno.Lageman@Sun.COM> | 2009-06-24 22:52:54 -0700 |
|---|---|---|
| committer | Menno Lageman <Menno.Lageman@Sun.COM> | 2009-06-24 22:52:54 -0700 |
| commit | 7166d658d92feaaa5e352bcc89ac223e558e4978 (patch) | |
| tree | df61985158ec75d174300e7b874113f323b88797 | |
| parent | f275d02f08c70e13825071e2577d1481e8bba78e (diff) | |
| download | illumos-joyent-7166d658d92feaaa5e352bcc89ac223e558e4978.tar.gz | |
PSARC/2009/182 prstat(1M) -r option
5073035 prstat could use a -r option which disables name lookups
6736091 u_name member of name_t struct not used in prstat(1M)
Contributed by Chad Mynhier <cmynhier@gmail.com>.
| -rw-r--r-- | usr/src/cmd/prstat/prstat.c | 21 | ||||
| -rw-r--r-- | usr/src/cmd/prstat/prstat.h | 3 | ||||
| -rw-r--r-- | usr/src/cmd/prstat/prtable.c | 28 | ||||
| -rw-r--r-- | usr/src/cmd/prstat/prtable.h | 21 | ||||
| -rw-r--r-- | usr/src/cmd/prstat/prutil.c | 13 | ||||
| -rw-r--r-- | usr/src/cmd/prstat/prutil.h | 13 |
6 files changed, 52 insertions, 47 deletions
diff --git a/usr/src/cmd/prstat/prstat.c b/usr/src/cmd/prstat/prstat.c index 944b122b7c..a7ff342dc3 100644 --- a/usr/src/cmd/prstat/prstat.c +++ b/usr/src/cmd/prstat/prstat.c @@ -22,6 +22,8 @@ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Portions Copyright 2009 Chad Mynhier */ #include <sys/types.h> @@ -141,8 +143,8 @@ static table_t prj_tbl = {0, 0, NULL}; /* selected projects */ static table_t tsk_tbl = {0, 0, NULL}; /* selected tasks */ static table_t lgr_tbl = {0, 0, NULL}; /* selected lgroups */ static zonetbl_t zone_tbl = {0, 0, NULL}; /* selected zones */ -static nametbl_t euid_tbl = {0, 0, NULL}; /* selected effective users */ -static nametbl_t ruid_tbl = {0, 0, NULL}; /* selected real users */ +static uidtbl_t euid_tbl = {0, 0, NULL}; /* selected effective users */ +static uidtbl_t ruid_tbl = {0, 0, NULL}; /* selected real users */ static uint_t total_procs; /* total number of procs */ static uint_t total_lwps; /* total number of lwps */ @@ -445,13 +447,15 @@ list_print(list_t *list) else mem = id->id_pctmem; if (list->l_type == LT_USERS) - pwd_getname(id->id_uid, pname, LOGNAME_MAX + 1); + pwd_getname(id->id_uid, pname, LOGNAME_MAX + 1, + opts.o_outpmode & OPT_NORESOLVE); else if (list->l_type == LT_ZONES) getzonename(id->id_zoneid, zonename, ZONENAME_MAX); else getprojname(id->id_projid, projname, - PROJNAME_MAX); + PROJNAME_MAX, + opts.o_outpmode & OPT_NORESOLVE); Format_size(psize, id->id_size, 6); Format_size(prssize, id->id_rssize, 6); Format_pct(pmem, mem, 4); @@ -484,8 +488,8 @@ list_print(list_t *list) else lwpid = lwp->li_info.pr_nlwp + lwp->li_info.pr_nzomb; - pwd_getname(lwp->li_info.pr_uid, pname, - LOGNAME_MAX + 1); + pwd_getname(lwp->li_info.pr_uid, pname, LOGNAME_MAX + 1, + opts.o_outpmode & OPT_NORESOLVE); if (opts.o_outpmode & OPT_PSINFO) { Format_size(psize, lwp->li_info.pr_size, 6); Format_size(prssize, lwp->li_info.pr_rssize, 6); @@ -1360,8 +1364,11 @@ main(int argc, char **argv) pagesize = sysconf(_SC_PAGESIZE); while ((opt = getopt(argc, argv, - "vcd:HmaRLtu:U:n:p:C:P:h:s:S:j:k:TJz:Z")) != (int)EOF) { + "vcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJz:Z")) != (int)EOF) { switch (opt) { + case 'r': + opts.o_outpmode |= OPT_NORESOLVE; + break; case 'R': opts.o_outpmode |= OPT_REALTIME; break; diff --git a/usr/src/cmd/prstat/prstat.h b/usr/src/cmd/prstat/prstat.h index 2b60b0b0fc..eefddcfcc3 100644 --- a/usr/src/cmd/prstat/prstat.h +++ b/usr/src/cmd/prstat/prstat.h @@ -22,6 +22,8 @@ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Portions Copyright 2009 Chad Mynhier */ #ifndef _PRSTAT_H @@ -70,6 +72,7 @@ extern "C" { #define OPT_LGRP 0x8000 /* report home lgroups */ #define OPT_UDATE 0x20000 /* print unix timestamp */ #define OPT_DDATE 0x40000 /* print timestamp in date(1) format */ +#define OPT_NORESOLVE 0x80000 /* no nsswitch lookups */ /* * Flags to keep track of process or lwp status diff --git a/usr/src/cmd/prstat/prtable.c b/usr/src/cmd/prstat/prtable.c index e0fe3ded13..87d862140b 100644 --- a/usr/src/cmd/prstat/prtable.c +++ b/usr/src/cmd/prstat/prtable.c @@ -19,12 +19,12 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Portions Copyright 2009 Chad Mynhier */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <procfs.h> #include <unistd.h> #include <stdlib.h> @@ -59,11 +59,11 @@ pwd_getid(char *name) } void -pwd_getname(uid_t uid, char *name, int length) +pwd_getname(uid_t uid, char *name, int length, int noresolve) { struct passwd *pwd; - if ((pwd = getpwuid(uid)) == NULL) { + if (noresolve || (pwd = getpwuid(uid)) == NULL) { (void) snprintf(name, length, "%u", uid); } else { (void) snprintf(name, length, "%s", pwd->pw_name); @@ -71,35 +71,33 @@ pwd_getname(uid_t uid, char *name, int length) } void -add_uid(nametbl_t *tbl, char *name) +add_uid(uidtbl_t *tbl, char *name) { - name_t *entp; + uid_t *uid; if (tbl->n_size == tbl->n_nent) { /* reallocation */ if ((tbl->n_size *= 2) == 0) tbl->n_size = 4; /* first time */ - tbl->n_list = Realloc(tbl->n_list, tbl->n_size*sizeof (name_t)); + tbl->n_list = Realloc(tbl->n_list, tbl->n_size*sizeof (uid_t)); } - entp = &tbl->n_list[tbl->n_nent++]; + uid = &tbl->n_list[tbl->n_nent++]; if (isdigit(name[0])) { - entp->u_id = Atoi(name); - pwd_getname(entp->u_id, entp->u_name, LOGNAME_MAX); + *uid = Atoi(name); } else { - entp->u_id = pwd_getid(name); - (void) snprintf(entp->u_name, LOGNAME_MAX, "%s", name); + *uid = pwd_getid(name); } } int -has_uid(nametbl_t *tbl, uid_t uid) +has_uid(uidtbl_t *tbl, uid_t uid) { size_t i; if (tbl->n_nent) { /* do linear search if table is not empty */ for (i = 0; i < tbl->n_nent; i++) - if (tbl->n_list[i].u_id == uid) + if (tbl->n_list[i] == uid) return (1); } else { return (1); /* if table is empty return true */ diff --git a/usr/src/cmd/prstat/prtable.h b/usr/src/cmd/prstat/prtable.h index e33ea9e2d0..da8557ac8f 100644 --- a/usr/src/cmd/prstat/prtable.h +++ b/usr/src/cmd/prstat/prtable.h @@ -19,15 +19,15 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Portions Copyright 2009 Chad Mynhier */ #ifndef _PRTABLE_H #define _PRTABLE_H -#pragma ident "%Z%%M% %I% %E% SMI" - #ifdef __cplusplus extern "C" { #endif @@ -46,15 +46,10 @@ typedef struct { } table_t; typedef struct { - uid_t u_id; - char u_name[LOGNAME_MAX+1]; -} name_t; - -typedef struct { size_t n_size; size_t n_nent; - name_t *n_list; -} nametbl_t; + uid_t *n_list; +} uidtbl_t; typedef struct { zoneid_t z_id; @@ -75,9 +70,9 @@ typedef struct plwp { /* linked list of pointers to lwps */ struct plwp *l_next; } plwp_t; -extern void pwd_getname(uid_t, char *, int); -extern void add_uid(nametbl_t *, char *); -extern int has_uid(nametbl_t *, uid_t); +extern void pwd_getname(uid_t, char *, int, int); +extern void add_uid(uidtbl_t *, char *); +extern int has_uid(uidtbl_t *, uid_t); extern void add_element(table_t *, long); extern int has_element(table_t *, long); extern void add_zone(zonetbl_t *, char *); diff --git a/usr/src/cmd/prstat/prutil.c b/usr/src/cmd/prstat/prutil.c index f8484e30db..75db7c3b3b 100644 --- a/usr/src/cmd/prstat/prutil.c +++ b/usr/src/cmd/prstat/prutil.c @@ -21,6 +21,8 @@ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Portions Copyright 2009 Chad Mynhier */ #include <sys/types.h> @@ -104,7 +106,7 @@ void Usage() { (void) fprintf(stderr, gettext( - "Usage:\tprstat [-acHJLmRtTvZ] [-u euidlist] [-U uidlist]\n" + "Usage:\tprstat [-acHJLmrRtTvZ] [-u euidlist] [-U uidlist]\n" "\t[-p pidlist] [-P cpulist] [-C psrsetlist] [-h lgrouplist]\n" "\t[-j projidlist] [-k taskidlist] [-z zoneidlist]\n" "\t[-s key | -S key] [-n nprocs[,nusers]] [-d d|u]\n" @@ -276,14 +278,15 @@ Priocntl(char *class) } void -getprojname(projid_t projid, char *str, int len) +getprojname(projid_t projid, char *str, int len, int noresolve) { struct project proj; - if (getprojbyid(projid, &proj, projbuf, PROJECT_BUFSZ) != NULL) - (void) snprintf(str, len, "%-28s", proj.pj_name); - else + if (noresolve || getprojbyid(projid, &proj, projbuf, PROJECT_BUFSZ) == + NULL) (void) snprintf(str, len, "%-6d", (int)projid); + else + (void) snprintf(str, len, "%-28s", proj.pj_name); } void diff --git a/usr/src/cmd/prstat/prutil.h b/usr/src/cmd/prstat/prutil.h index d0600b1c20..c98b3e7908 100644 --- a/usr/src/cmd/prstat/prutil.h +++ b/usr/src/cmd/prstat/prutil.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,15 +19,15 @@ * CDDL HEADER END */ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Portions Copyright 2009 Chad Mynhier */ #ifndef _PRUTIL_H #define _PRUTIL_H -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/processor.h> #include <sys/types.h> @@ -51,7 +50,7 @@ extern void *Malloc(size_t); extern void *Zalloc(size_t); extern int Setrlimit(); extern void Priocntl(char *); -extern void getprojname(projid_t, char *, int); +extern void getprojname(projid_t, char *, int, int); extern void getzonename(projid_t, char *, int); extern void stripfname(char *); |
