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

@@ -74,11 +76,12 @@
  * Set to ZONENAME_MAX, the minimum value needed to allow any
  * zone to be specified.
  */
 #define ARGSIZ ZONENAME_MAX
 
-#define MAXUGNAME 10    /* max chars in a user/group name or printed u/g id */
+#define MAXUGNAME (LOGNAME_MAX+2)       /* max chars in a user/group */
+                                                /* name or printed u/g id */
 
 /* Structure for storing user or group info */
 struct ugdata {
         id_t    id;                     /* numeric user-id or group-id */
         char    name[MAXUGNAME+1];      /* user/group name, null terminated */

@@ -222,10 +225,11 @@
 static  int     Gflg;
 static  int     aflg;
 static  int     dflg;
 static  int     Lflg;
 static  int     Pflg;
+static  int     Wflg;
 static  int     yflg;
 static  int     pflg;
 static  int     fflg;
 static  int     cflg;
 static  int     jflg;

@@ -422,11 +426,11 @@
         if (len >= sizeof (loc_stime_str))
                 len = sizeof (loc_stime_str) - 1;
 
         fname[F_STIME].width = fname[F_STIME].minwidth = len;
 
-        while ((c = getopt(argc, argv, "jlfceAadLPyZHh:t:p:g:u:U:G:n:s:o:z:"))
+        while ((c = getopt(argc, argv, "jlfceAadLPWyZHh:t:p:g:u:U:G:n:s:o:z:"))
             != EOF)
                 switch (c) {
                 case 'H':               /* Show home lgroups */
                         Hflg++;
                         break;

@@ -516,10 +520,13 @@
                         Lflg++;
                         break;
                 case 'P':       /* show bound processor */
                         Pflg++;
                         break;
+                case 'W':       /* truncate long names */
+                        Wflg++;
+                        break;
                 case 'y':       /* omit F & ADDR, report RSS & SZ in Kby */
                         yflg++;
                         break;
                 case 'n':       /* no longer needed; retain as no-op */
                         (void) fprintf(stderr,

@@ -1055,11 +1062,11 @@
 {
         struct def_field *df, *sorted[NFIELDS];
         int pos = 80, i = 0;
 
         static char usage1[] =
-            "ps [ -aAdefHlcjLPyZ ] [ -o format ] [ -t termlist ]";
+            "ps [ -aAdefHlcjLPWyZ ] [ -o format ] [ -t termlist ]";
         static char usage2[] =
             "\t[ -u userlist ] [ -U userlist ] [ -G grouplist ]";
         static char usage3[] =
             "\t[ -p proclist ] [ -g pgrplist ] [ -s sidlist ]";
         static char usage4[] =

@@ -1395,19 +1402,26 @@
         if (Zflg) {                                             /* ZONE */
                 if (getzonenamebyid(psinfo->pr_zoneid, zonename,
                     sizeof (zonename)) < 0) {
                         (void) printf(" %7.7d ", ((int)psinfo->pr_zoneid));
                 } else {
+                        if (strlen(zonename) > 8)
+                                (void) printf("%7.7s%c ", zonename, '*');
+                        else
                         (void) printf("%8.8s ", zonename);
                 }
         }
 
         if (fflg) {                                             /* UID */
-                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
-                        (void) printf("%8.8s ", pwd->pw_name);
+                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
+                        if (strlen(pwd->pw_name) > 8)
+                                (void) printf("%7.7s%c ", pwd->pw_name, '*');
                 else
+                                (void) printf("%8.8s ", pwd->pw_name);
+                } else {
                         (void) printf(" %7.7u ", psinfo->pr_euid);
+                }
         } else if (lflg) {
                 (void) printf("%6u ", psinfo->pr_euid);
         }
         (void) printf("%*d", pidwidth, (int)psinfo->pr_pid); /* PID */
         if (lflg || fflg)

@@ -1626,20 +1640,30 @@
 
         zombie_lwp = (Lflg && psinfo->pr_lwp.pr_sname == 'Z');
 
         switch (f->fname) {
         case F_RUSER:
-                if ((pwd = getpwuid(psinfo->pr_uid)) != NULL)
-                        (void) printf("%*s", width, pwd->pw_name);
+                if ((pwd = getpwuid(psinfo->pr_uid)) != NULL) {
+                        if (Wflg && strlen(pwd->pw_name) > width)
+                                (void) printf("%.*s%c", width - 1,
+                                    pwd->pw_name, '*');
                 else
+                                (void) printf("%*s", width, pwd->pw_name);
+                } else {
                         (void) printf("%*u", width, psinfo->pr_uid);
+                }
                 break;
         case F_USER:
-                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
-                        (void) printf("%*s", width, pwd->pw_name);
+                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
+                        if (Wflg && strlen(pwd->pw_name) > width)
+                                (void) printf("%.*s%c", width - 1,
+                                    pwd->pw_name, '*');
                 else
+                                (void) printf("%*s", width, pwd->pw_name);
+                } else {
                         (void) printf("%*u", width, psinfo->pr_euid);
+                }
                 break;
         case F_RGROUP:
                 if ((grp = getgrgid(psinfo->pr_gid)) != NULL)
                         (void) printf("%*s", width, grp->gr_name);
                 else

@@ -1877,18 +1901,24 @@
                 {
                         struct project cproj;
                         char proj_buf[PROJECT_BUFSZ];
 
                         if ((getprojbyid(psinfo->pr_projid, &cproj,
-                            (void *)&proj_buf, PROJECT_BUFSZ)) == NULL)
+                            (void *)&proj_buf, PROJECT_BUFSZ)) == NULL) {
                                 (void) printf("%*d", width,
                                     (int)psinfo->pr_projid);
+                        } else {
+                                if (Wflg && cproj.pj_name != NULL &&
+                                    strlen(cproj.pj_name) > width)
+                                        (void) printf("%.*s%c", width - 1,
+                                            cproj.pj_name, '*');
                         else
                                 (void) printf("%*s", width,
                                     (cproj.pj_name != NULL) ?
                                     cproj.pj_name : "---");
                 }
+                }
                 break;
         case F_PSET:
                 if (zombie_lwp || psinfo->pr_lwp.pr_bindpset == PS_NONE)
                         (void) printf("%*s", width, "-");
                 else

@@ -1904,10 +1934,14 @@
                         if (getzonenamebyid(psinfo->pr_zoneid, zonename,
                             sizeof (zonename)) < 0) {
                                 (void) printf("%*d", width,
                                     ((int)psinfo->pr_zoneid));
                         } else {
+                                if (Wflg && strlen(zonename) > width)
+                                        (void) printf("%.*s%c", width - 1,
+                                            zonename, '*');
+                                else
                                 (void) printf("%*s", width, zonename);
                         }
                 }
                 break;
         case F_CTID:

@@ -2181,22 +2215,29 @@
         if (Zflg) {
                 if (getzonenamebyid(psinfo->pr_zoneid, zonename,
                     sizeof (zonename)) < 0) {
                         (void) printf(" %7.7d ", ((int)psinfo->pr_zoneid));
                 } else {
+                        if (strlen(zonename) > 8)
+                                (void) printf("%7.7s%c ", zonename, '*');
+                        else
                         (void) printf("%8.8s ", zonename);
                 }
         }
         if (Hflg) {
                 /* Display home lgroup */
                 (void) printf(" %6d", (int)psinfo->pr_lwp.pr_lgrp); /* LGRP */
         }
         if (fflg) {
-                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
-                        (void) printf("%8.8s ", pwd->pw_name);
+                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
+                        if (strlen(pwd->pw_name) > 8)
+                                (void) printf("%7.7s%c ", pwd->pw_name, '*');
                 else
+                                (void) printf("%8.8s ", pwd->pw_name);
+                } else {
                         (void) printf(" %7.7u ", psinfo->pr_euid);
+                }
         } else if (lflg)
                 (void) printf("%6u ", psinfo->pr_euid);
 
         (void) printf("%*d", pidwidth, (int)psinfo->pr_pid);    /* PID */
         if (lflg || fflg)