diff options
| author | Keith M Wesolowski <wesolows@foobazco.org> | 2013-10-10 23:23:15 +0000 |
|---|---|---|
| committer | Keith M Wesolowski <wesolows@foobazco.org> | 2013-10-10 23:32:17 +0000 |
| commit | e0b0bfaae7148432e8012c03c28865a062269b8a (patch) | |
| tree | 8eca098b56f70c0163da0d70811cd8fedd72b4f5 /usr/src/cmd/prstat | |
| parent | 7b4aafc0bae4c5843494076dae7433ef7f3e8169 (diff) | |
| parent | 746f551ddc191f00808cd4121966c1ee42d5b74f (diff) | |
| download | illumos-joyent-e0b0bfaae7148432e8012c03c28865a062269b8a.tar.gz | |
[illumos-gate merge]
commit 746f551ddc191f00808cd4121966c1ee42d5b74f
2989 LOGNAME_MAX should be increased to 32 (fix gcc build)
commit 23b68ef4aef54d7487e138ec22eafdfc83844017
4016 disk-monitor should activate fault/fail indicators (remove build artifact)
commit ad7ed3fec423fe5215f6da8888d44a36514ee898
4182 proto_promisc* miss calls to mac_perim_exit
commit 5691611ed44f54317a0e6ff4526c4cc0d8bca9b3
2989 LOGNAME_MAX should be increased to 32 (missing file)
commit 0a1278f26ea4b7c8c0285d4f2d6c5b680904aa01
2989 LOGNAME_MAX should be increased to 32
1166 useradd warns on names with more than 8 chars
Conflicts:
usr/src/cmd/passwd/passwd.c (OS-1836, superceded)
usr/src/man/man1m/prstat.1m (OS-1044, keep)
usr/src/lib/libc/port/gen/getlogin.c (OS-1836, superceded)
usr/src/head/unistd.h (OS-1836, superceded)
usr/src/cmd/prstat/prutil.c (OS-1044, keep)
usr/src/cmd/prstat/prstat.c (OS-1044, keep)
Diffstat (limited to 'usr/src/cmd/prstat')
| -rw-r--r-- | usr/src/cmd/prstat/prstat.c | 51 | ||||
| -rw-r--r-- | usr/src/cmd/prstat/prstat.h | 3 | ||||
| -rw-r--r-- | usr/src/cmd/prstat/prtable.c | 23 | ||||
| -rw-r--r-- | usr/src/cmd/prstat/prtable.h | 4 | ||||
| -rw-r--r-- | usr/src/cmd/prstat/prutil.c | 39 | ||||
| -rw-r--r-- | usr/src/cmd/prstat/prutil.h | 6 |
6 files changed, 95 insertions, 31 deletions
diff --git a/usr/src/cmd/prstat/prstat.c b/usr/src/cmd/prstat/prstat.c index e14538a57e..8e4e18aafc 100644 --- a/usr/src/cmd/prstat/prstat.c +++ b/usr/src/cmd/prstat/prstat.c @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * @@ -76,6 +78,10 @@ #include <curses.h> #include <term.h> +#define LOGIN_WIDTH 8 +#define ZONE_WIDTH 28 +#define PROJECT_WIDTH 28 + #define PSINFO_HEADER_PROC \ " PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP " #define PSINFO_HEADER_PROC_LGRP \ @@ -109,8 +115,8 @@ #define PSINFO_LINE_LGRP \ "%6d %-8s %5s %5s %-6s %3s %3s %9s %3.3s%% %4d %-.16s/%d" #define USAGE_LINE \ -"%6d %-8s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s "\ -"%3.3s %-.12s/%d" +"%6d %-8s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s "\ +"%3.3s %3.3s %-.12s/%d" #define USER_LINE \ "%6d %-8s %5.5s %5.5s %3.3s%% %9s %3.3s%%" #define TASK_LINE \ @@ -455,16 +461,23 @@ list_print(list_t *list) mem = (100 * id->id_pctmem) / total_mem; else mem = id->id_pctmem; - if (list->l_type == LT_USERS) - pwd_getname(id->id_uid, pname, LOGNAME_MAX + 1, - opts.o_outpmode & OPT_NORESOLVE); - else if (list->l_type == LT_ZONES) + if (list->l_type == LT_USERS) { + pwd_getname(id->id_uid, pname, sizeof (pname), + opts.o_outpmode & OPT_NORESOLVE, + opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC), + LOGIN_WIDTH); + } else if (list->l_type == LT_ZONES) { getzonename(id->id_zoneid, zonename, - ZONENAME_MAX); - else + sizeof (zonename), + opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC), + ZONE_WIDTH); + } else { getprojname(id->id_projid, projname, - PROJNAME_MAX, - opts.o_outpmode & OPT_NORESOLVE); + sizeof (projname), + opts.o_outpmode & OPT_NORESOLVE, + opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC), + PROJECT_WIDTH); + } Format_size(psize, id->id_size, 6); Format_size(prssize, id->id_rssize, 6); Format_pct(pmem, mem, 4); @@ -497,8 +510,10 @@ 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, - opts.o_outpmode & OPT_NORESOLVE); + pwd_getname(lwp->li_info.pr_uid, pname, sizeof (pname), + opts.o_outpmode & OPT_NORESOLVE, + opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC), + LOGIN_WIDTH); if (opts.o_outpmode & OPT_PSINFO) { Format_size(psize, lwp->li_info.pr_size, 6); Format_size(prssize, lwp->li_info.pr_rssize, 6); @@ -531,14 +546,15 @@ list_print(list_t *list) if (opts.o_outpmode & OPT_LGRP) { (void) printf(PSINFO_LINE_LGRP, (int)lwp->li_info.pr_pid, pname, - psize, prssize, pstate, ppri, pnice, - ptime, pcpu, + psize, prssize, pstate, + ppri, pnice, ptime, pcpu, (int)lwp->li_info.pr_lwp.pr_lgrp, lwp->li_info.pr_fname, lwpid); } else { (void) printf(PSINFO_LINE, (int)lwp->li_info.pr_pid, pname, - psize, prssize, pstate, ppri, pnice, + psize, prssize, + pstate, ppri, pnice, ptime, pcpu, lwp->li_info.pr_fname, lwpid); } @@ -1376,7 +1392,7 @@ main(int argc, char **argv) pagesize = sysconf(_SC_PAGESIZE); while ((opt = getopt(argc, argv, - "vVcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJz:Z")) != (int)EOF) { + "vVcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJWz:Z")) != (int)EOF) { switch (opt) { case 'r': opts.o_outpmode |= OPT_NORESOLVE; @@ -1478,6 +1494,9 @@ main(int argc, char **argv) case 'L': opts.o_outpmode |= OPT_LWPS; break; + case 'W': + opts.o_outpmode |= OPT_TRUNC; + break; case 'z': if ((p = strtok(optarg, ", ")) == NULL) Die(gettext("invalid argument for -z\n")); diff --git a/usr/src/cmd/prstat/prstat.h b/usr/src/cmd/prstat/prstat.h index f75bdaf412..bf38b3e2bd 100644 --- a/usr/src/cmd/prstat/prstat.h +++ b/usr/src/cmd/prstat/prstat.h @@ -20,6 +20,8 @@ */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * @@ -75,6 +77,7 @@ extern "C" { #define OPT_UDATE 0x20000 /* print unix timestamp */ #define OPT_DDATE 0x40000 /* print timestamp in date(1) format */ #define OPT_NORESOLVE 0x80000 /* no nsswitch lookups */ +#define OPT_TRUNC 0x100000 /* truncate long names */ /* * 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 87d862140b..e144ef7ff8 100644 --- a/usr/src/cmd/prstat/prtable.c +++ b/usr/src/cmd/prstat/prtable.c @@ -19,6 +19,8 @@ * CDDL HEADER END */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * @@ -35,6 +37,7 @@ #include <errno.h> #include <zone.h> #include <libzonecfg.h> +#include <wchar.h> #include "prstat.h" #include "prutil.h" @@ -59,14 +62,28 @@ pwd_getid(char *name) } void -pwd_getname(uid_t uid, char *name, int length, int noresolve) +pwd_getname(uid_t uid, char *name, size_t length, int noresolve, + int trunc, size_t width) { struct passwd *pwd; + size_t n; if (noresolve || (pwd = getpwuid(uid)) == NULL) { - (void) snprintf(name, length, "%u", uid); + n = snprintf(NULL, 0, "%u", uid); + if (trunc && n > width) + (void) snprintf(name, length, "%.*u%c", + width - 1, uid, '*'); + else + (void) snprintf(name, length, "%u", uid); } else { - (void) snprintf(name, length, "%s", pwd->pw_name); + n = mbstowcs(NULL, pwd->pw_name, 0); + if (n == (size_t)-1) + (void) snprintf(name, length, "%s", "ERROR"); + else if (trunc && n > width) + (void) snprintf(name, length, "%.*s%c", + width - 1, pwd->pw_name, '*'); + else + (void) snprintf(name, length, "%s", pwd->pw_name); } } diff --git a/usr/src/cmd/prstat/prtable.h b/usr/src/cmd/prstat/prtable.h index da8557ac8f..acfc73593c 100644 --- a/usr/src/cmd/prstat/prtable.h +++ b/usr/src/cmd/prstat/prtable.h @@ -19,6 +19,8 @@ * CDDL HEADER END */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * @@ -70,7 +72,7 @@ typedef struct plwp { /* linked list of pointers to lwps */ struct plwp *l_next; } plwp_t; -extern void pwd_getname(uid_t, char *, int, int); +extern void pwd_getname(uid_t, char *, size_t, int, int, size_t); extern void add_uid(uidtbl_t *, char *); extern int has_uid(uidtbl_t *, uid_t); extern void add_element(table_t *, long); diff --git a/usr/src/cmd/prstat/prutil.c b/usr/src/cmd/prstat/prutil.c index 6ff4f5c49f..7def1bd40b 100644 --- a/usr/src/cmd/prstat/prutil.c +++ b/usr/src/cmd/prstat/prutil.c @@ -19,6 +19,8 @@ * CDDL HEADER END */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * @@ -107,7 +109,7 @@ void Usage() { (void) fprintf(stderr, gettext( - "Usage:\tprstat [-acHJLmrRtTvVZ] [-u euidlist] [-U uidlist]\n" + "Usage:\tprstat [-acHJLmrRtTvVWZ] [-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" @@ -279,26 +281,45 @@ Priocntl(char *class) } void -getprojname(projid_t projid, char *str, int len, int noresolve) +getprojname(projid_t projid, char *str, size_t len, int noresolve, + int trunc, size_t width) { struct project proj; + size_t n; if (noresolve || getprojbyid(projid, &proj, projbuf, PROJECT_BUFSZ) == - NULL) + NULL) { (void) snprintf(str, len, "%-6d", (int)projid); - else - (void) snprintf(str, len, "%-28s", proj.pj_name); + } else { + n = mbstowcs(NULL, proj.pj_name, 0); + if (n == (size_t)-1) + (void) snprintf(str, len, "%-28s", "ERROR"); + else if (trunc && n > width) + (void) snprintf(str, len, "%.*s%c", width - 1, + proj.pj_name, '*'); + else + (void) snprintf(str, len, "%-28s", proj.pj_name); + } } void -getzonename(zoneid_t zoneid, char *str, int len) +getzonename(zoneid_t zoneid, char *str, size_t len, int trunc, size_t width) { char zone_name[ZONENAME_MAX]; + size_t n; - if (getzonenamebyid(zoneid, zone_name, sizeof (zone_name)) < 0) + if (getzonenamebyid(zoneid, zone_name, sizeof (zone_name)) < 0) { (void) snprintf(str, len, "%-6d", (int)zoneid); - else - (void) snprintf(str, len, "%-28s", zone_name); + } else { + n = mbstowcs(NULL, zone_name, 0); + if (n == (size_t)-1) + (void) snprintf(str, len, "%-28s", "ERROR"); + else if (trunc && n > width) + (void) snprintf(str, len, "%.*s%c", width - 1, + zone_name, '*'); + else + (void) snprintf(str, len, "%-28s", zone_name); + } } /* diff --git a/usr/src/cmd/prstat/prutil.h b/usr/src/cmd/prstat/prutil.h index c98b3e7908..cfa2133714 100644 --- a/usr/src/cmd/prstat/prutil.h +++ b/usr/src/cmd/prstat/prutil.h @@ -19,6 +19,8 @@ * CDDL HEADER END */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * @@ -50,8 +52,8 @@ extern void *Malloc(size_t); extern void *Zalloc(size_t); extern int Setrlimit(); extern void Priocntl(char *); -extern void getprojname(projid_t, char *, int, int); -extern void getzonename(projid_t, char *, int); +extern void getprojname(projid_t, char *, size_t, int, int, size_t); +extern void getzonename(projid_t, char *, size_t, int, size_t); extern void stripfname(char *); #ifdef __cplusplus |
