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
  */

@@ -73,10 +75,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 +112,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 \

@@ -444,20 +450,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|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);
                         Format_pct(pcpu, cpu, 4);
                         Format_time(ptime, id->id_time, 10);

@@ -486,12 +499,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|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);
                                 Format_state(pstate,
                                     lwp->li_info.pr_lwp.pr_sname,

@@ -520,18 +535,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');

@@ -1362,11 +1378,11 @@
         fd_init(Setrlimit());
 
         pagesize = sysconf(_SC_PAGESIZE);
 
         while ((opt = getopt(argc, argv,
-            "vcd:HmarRLtu: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:TJWz:Z")) != (int)EOF) {
                 switch (opt) {
                 case 'r':
                         opts.o_outpmode |= OPT_NORESOLVE;
                         break;
                 case 'R':

@@ -1459,10 +1475,13 @@
                         fill_prj_table(optarg);
                         break;
                 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"));
                         add_zone(&zone_tbl, p);
                         while (p = strtok(NULL, ", "))