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/prutil.c
          +++ new/usr/src/cmd/prstat/prutil.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   *
  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 + * Copyright (c) 2013 Gary Mills
       23 + *
  22   24   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   25   * Use is subject to license terms.
  24   26   *
  25   27   * Portions Copyright 2009 Chad Mynhier
  26   28   */
  27   29  
  28   30  #include <sys/types.h>
  29   31  #include <sys/param.h>
  30   32  #include <sys/resource.h>
  31   33  #include <sys/priocntl.h>
↓ open down ↓ 67 lines elided ↑ open up ↑
  99  101                  p = arg0;
 100  102          else
 101  103                  p++;
 102  104          progname = p;
 103  105  }
 104  106  
 105  107  void
 106  108  Usage()
 107  109  {
 108  110          (void) fprintf(stderr, gettext(
 109      -            "Usage:\tprstat [-acHJLmrRtTvZ] [-u euidlist] [-U uidlist]\n"
      111 +            "Usage:\tprstat [-acHJLmrRtTvWZ] [-u euidlist] [-U uidlist]\n"
 110  112              "\t[-p pidlist] [-P cpulist] [-C psrsetlist] [-h lgrouplist]\n"
 111  113              "\t[-j projidlist] [-k taskidlist] [-z zoneidlist]\n"
 112  114              "\t[-s key | -S key] [-n nprocs[,nusers]] [-d d|u]\n"
 113  115              "\t[interval [counter]]\n"));
 114  116          exit(1);
 115  117  }
 116  118  
 117  119  int
 118  120  Atoi(char *p)
 119  121  {
↓ open down ↓ 151 lines elided ↑ open up ↑
 271  273          }
 272  274          pcparms.pc_cid = pcinfo.pc_cid;
 273  275          ((rtparms_t *)pcparms.pc_clparms)->rt_pri = 0;
 274  276          ((rtparms_t *)pcparms.pc_clparms)->rt_tqsecs = 0;
 275  277          ((rtparms_t *)pcparms.pc_clparms)->rt_tqnsecs = RT_NOCHANGE;
 276  278          if (priocntl(P_PID, getpid(), PC_SETPARMS, (caddr_t)&pcparms) == -1)
 277  279                  Warn(gettext("cannot enter the real time class"));
 278  280  }
 279  281  
 280  282  void
 281      -getprojname(projid_t projid, char *str, int len, int noresolve)
      283 +getprojname(projid_t projid, char *str, size_t len, int noresolve,
      284 +    int trunc, size_t width)
 282  285  {
 283  286          struct project proj;
      287 +        size_t n;
 284  288  
 285  289          if (noresolve || getprojbyid(projid, &proj, projbuf, PROJECT_BUFSZ) ==
 286      -            NULL)
      290 +            NULL) {
 287  291                  (void) snprintf(str, len, "%-6d", (int)projid);
 288      -        else
 289      -                (void) snprintf(str, len, "%-28s", proj.pj_name);
      292 +        } else {
      293 +                n = mbstowcs(NULL, proj.pj_name, 0);
      294 +                if (n == (size_t)-1)
      295 +                        (void) snprintf(str, len, "%-28s", "ERROR");
      296 +                else if (trunc && n > width)
      297 +                        (void) snprintf(str, len, "%.*s%c", width - 1,
      298 +                            proj.pj_name, '*');
      299 +                else
      300 +                        (void) snprintf(str, len, "%-28s", proj.pj_name);
      301 +        }
 290  302  }
 291  303  
 292  304  void
 293      -getzonename(zoneid_t zoneid, char *str, int len)
      305 +getzonename(zoneid_t zoneid, char *str, size_t len, int trunc, size_t width)
 294  306  {
 295  307          char zone_name[ZONENAME_MAX];
      308 +        size_t n;
 296  309  
 297      -        if (getzonenamebyid(zoneid, zone_name, sizeof (zone_name)) < 0)
      310 +        if (getzonenamebyid(zoneid, zone_name, sizeof (zone_name)) < 0) {
 298  311                  (void) snprintf(str, len, "%-6d", (int)zoneid);
 299      -        else
 300      -                (void) snprintf(str, len, "%-28s", zone_name);
      312 +        } else {
      313 +                n = mbstowcs(NULL, zone_name, 0);
      314 +                if (n == (size_t)-1)
      315 +                        (void) snprintf(str, len, "%-28s", "ERROR");
      316 +                else if (trunc && n > width)
      317 +                        (void) snprintf(str, len, "%.*s%c", width - 1,
      318 +                            zone_name, '*');
      319 +                else
      320 +                        (void) snprintf(str, len, "%-28s", zone_name);
      321 +        }
 301  322  }
 302  323  
 303  324  /*
 304  325   * Remove all unprintable characters from process name
 305  326   */
 306  327  void
 307  328  stripfname(char *buf)
 308  329  {
 309  330          int bytesleft = PRFNSZ;
 310  331          wchar_t wchar;
↓ open down ↓ 22 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX