Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars
@@ -18,10 +18,12 @@
*
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Portions Copyright 2009 Chad Mynhier
*/
@@ -57,10 +59,16 @@
#include "prutil.h"
#include "prtable.h"
#include "prsort.h"
#include "prfile.h"
+#ifdef LOGNAME_MAX_ILLUMOS
+#define _LOGNAME_MAX LOGNAME_MAX_ILLUMOS
+#else /* LOGNAME_MAX_ILLUMOS */
+#define _LOGNAME_MAX LOGNAME_MAX
+#endif /* LOGNAME_MAX_ILLUMOS */
+
/*
* x86 <sys/regs.h> ERR conflicts with <curses.h> ERR. For the purposes
* of this file, we care about the curses.h ERR so include that last.
*/
@@ -73,10 +81,14 @@
#endif
#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 \
" PID USERNAME SIZE RSS STATE PRI NICE TIME CPU LGRP PROCESS/NLWP "
#define PSINFO_HEADER_LWP \
@@ -106,12 +118,12 @@
#define PSINFO_LINE \
"%6d %-8s %5s %5s %-6s %3s %3s %9s %3.3s%% %-.16s/%d"
#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 \
"%6d %8d %5s %5s %3.3s%% %9s %3.3s%% %28s"
#define PROJECT_LINE \
@@ -352,11 +364,11 @@
char usr[4], sys[4], trp[4], tfl[4];
char dfl[4], lck[4], slp[4], lat[4];
char vcx[4], icx[4], scl[4], sig[4];
char psize[6], prssize[6], pmem[6], pcpu[6], ptime[12];
char pstate[7], pnice[4], ppri[4];
- char pname[LOGNAME_MAX+1];
+ char pname[_LOGNAME_MAX+1];
char projname[PROJNAME_MAX+1];
char zonename[ZONENAME_MAX+1];
float cpu, mem;
double loadavg[3] = {0, 0, 0};
int i, lwpid;
@@ -444,20 +456,27 @@
cpu = id->id_pctcpu;
if (id->id_sizematch == B_FALSE && total_mem >= 100)
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,
+ LOGIN_WIDTH);
+ } else if (list->l_type == LT_ZONES) {
getzonename(id->id_zoneid, zonename,
- ZONENAME_MAX);
- else
+ sizeof (zonename) - 1,
+ opts.o_outpmode & OPT_TERMCAP,
+ ZONE_WIDTH);
+ } else {
getprojname(id->id_projid, projname,
- PROJNAME_MAX,
- opts.o_outpmode & OPT_NORESOLVE);
+ sizeof (projname) - 1,
+ opts.o_outpmode & OPT_NORESOLVE,
+ opts.o_outpmode & OPT_TERMCAP,
+ PROJECT_WIDTH);
+ }
Format_size(psize, id->id_size, 6);
Format_size(prssize, id->id_rssize, 6);
Format_pct(pmem, mem, 4);
Format_pct(pcpu, cpu, 4);
Format_time(ptime, id->id_time, 10);
@@ -486,12 +505,14 @@
if (opts.o_outpmode & OPT_LWPS)
lwpid = lwp->li_info.pr_lwp.pr_lwpid;
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,
+ 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);
Format_state(pstate,
lwp->li_info.pr_lwp.pr_sname,
@@ -520,18 +541,19 @@
(void) putchar('\r');
stripfname(lwp->li_info.pr_fname);
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);
}
(void) putp(t_eol);
(void) putchar('\n');