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


   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*


  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Portions Copyright 2009 Chad Mynhier
  26  */
  27 
  28 #include <sys/types.h>
  29 #include <sys/param.h>
  30 #include <sys/resource.h>
  31 #include <sys/priocntl.h>
  32 #include <sys/rtpriocntl.h>
  33 #include <sys/tspriocntl.h>
  34 #include <zone.h>
  35 
  36 #include <libintl.h>
  37 #include <limits.h>
  38 #include <wchar.h>
  39 #include <unistd.h>
  40 #include <string.h>
  41 #include <stdlib.h>


 261 
 262 void
 263 Priocntl(char *class)
 264 {
 265         pcinfo_t pcinfo;
 266         pcparms_t pcparms;
 267         (void) strcpy(pcinfo.pc_clname, class);
 268         if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1) {
 269                 Warn(gettext("cannot get real time class parameters"));
 270                 return;
 271         }
 272         pcparms.pc_cid = pcinfo.pc_cid;
 273         ((rtparms_t *)pcparms.pc_clparms)->rt_pri = 0;
 274         ((rtparms_t *)pcparms.pc_clparms)->rt_tqsecs = 0;
 275         ((rtparms_t *)pcparms.pc_clparms)->rt_tqnsecs = RT_NOCHANGE;
 276         if (priocntl(P_PID, getpid(), PC_SETPARMS, (caddr_t)&pcparms) == -1)
 277                 Warn(gettext("cannot enter the real time class"));
 278 }
 279 
 280 void
 281 getprojname(projid_t projid, char *str, int len, int noresolve)

 282 {
 283         struct project proj;

 284 
 285         if (noresolve || getprojbyid(projid, &proj, projbuf, PROJECT_BUFSZ) ==
 286             NULL)
 287                 (void) snprintf(str, len, "%-6d", (int)projid);





 288         else
 289                 (void) snprintf(str, len, "%-28s", proj.pj_name);

 290 }
 291 
 292 void
 293 getzonename(zoneid_t zoneid, char *str, int len)
 294 {
 295         char zone_name[ZONENAME_MAX];

 296 
 297         if (getzonenamebyid(zoneid, zone_name, sizeof (zone_name)) < 0)
 298                 (void) snprintf(str, len, "%-6d", (int)zoneid);





 299         else
 300                 (void) snprintf(str, len, "%-28s", zone_name);

 301 }
 302 
 303 /*
 304  * Remove all unprintable characters from process name
 305  */
 306 void
 307 stripfname(char *buf)
 308 {
 309         int bytesleft = PRFNSZ;
 310         wchar_t wchar;
 311         int length;
 312         char *cp;
 313 
 314         buf[bytesleft - 1] = '\0';
 315 
 316         for (cp = buf; *cp != '\0'; cp += length) {
 317                 length = mbtowc(&wchar, cp, MB_LEN_MAX);
 318                 if (length <= 0) {
 319                         *cp = '\0';
 320                         break;


   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2013 Gary Mills
  23  *
  24  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  *
  27  * Portions Copyright 2009 Chad Mynhier
  28  */
  29 
  30 #include <sys/types.h>
  31 #include <sys/param.h>
  32 #include <sys/resource.h>
  33 #include <sys/priocntl.h>
  34 #include <sys/rtpriocntl.h>
  35 #include <sys/tspriocntl.h>
  36 #include <zone.h>
  37 
  38 #include <libintl.h>
  39 #include <limits.h>
  40 #include <wchar.h>
  41 #include <unistd.h>
  42 #include <string.h>
  43 #include <stdlib.h>


 263 
 264 void
 265 Priocntl(char *class)
 266 {
 267         pcinfo_t pcinfo;
 268         pcparms_t pcparms;
 269         (void) strcpy(pcinfo.pc_clname, class);
 270         if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1) {
 271                 Warn(gettext("cannot get real time class parameters"));
 272                 return;
 273         }
 274         pcparms.pc_cid = pcinfo.pc_cid;
 275         ((rtparms_t *)pcparms.pc_clparms)->rt_pri = 0;
 276         ((rtparms_t *)pcparms.pc_clparms)->rt_tqsecs = 0;
 277         ((rtparms_t *)pcparms.pc_clparms)->rt_tqnsecs = RT_NOCHANGE;
 278         if (priocntl(P_PID, getpid(), PC_SETPARMS, (caddr_t)&pcparms) == -1)
 279                 Warn(gettext("cannot enter the real time class"));
 280 }
 281 
 282 void
 283 getprojname(projid_t projid, char *str, size_t len, int noresolve,
 284     int termcap, size_t width)
 285 {
 286         struct project proj;
 287         size_t n;
 288 
 289         if (noresolve || getprojbyid(projid, &proj, projbuf, PROJECT_BUFSZ) ==
 290             NULL) {
 291                 (void) snprintf(str, len, "%-6d", (int)projid);
 292         } else {
 293                 n = strlen(proj.pj_name);
 294                 if (termcap && n > width)
 295                         (void) snprintf(str, len, "%.*s%c", width - 1,
 296                             proj.pj_name, '*');
 297                 else
 298                         (void) snprintf(str, len, "%-28s", proj.pj_name);
 299         }
 300 }
 301 
 302 void
 303 getzonename(zoneid_t zoneid, char *str, size_t len, int termcap, size_t width)
 304 {
 305         char zone_name[ZONENAME_MAX];
 306         size_t n;
 307 
 308         if (getzonenamebyid(zoneid, zone_name, sizeof (zone_name)) < 0) {
 309                 (void) snprintf(str, len, "%-6d", (int)zoneid);
 310         } else {
 311                 n = strlen(zone_name);
 312                 if (termcap && n > width)
 313                         (void) snprintf(str, len, "%.*s%c", width - 1,
 314                             zone_name, '*');
 315                 else
 316                         (void) snprintf(str, len, "%-28s", zone_name);
 317         }
 318 }
 319 
 320 /*
 321  * Remove all unprintable characters from process name
 322  */
 323 void
 324 stripfname(char *buf)
 325 {
 326         int bytesleft = PRFNSZ;
 327         wchar_t wchar;
 328         int length;
 329         char *cp;
 330 
 331         buf[bytesleft - 1] = '\0';
 332 
 333         for (cp = buf; *cp != '\0'; cp += length) {
 334                 length = mbtowc(&wchar, cp, MB_LEN_MAX);
 335                 if (length <= 0) {
 336                         *cp = '\0';
 337                         break;