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 ↓ 224 lines elided ↑ open up ↑
 347  353  static void
 348  354  list_print(list_t *list)
 349  355  {
 350  356          lwp_info_t *lwp;
 351  357          id_info_t *id;
 352  358          char usr[4], sys[4], trp[4], tfl[4];
 353  359          char dfl[4], lck[4], slp[4], lat[4];
 354  360          char vcx[4], icx[4], scl[4], sig[4];
 355  361          char psize[6], prssize[6], pmem[6], pcpu[6], ptime[12];
 356  362          char pstate[7], pnice[4], ppri[4];
 357      -        char pname[LOGNAME_MAX+1];
      363 +        char pname[LOGNAME_MAX_ILLUMOS+1];
 358  364          char projname[PROJNAME_MAX+1];
 359  365          char zonename[ZONENAME_MAX+1];
 360  366          float cpu, mem;
 361  367          double loadavg[3] = {0, 0, 0};
 362  368          int i, lwpid;
 363  369  
 364  370          if (foreach_element(&set_tbl, &loadavg, psetloadavg) == 0) {
 365  371                  /*
 366  372                   * If processor sets aren't specified, we display system-wide
 367  373                   * load averages.
↓ open down ↓ 71 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,
      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,
      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,
      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,
      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 ↓ 1113 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX