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 ↓ 19 lines elided ↑ open up ↑
  52   54  #include <langinfo.h>
  53   55  #include <libintl.h>
  54   56  #include <locale.h>
  55   57  
  56   58  #include "prstat.h"
  57   59  #include "prutil.h"
  58   60  #include "prtable.h"
  59   61  #include "prsort.h"
  60   62  #include "prfile.h"
  61   63  
       64 +#ifdef  LOGNAME_MAX_ILLUMOS
       65 +#define _LOGNAME_MAX    LOGNAME_MAX_ILLUMOS
       66 +#else /* LOGNAME_MAX_ILLUMOS */
       67 +#define _LOGNAME_MAX    LOGNAME_MAX
       68 +#endif /* LOGNAME_MAX_ILLUMOS */
       69 +
  62   70  /*
  63   71   * x86 <sys/regs.h> ERR conflicts with <curses.h> ERR.  For the purposes
  64   72   * of this file, we care about the curses.h ERR so include that last.
  65   73   */
  66   74  
  67   75  #if     defined(ERR)
  68   76  #undef  ERR
  69   77  #endif
  70   78  
  71   79  #ifndef TEXT_DOMAIN                     /* should be defined by cc -D */
  72   80  #define TEXT_DOMAIN     "SYS_TEST"      /* use this only if it wasn't */
  73   81  #endif
  74   82  
  75   83  #include <curses.h>
  76   84  #include <term.h>
  77   85  
       86 +#define LOGIN_WIDTH     8
       87 +#define ZONE_WIDTH      28
       88 +#define PROJECT_WIDTH   28
       89 +
  78   90  #define PSINFO_HEADER_PROC \
  79   91  "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP       "
  80   92  #define PSINFO_HEADER_PROC_LGRP \
  81   93  "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/NLWP  "
  82   94  #define PSINFO_HEADER_LWP \
  83   95  "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/LWPID      "
  84   96  #define PSINFO_HEADER_LWP_LGRP \
  85   97  "   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU LGRP PROCESS/LWPID "
  86   98  #define USAGE_HEADER_PROC \
  87   99  "   PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/NLWP  "
↓ open down ↓ 13 lines elided ↑ open up ↑
 101  113  "PROJID     NLWP  SWAP   RSS MEMORY      TIME  CPU PROJECT                     "
 102  114  #define ZONE_HEADER_PROC \
 103  115  "ZONEID    NPROC  SWAP   RSS MEMORY      TIME  CPU ZONE                        "
 104  116  #define ZONE_HEADER_LWP \
 105  117  "ZONEID     NLWP  SWAP   RSS MEMORY      TIME  CPU ZONE                        "
 106  118  #define PSINFO_LINE \
 107  119  "%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %-.16s/%d"
 108  120  #define PSINFO_LINE_LGRP \
 109  121  "%6d %-8s %5s %5s %-6s %3s  %3s %9s %3.3s%% %4d %-.16s/%d"
 110  122  #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"
      123 +"%6d %-8s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s %3.3s "\
      124 +"%3.3s %3.3s %-.12s/%d"
 113  125  #define USER_LINE \
 114  126  "%6d %-8s %5.5s %5.5s   %3.3s%% %9s %3.3s%%"
 115  127  #define TASK_LINE \
 116  128  "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 117  129  #define PROJECT_LINE \
 118  130  "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 119  131  #define ZONE_LINE \
 120  132  "%6d %8d %5s %5s   %3.3s%% %9s %3.3s%% %28s"
 121  133  
 122  134  #define TOTAL_LINE \
↓ open down ↓ 224 lines elided ↑ open up ↑
 347  359  static void
 348  360  list_print(list_t *list)
 349  361  {
 350  362          lwp_info_t *lwp;
 351  363          id_info_t *id;
 352  364          char usr[4], sys[4], trp[4], tfl[4];
 353  365          char dfl[4], lck[4], slp[4], lat[4];
 354  366          char vcx[4], icx[4], scl[4], sig[4];
 355  367          char psize[6], prssize[6], pmem[6], pcpu[6], ptime[12];
 356  368          char pstate[7], pnice[4], ppri[4];
 357      -        char pname[LOGNAME_MAX+1];
      369 +        char pname[_LOGNAME_MAX+1];
 358  370          char projname[PROJNAME_MAX+1];
 359  371          char zonename[ZONENAME_MAX+1];
 360  372          float cpu, mem;
 361  373          double loadavg[3] = {0, 0, 0};
 362  374          int i, lwpid;
 363  375  
 364  376          if (foreach_element(&set_tbl, &loadavg, psetloadavg) == 0) {
 365  377                  /*
 366  378                   * If processor sets aren't specified, we display system-wide
 367  379                   * load averages.
↓ open down ↓ 71 lines elided ↑ open up ↑
 439  451                           * CPU usage and memory usage normalization
 440  452                           */
 441  453                          if (total_cpu >= 100)
 442  454                                  cpu = (100 * id->id_pctcpu) / total_cpu;
 443  455                          else
 444  456                                  cpu = id->id_pctcpu;
 445  457                          if (id->id_sizematch == B_FALSE && total_mem >= 100)
 446  458                                  mem = (100 * id->id_pctmem) / total_mem;
 447  459                          else
 448  460                                  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)
      461 +                        if (list->l_type == LT_USERS) {
      462 +                                pwd_getname(id->id_uid, pname, sizeof (pname),
      463 +                                    opts.o_outpmode & OPT_NORESOLVE,
      464 +                                    opts.o_outpmode & OPT_TERMCAP,
      465 +                                    LOGIN_WIDTH);
      466 +                        } else if (list->l_type == LT_ZONES) {
 453  467                                  getzonename(id->id_zoneid, zonename,
 454      -                                    ZONENAME_MAX);
 455      -                        else
      468 +                                    sizeof (zonename) - 1,
      469 +                                    opts.o_outpmode & OPT_TERMCAP,
      470 +                                    ZONE_WIDTH);
      471 +                        } else {
 456  472                                  getprojname(id->id_projid, projname,
 457      -                                    PROJNAME_MAX,
 458      -                                    opts.o_outpmode & OPT_NORESOLVE);
      473 +                                    sizeof (projname) - 1,
      474 +                                    opts.o_outpmode & OPT_NORESOLVE,
      475 +                                    opts.o_outpmode & OPT_TERMCAP,
      476 +                                    PROJECT_WIDTH);
      477 +                        }
 459  478                          Format_size(psize, id->id_size, 6);
 460  479                          Format_size(prssize, id->id_rssize, 6);
 461  480                          Format_pct(pmem, mem, 4);
 462  481                          Format_pct(pcpu, cpu, 4);
 463  482                          Format_time(ptime, id->id_time, 10);
 464  483                          if (opts.o_outpmode & OPT_TTY)
 465  484                                  (void) putchar('\r');
 466  485                          if (list->l_type == LT_PROJECTS)
 467  486                                  (void) printf(PROJECT_LINE, (int)id->id_projid,
 468  487                                      id->id_nproc, psize, prssize, pmem, ptime,
↓ open down ↓ 12 lines elided ↑ open up ↑
 481  500                          (void) putp(t_eol);
 482  501                          (void) putchar('\n');
 483  502                          break;
 484  503                  case LT_LWPS:
 485  504                          lwp = list->l_ptrs[i];
 486  505                          if (opts.o_outpmode & OPT_LWPS)
 487  506                                  lwpid = lwp->li_info.pr_lwp.pr_lwpid;
 488  507                          else
 489  508                                  lwpid = lwp->li_info.pr_nlwp +
 490  509                                      lwp->li_info.pr_nzomb;
 491      -                        pwd_getname(lwp->li_info.pr_uid, pname, LOGNAME_MAX + 1,
 492      -                            opts.o_outpmode & OPT_NORESOLVE);
      510 +                        pwd_getname(lwp->li_info.pr_uid, pname, sizeof (pname),
      511 +                            opts.o_outpmode & OPT_NORESOLVE,
      512 +                            opts.o_outpmode & OPT_TERMCAP,
      513 +                            LOGIN_WIDTH);
 493  514                          if (opts.o_outpmode & OPT_PSINFO) {
 494  515                                  Format_size(psize, lwp->li_info.pr_size, 6);
 495  516                                  Format_size(prssize, lwp->li_info.pr_rssize, 6);
 496  517                                  Format_state(pstate,
 497  518                                      lwp->li_info.pr_lwp.pr_sname,
 498  519                                      lwp->li_info.pr_lwp.pr_onpro, 7);
 499  520                                  if (strcmp(lwp->li_info.pr_lwp.pr_clname,
 500  521                                      "RT") == 0 ||
 501  522                                      strcmp(lwp->li_info.pr_lwp.pr_clname,
 502  523                                      "SYS") == 0 ||
↓ open down ↓ 12 lines elided ↑ open up ↑
 515  536                                              10);
 516  537                                  else
 517  538                                          Format_time(ptime,
 518  539                                              lwp->li_info.pr_time.tv_sec, 10);
 519  540                                  if (opts.o_outpmode & OPT_TTY)
 520  541                                          (void) putchar('\r');
 521  542                                  stripfname(lwp->li_info.pr_fname);
 522  543                                  if (opts.o_outpmode & OPT_LGRP) {
 523  544                                          (void) printf(PSINFO_LINE_LGRP,
 524  545                                              (int)lwp->li_info.pr_pid, pname,
 525      -                                            psize, prssize, pstate, ppri, pnice,
 526      -                                            ptime, pcpu,
      546 +                                            psize, prssize, pstate,
      547 +                                            ppri, pnice, ptime, pcpu,
 527  548                                              (int)lwp->li_info.pr_lwp.pr_lgrp,
 528  549                                              lwp->li_info.pr_fname, lwpid);
 529  550                                  } else {
 530  551                                          (void) printf(PSINFO_LINE,
 531  552                                              (int)lwp->li_info.pr_pid, pname,
 532      -                                            psize, prssize, pstate, ppri, pnice,
      553 +                                            psize, prssize,
      554 +                                            pstate, ppri, pnice,
 533  555                                              ptime, pcpu,
 534  556                                              lwp->li_info.pr_fname, lwpid);
 535  557                                  }
 536  558                                  (void) putp(t_eol);
 537  559                                  (void) putchar('\n');
 538  560                          }
 539  561                          if (opts.o_outpmode & OPT_MSACCT) {
 540  562                                  Format_pct(usr, lwp->li_usr, 4);
 541  563                                  Format_pct(sys, lwp->li_sys, 4);
 542  564                                  Format_pct(slp, lwp->li_slp, 4);
↓ open down ↓ 1113 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX