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/prstat/prstat.c
          +++ new/usr/src/cmd/prstat/prstat.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   * Portions Copyright 2009 Chad Mynhier
  27   29   */
  28   30  
  29   31  #include <sys/types.h>
  30   32  #include <sys/resource.h>
  31   33  #include <sys/loadavg.h>
  32   34  #include <sys/time.h>
↓ open down ↓ 35 lines elided ↑ open up ↑
  68   70  #undef  ERR
  69   71  #endif
  70   72  
  71   73  #ifndef TEXT_DOMAIN                     /* should be defined by cc -D */
  72   74  #define TEXT_DOMAIN     "SYS_TEST"      /* use this only if it wasn't */
  73   75  #endif
  74   76  
  75   77  #include <curses.h>
  76   78  #include <term.h>
  77   79  
       80 +#define LOGIN_WIDTH     8
       81 +#define ZONE_WIDTH      28
       82 +#define PROJECT_WIDTH   28
       83 +
  78   84  #define PSINFO_HEADER_PROC \
  79   85  "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP       "
  80   86  #define PSINFO_HEADER_PROC_LGRP \
  81   87  "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/NLWP  "
  82   88  #define PSINFO_HEADER_LWP \
  83   89  "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/LWPID      "
  84   90  #define PSINFO_HEADER_LWP_LGRP \
  85   91  "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/LWPID "
  86   92  #define USAGE_HEADER_PROC \
  87   93  "   PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/NLWP  "
↓ open down ↓ 13 lines elided ↑ open up ↑
 101  107  "PROJID     NLWP  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 102  108  #define ZONE_HEADER_PROC \
 103  109  "ZONEID    NPROC  SWAP   RSS MEMORY      TIME  CPU ZONE                        "
 104  110  #define ZONE_HEADER_LWP \
 105  111  "ZONEID     NLWP  SWAP   RSS MEMORY      TIME  CPU ZONE                        "
 106  112  #define PSINFO_LINE \
 107  113  "%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %-.16s/%d"
 108  114  #define PSINFO_LINE_LGRP \
 109  115  "%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %4d %-.16s/%d"
 110  116  #define USAGE_LINE \
 111      -"%6d %-8s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s "\
 112      -"%3.3s %-.12s/%d"
      117 +"%6d %-8s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s "\
      118 +"%3.3s %3.3s %-.12s/%d"
 113  119  #define USER_LINE \
 114  120  "%6d %-8s %5.5s %5.5s   %3.3s%% %9s %3.3s%%"
 115  121  #define TASK_LINE \
 116  122  "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 117  123  #define PROJECT_LINE \
 118  124  "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 119  125  #define ZONE_LINE \
 120  126  "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 121  127  
 122  128  #define TOTAL_LINE \
↓ open down ↓ 316 lines elided ↑ open up ↑
 439  445                           * CPU usage and memory usage normalization
 440  446                           */
 441  447                          if (total_cpu >= 100)
 442  448                                  cpu = (100 * id->id_pctcpu) / total_cpu;
 443  449                          else
 444  450                                  cpu = id->id_pctcpu;
 445  451                          if (id->id_sizematch == B_FALSE && total_mem >= 100)
 446  452                                  mem = (100 * id->id_pctmem) / total_mem;
 447  453                          else
 448  454                                  mem = id->id_pctmem;
 449      -                        if (list->l_type == LT_USERS)
 450      -                                pwd_getname(id->id_uid, pname, LOGNAME_MAX + 1,
 451      -                                    opts.o_outpmode & OPT_NORESOLVE);
 452      -                        else if (list->l_type == LT_ZONES)
      455 +                        if (list->l_type == LT_USERS) {
      456 +                                pwd_getname(id->id_uid, pname, sizeof (pname),
      457 +                                    opts.o_outpmode & OPT_NORESOLVE,
      458 +                                    opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
      459 +                                    LOGIN_WIDTH);
      460 +                        } else if (list->l_type == LT_ZONES) {
 453  461                                  getzonename(id->id_zoneid, zonename,
 454      -                                    ZONENAME_MAX);
 455      -                        else
      462 +                                    sizeof (zonename) - 1,
      463 +                                    opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
      464 +                                    ZONE_WIDTH);
      465 +                        } else {
 456  466                                  getprojname(id->id_projid, projname,
 457      -                                    PROJNAME_MAX,
 458      -                                    opts.o_outpmode & OPT_NORESOLVE);
      467 +                                    sizeof (projname) - 1,
      468 +                                    opts.o_outpmode & OPT_NORESOLVE,
      469 +                                    opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
      470 +                                    PROJECT_WIDTH);
      471 +                        }
 459  472                          Format_size(psize, id->id_size, 6);
 460  473                          Format_size(prssize, id->id_rssize, 6);
 461  474                          Format_pct(pmem, mem, 4);
 462  475                          Format_pct(pcpu, cpu, 4);
 463  476                          Format_time(ptime, id->id_time, 10);
 464  477                          if (opts.o_outpmode & OPT_TTY)
 465  478                                  (void) putchar('\r');
 466  479                          if (list->l_type == LT_PROJECTS)
 467  480                                  (void) printf(PROJECT_LINE, (int)id->id_projid,
 468  481                                      id->id_nproc, psize, prssize, pmem, ptime,
↓ open down ↓ 12 lines elided ↑ open up ↑
 481  494                          (void) putp(t_eol);
 482  495                          (void) putchar('\n');
 483  496                          break;
 484  497                  case LT_LWPS:
 485  498                          lwp = list->l_ptrs[i];
 486  499                          if (opts.o_outpmode & OPT_LWPS)
 487  500                                  lwpid = lwp->li_info.pr_lwp.pr_lwpid;
 488  501                          else
 489  502                                  lwpid = lwp->li_info.pr_nlwp +
 490  503                                      lwp->li_info.pr_nzomb;
 491      -                        pwd_getname(lwp->li_info.pr_uid, pname, LOGNAME_MAX + 1,
 492      -                            opts.o_outpmode & OPT_NORESOLVE);
      504 +                        pwd_getname(lwp->li_info.pr_uid, pname, sizeof (pname),
      505 +                            opts.o_outpmode & OPT_NORESOLVE,
      506 +                            opts.o_outpmode & (OPT_TERMCAP|OPT_TRUNC),
      507 +                            LOGIN_WIDTH);
 493  508                          if (opts.o_outpmode & OPT_PSINFO) {
 494  509                                  Format_size(psize, lwp->li_info.pr_size, 6);
 495  510                                  Format_size(prssize, lwp->li_info.pr_rssize, 6);
 496  511                                  Format_state(pstate,
 497  512                                      lwp->li_info.pr_lwp.pr_sname,
 498  513                                      lwp->li_info.pr_lwp.pr_onpro, 7);
 499  514                                  if (strcmp(lwp->li_info.pr_lwp.pr_clname,
 500  515                                      "RT") == 0 ||
 501  516                                      strcmp(lwp->li_info.pr_lwp.pr_clname,
 502  517                                      "SYS") == 0 ||
↓ open down ↓ 12 lines elided ↑ open up ↑
 515  530                                              10);
 516  531                                  else
 517  532                                          Format_time(ptime,
 518  533                                              lwp->li_info.pr_time.tv_sec, 10);
 519  534                                  if (opts.o_outpmode & OPT_TTY)
 520  535                                          (void) putchar('\r');
 521  536                                  stripfname(lwp->li_info.pr_fname);
 522  537                                  if (opts.o_outpmode & OPT_LGRP) {
 523  538                                          (void) printf(PSINFO_LINE_LGRP,
 524  539                                              (int)lwp->li_info.pr_pid, pname,
 525      -                                            psize, prssize, pstate, ppri, pnice,
 526      -                                            ptime, pcpu,
      540 +                                            psize, prssize, pstate,
      541 +                                            ppri, pnice, ptime, pcpu,
 527  542                                              (int)lwp->li_info.pr_lwp.pr_lgrp,
 528  543                                              lwp->li_info.pr_fname, lwpid);
 529  544                                  } else {
 530  545                                          (void) printf(PSINFO_LINE,
 531  546                                              (int)lwp->li_info.pr_pid, pname,
 532      -                                            psize, prssize, pstate, ppri, pnice,
      547 +                                            psize, prssize,
      548 +                                            pstate, ppri, pnice,
 533  549                                              ptime, pcpu,
 534  550                                              lwp->li_info.pr_fname, lwpid);
 535  551                                  }
 536  552                                  (void) putp(t_eol);
 537  553                                  (void) putchar('\n');
 538  554                          }
 539  555                          if (opts.o_outpmode & OPT_MSACCT) {
 540  556                                  Format_pct(usr, lwp->li_usr, 4);
 541  557                                  Format_pct(sys, lwp->li_sys, 4);
 542  558                                  Format_pct(slp, lwp->li_slp, 4);
↓ open down ↓ 814 lines elided ↑ open up ↑
1357 1373  
1358 1374          (void) setlocale(LC_ALL, "");
1359 1375          (void) textdomain(TEXT_DOMAIN);
1360 1376          Progname(argv[0]);
1361 1377          lwpid_init();
1362 1378          fd_init(Setrlimit());
1363 1379  
1364 1380          pagesize = sysconf(_SC_PAGESIZE);
1365 1381  
1366 1382          while ((opt = getopt(argc, argv,
1367      -            "vcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJz:Z")) != (int)EOF) {
     1383 +            "vcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJWz:Z")) != (int)EOF) {
1368 1384                  switch (opt) {
1369 1385                  case 'r':
1370 1386                          opts.o_outpmode |= OPT_NORESOLVE;
1371 1387                          break;
1372 1388                  case 'R':
1373 1389                          opts.o_outpmode |= OPT_REALTIME;
1374 1390                          break;
1375 1391                  case 'c':
1376 1392                          opts.o_outpmode &= ~OPT_TERMCAP;
1377 1393                          opts.o_outpmode &= ~OPT_FULLSCREEN;
↓ open down ↓ 76 lines elided ↑ open up ↑
1454 1470                          break;
1455 1471                  case 'k':
1456 1472                          fill_table(&tsk_tbl, optarg, 'k');
1457 1473                          break;
1458 1474                  case 'j':
1459 1475                          fill_prj_table(optarg);
1460 1476                          break;
1461 1477                  case 'L':
1462 1478                          opts.o_outpmode |= OPT_LWPS;
1463 1479                          break;
     1480 +                case 'W':
     1481 +                        opts.o_outpmode |= OPT_TRUNC;
     1482 +                        break;
1464 1483                  case 'z':
1465 1484                          if ((p = strtok(optarg, ", ")) == NULL)
1466 1485                                  Die(gettext("invalid argument for -z\n"));
1467 1486                          add_zone(&zone_tbl, p);
1468 1487                          while (p = strtok(NULL, ", "))
1469 1488                                  add_zone(&zone_tbl, p);
1470 1489                          break;
1471 1490                  case 'Z':
1472 1491                          opts.o_outpmode |= OPT_SPLIT | OPT_ZONES;
1473 1492                          break;
↓ open down ↓ 182 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX