Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ps/ps.c
          +++ new/usr/src/cmd/ps/ps.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
       23 + * Copyright (c) 2013 Gary Mills
       24 + *
  23   25   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   26   * Use is subject to license terms.
  25   27   */
  26   28  
  27   29  /*
  28   30   * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  29   31   */
  30   32  
  31   33  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  32   34  /*        All Rights Reserved   */
↓ open down ↓ 36 lines elided ↑ open up ↑
  69   71  #define NTTYS   20      /* initial size of table for -t option  */
  70   72  #define SIZ     30      /* initial size of tables for -p, -s, -g, -h and -z */
  71   73  
  72   74  /*
  73   75   * Size of buffer holding args for t, p, s, g, u, U, G, z options.
  74   76   * Set to ZONENAME_MAX, the minimum value needed to allow any
  75   77   * zone to be specified.
  76   78   */
  77   79  #define ARGSIZ ZONENAME_MAX
  78   80  
  79      -#define MAXUGNAME 10    /* max chars in a user/group name or printed u/g id */
       81 +#define MAXUGNAME (LOGNAME_MAX+2)       /* max chars in a user/group */
       82 +                                                /* name or printed u/g id */
  80   83  
  81   84  /* Structure for storing user or group info */
  82   85  struct ugdata {
  83   86          id_t    id;                     /* numeric user-id or group-id */
  84   87          char    name[MAXUGNAME+1];      /* user/group name, null terminated */
  85   88  };
  86   89  
  87   90  struct ughead {
  88   91          size_t  size;           /* number of ugdata structs allocated */
  89   92          size_t  nent;           /* number of active entries */
↓ open down ↓ 127 lines elided ↑ open up ↑
 217  220  static  int     retcode = 1;
 218  221  static  int     lflg;
 219  222  static  int     Aflg;
 220  223  static  int     uflg;
 221  224  static  int     Uflg;
 222  225  static  int     Gflg;
 223  226  static  int     aflg;
 224  227  static  int     dflg;
 225  228  static  int     Lflg;
 226  229  static  int     Pflg;
      230 +static  int     Wflg;
 227  231  static  int     yflg;
 228  232  static  int     pflg;
 229  233  static  int     fflg;
 230  234  static  int     cflg;
 231  235  static  int     jflg;
 232  236  static  int     gflg;
 233  237  static  int     sflg;
 234  238  static  int     tflg;
 235  239  static  int     zflg;
 236  240  static  int     Zflg;
↓ open down ↓ 180 lines elided ↑ open up ↑
 417  421           * Specify the printf format with width and precision for
 418  422           * the STIME field.
 419  423           */
 420  424          len = snprintf(loc_stime_str, sizeof (loc_stime_str),
 421  425              dcgettext(NULL, "%8.8s", LC_TIME), "STIME");
 422  426          if (len >= sizeof (loc_stime_str))
 423  427                  len = sizeof (loc_stime_str) - 1;
 424  428  
 425  429          fname[F_STIME].width = fname[F_STIME].minwidth = len;
 426  430  
 427      -        while ((c = getopt(argc, argv, "jlfceAadLPyZHh:t:p:g:u:U:G:n:s:o:z:"))
      431 +        while ((c = getopt(argc, argv, "jlfceAadLPWyZHh:t:p:g:u:U:G:n:s:o:z:"))
 428  432              != EOF)
 429  433                  switch (c) {
 430  434                  case 'H':               /* Show home lgroups */
 431  435                          Hflg++;
 432  436                          break;
 433  437                  case 'h':
 434  438                          /*
 435  439                           * Show processes/threads with given home lgroups
 436  440                           */
 437  441                          hflg++;
↓ open down ↓ 73 lines elided ↑ open up ↑
 511  515                          break;
 512  516                  case 'd':       /* same as e except no session leaders */
 513  517                          dflg++;
 514  518                          break;
 515  519                  case 'L':       /* show lwps */
 516  520                          Lflg++;
 517  521                          break;
 518  522                  case 'P':       /* show bound processor */
 519  523                          Pflg++;
 520  524                          break;
      525 +                case 'W':       /* truncate long names */
      526 +                        Wflg++;
      527 +                        break;
 521  528                  case 'y':       /* omit F & ADDR, report RSS & SZ in Kby */
 522  529                          yflg++;
 523  530                          break;
 524  531                  case 'n':       /* no longer needed; retain as no-op */
 525  532                          (void) fprintf(stderr,
 526  533                              gettext("ps: warning: -n option ignored\n"));
 527  534                          break;
 528  535                  case 't':               /* terminals */
 529  536  #define TSZ     30
 530  537                          tflg++;
↓ open down ↓ 519 lines elided ↑ open up ↑
1050 1057          return (strcmp(lhs->fname, rhs->fname));
1051 1058  }
1052 1059  
1053 1060  static void
1054 1061  usage(void)             /* print usage message and quit */
1055 1062  {
1056 1063          struct def_field *df, *sorted[NFIELDS];
1057 1064          int pos = 80, i = 0;
1058 1065  
1059 1066          static char usage1[] =
1060      -            "ps [ -aAdefHlcjLPyZ ] [ -o format ] [ -t termlist ]";
     1067 +            "ps [ -aAdefHlcjLPWyZ ] [ -o format ] [ -t termlist ]";
1061 1068          static char usage2[] =
1062 1069              "\t[ -u userlist ] [ -U userlist ] [ -G grouplist ]";
1063 1070          static char usage3[] =
1064 1071              "\t[ -p proclist ] [ -g pgrplist ] [ -s sidlist ]";
1065 1072          static char usage4[] =
1066 1073              "\t[ -z zonelist ] [-h lgrplist]";
1067 1074          static char usage5[] =
1068 1075              "  'format' is one or more of:";
1069 1076  
1070 1077          (void) fprintf(stderr,
↓ open down ↓ 319 lines elided ↑ open up ↑
1390 1397                  if (!yflg)
1391 1398                          (void) printf("%2x ", psinfo->pr_flag & 0377); /* F */
1392 1399                  (void) printf("%c ", psinfo->pr_lwp.pr_sname);  /* S */
1393 1400          }
1394 1401  
1395 1402          if (Zflg) {                                             /* ZONE */
1396 1403                  if (getzonenamebyid(psinfo->pr_zoneid, zonename,
1397 1404                      sizeof (zonename)) < 0) {
1398 1405                          (void) printf(" %7.7d ", ((int)psinfo->pr_zoneid));
1399 1406                  } else {
1400      -                        (void) printf("%8.8s ", zonename);
     1407 +                        if (strlen(zonename) > 8)
     1408 +                                (void) printf("%7.7s%c ", zonename, '*');
     1409 +                        else
     1410 +                                (void) printf("%8.8s ", zonename);
1401 1411                  }
1402 1412          }
1403 1413  
1404 1414          if (fflg) {                                             /* UID */
1405      -                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
1406      -                        (void) printf("%8.8s ", pwd->pw_name);
1407      -                else
     1415 +                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
     1416 +                        if (strlen(pwd->pw_name) > 8)
     1417 +                                (void) printf("%7.7s%c ", pwd->pw_name, '*');
     1418 +                        else
     1419 +                                (void) printf("%8.8s ", pwd->pw_name);
     1420 +                } else {
1408 1421                          (void) printf(" %7.7u ", psinfo->pr_euid);
     1422 +                }
1409 1423          } else if (lflg) {
1410 1424                  (void) printf("%6u ", psinfo->pr_euid);
1411 1425          }
1412 1426          (void) printf("%*d", pidwidth, (int)psinfo->pr_pid); /* PID */
1413 1427          if (lflg || fflg)
1414 1428                  (void) printf(" %*d", pidwidth,
1415 1429                      (int)psinfo->pr_ppid); /* PPID */
1416 1430          if (jflg) {
1417 1431                  (void) printf(" %*d", pidwidth,
1418 1432                      (int)psinfo->pr_pgid);      /* PGID */
↓ open down ↓ 202 lines elided ↑ open up ↑
1621 1635          char *cp;
1622 1636          int length;
1623 1637          ulong_t mask;
1624 1638          char c, *csave;
1625 1639          int zombie_lwp;
1626 1640  
1627 1641          zombie_lwp = (Lflg && psinfo->pr_lwp.pr_sname == 'Z');
1628 1642  
1629 1643          switch (f->fname) {
1630 1644          case F_RUSER:
1631      -                if ((pwd = getpwuid(psinfo->pr_uid)) != NULL)
1632      -                        (void) printf("%*s", width, pwd->pw_name);
1633      -                else
     1645 +                if ((pwd = getpwuid(psinfo->pr_uid)) != NULL) {
     1646 +                        if (Wflg && strlen(pwd->pw_name) > width)
     1647 +                                (void) printf("%.*s%c", width - 1,
     1648 +                                    pwd->pw_name, '*');
     1649 +                        else
     1650 +                                (void) printf("%*s", width, pwd->pw_name);
     1651 +                } else {
1634 1652                          (void) printf("%*u", width, psinfo->pr_uid);
     1653 +                }
1635 1654                  break;
1636 1655          case F_USER:
1637      -                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
1638      -                        (void) printf("%*s", width, pwd->pw_name);
1639      -                else
     1656 +                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
     1657 +                        if (Wflg && strlen(pwd->pw_name) > width)
     1658 +                                (void) printf("%.*s%c", width - 1,
     1659 +                                    pwd->pw_name, '*');
     1660 +                        else
     1661 +                                (void) printf("%*s", width, pwd->pw_name);
     1662 +                } else {
1640 1663                          (void) printf("%*u", width, psinfo->pr_euid);
     1664 +                }
1641 1665                  break;
1642 1666          case F_RGROUP:
1643 1667                  if ((grp = getgrgid(psinfo->pr_gid)) != NULL)
1644 1668                          (void) printf("%*s", width, grp->gr_name);
1645 1669                  else
1646 1670                          (void) printf("%*u", width, psinfo->pr_gid);
1647 1671                  break;
1648 1672          case F_GROUP:
1649 1673                  if ((grp = getgrgid(psinfo->pr_egid)) != NULL)
1650 1674                          (void) printf("%*s", width, grp->gr_name);
↓ open down ↓ 221 lines elided ↑ open up ↑
1872 1896                  break;
1873 1897          case F_PROJID:
1874 1898                  (void) printf("%*d", width, (int)psinfo->pr_projid);
1875 1899                  break;
1876 1900          case F_PROJECT:
1877 1901                  {
1878 1902                          struct project cproj;
1879 1903                          char proj_buf[PROJECT_BUFSZ];
1880 1904  
1881 1905                          if ((getprojbyid(psinfo->pr_projid, &cproj,
1882      -                            (void *)&proj_buf, PROJECT_BUFSZ)) == NULL)
     1906 +                            (void *)&proj_buf, PROJECT_BUFSZ)) == NULL) {
1883 1907                                  (void) printf("%*d", width,
1884 1908                                      (int)psinfo->pr_projid);
1885      -                        else
1886      -                                (void) printf("%*s", width,
1887      -                                    (cproj.pj_name != NULL) ?
1888      -                                    cproj.pj_name : "---");
     1909 +                        } else {
     1910 +                                if (Wflg && cproj.pj_name != NULL &&
     1911 +                                    strlen(cproj.pj_name) > width)
     1912 +                                        (void) printf("%.*s%c", width - 1,
     1913 +                                            cproj.pj_name, '*');
     1914 +                                else
     1915 +                                        (void) printf("%*s", width,
     1916 +                                            (cproj.pj_name != NULL) ?
     1917 +                                            cproj.pj_name : "---");
     1918 +                        }
1889 1919                  }
1890 1920                  break;
1891 1921          case F_PSET:
1892 1922                  if (zombie_lwp || psinfo->pr_lwp.pr_bindpset == PS_NONE)
1893 1923                          (void) printf("%*s", width, "-");
1894 1924                  else
1895 1925                          (void) printf("%*d", width, psinfo->pr_lwp.pr_bindpset);
1896 1926                  break;
1897 1927          case F_ZONEID:
1898 1928                  (void) printf("%*d", width, (int)psinfo->pr_zoneid);
1899 1929                  break;
1900 1930          case F_ZONE:
1901 1931                  {
1902 1932                          char zonename[ZONENAME_MAX];
1903 1933  
1904 1934                          if (getzonenamebyid(psinfo->pr_zoneid, zonename,
1905 1935                              sizeof (zonename)) < 0) {
1906 1936                                  (void) printf("%*d", width,
1907 1937                                      ((int)psinfo->pr_zoneid));
1908 1938                          } else {
1909      -                                (void) printf("%*s", width, zonename);
     1939 +                                if (Wflg && strlen(zonename) > width)
     1940 +                                        (void) printf("%.*s%c", width - 1,
     1941 +                                            zonename, '*');
     1942 +                                else
     1943 +                                        (void) printf("%*s", width, zonename);
1910 1944                          }
1911 1945                  }
1912 1946                  break;
1913 1947          case F_CTID:
1914 1948                  if (psinfo->pr_contract == -1)
1915 1949                          (void) printf("%*s", width, "-");
1916 1950                  else
1917 1951                          (void) printf("%*ld", width, (long)psinfo->pr_contract);
1918 1952                  break;
1919 1953          case F_LGRP:
↓ open down ↓ 256 lines elided ↑ open up ↑
2176 2210          if (lflg) {     /* F S */
2177 2211                  if (!yflg)
2178 2212                          (void) printf("%2x ", psinfo->pr_flag & 0377); /* F */
2179 2213                  (void) printf("%c ", psinfo->pr_lwp.pr_sname);  /* S */
2180 2214          }
2181 2215          if (Zflg) {
2182 2216                  if (getzonenamebyid(psinfo->pr_zoneid, zonename,
2183 2217                      sizeof (zonename)) < 0) {
2184 2218                          (void) printf(" %7.7d ", ((int)psinfo->pr_zoneid));
2185 2219                  } else {
2186      -                        (void) printf("%8.8s ", zonename);
     2220 +                        if (strlen(zonename) > 8)
     2221 +                                (void) printf("%7.7s%c ", zonename, '*');
     2222 +                        else
     2223 +                                (void) printf("%8.8s ", zonename);
2187 2224                  }
2188 2225          }
2189 2226          if (Hflg) {
2190 2227                  /* Display home lgroup */
2191 2228                  (void) printf(" %6d", (int)psinfo->pr_lwp.pr_lgrp); /* LGRP */
2192 2229          }
2193 2230          if (fflg) {
2194      -                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
2195      -                        (void) printf("%8.8s ", pwd->pw_name);
2196      -                else
     2231 +                if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
     2232 +                        if (strlen(pwd->pw_name) > 8)
     2233 +                                (void) printf("%7.7s%c ", pwd->pw_name, '*');
     2234 +                        else
     2235 +                                (void) printf("%8.8s ", pwd->pw_name);
     2236 +                } else {
2197 2237                          (void) printf(" %7.7u ", psinfo->pr_euid);
     2238 +                }
2198 2239          } else if (lflg)
2199 2240                  (void) printf("%6u ", psinfo->pr_euid);
2200 2241  
2201 2242          (void) printf("%*d", pidwidth, (int)psinfo->pr_pid);    /* PID */
2202 2243          if (lflg || fflg)
2203 2244                  (void) printf(" %*d", pidwidth,
2204 2245                      (int)psinfo->pr_ppid);                      /* PPID */
2205 2246  
2206 2247          if (jflg) {
2207 2248                  (void) printf(" %*d", pidwidth,
↓ open down ↓ 188 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX