Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars
*** 18,27 ****
--- 18,29 ----
*
* CDDL HEADER END
*/
/*
+ * Copyright (c) 2013 Gary Mills
+ *
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
*** 74,84 ****
* Set to ZONENAME_MAX, the minimum value needed to allow any
* zone to be specified.
*/
#define ARGSIZ ZONENAME_MAX
! #define MAXUGNAME 10 /* max chars in a user/group name or printed u/g id */
/* Structure for storing user or group info */
struct ugdata {
id_t id; /* numeric user-id or group-id */
char name[MAXUGNAME+1]; /* user/group name, null terminated */
--- 76,87 ----
* Set to ZONENAME_MAX, the minimum value needed to allow any
* zone to be specified.
*/
#define ARGSIZ ZONENAME_MAX
! #define MAXUGNAME (LOGNAME_MAX+2) /* max chars in a user/group */
! /* name or printed u/g id */
/* Structure for storing user or group info */
struct ugdata {
id_t id; /* numeric user-id or group-id */
char name[MAXUGNAME+1]; /* user/group name, null terminated */
*** 222,231 ****
--- 225,235 ----
static int Gflg;
static int aflg;
static int dflg;
static int Lflg;
static int Pflg;
+ static int Wflg;
static int yflg;
static int pflg;
static int fflg;
static int cflg;
static int jflg;
*** 422,432 ****
if (len >= sizeof (loc_stime_str))
len = sizeof (loc_stime_str) - 1;
fname[F_STIME].width = fname[F_STIME].minwidth = len;
! while ((c = getopt(argc, argv, "jlfceAadLPyZHh:t:p:g:u:U:G:n:s:o:z:"))
!= EOF)
switch (c) {
case 'H': /* Show home lgroups */
Hflg++;
break;
--- 426,436 ----
if (len >= sizeof (loc_stime_str))
len = sizeof (loc_stime_str) - 1;
fname[F_STIME].width = fname[F_STIME].minwidth = len;
! while ((c = getopt(argc, argv, "jlfceAadLPWyZHh:t:p:g:u:U:G:n:s:o:z:"))
!= EOF)
switch (c) {
case 'H': /* Show home lgroups */
Hflg++;
break;
*** 516,525 ****
--- 520,532 ----
Lflg++;
break;
case 'P': /* show bound processor */
Pflg++;
break;
+ case 'W': /* truncate long names */
+ Wflg++;
+ break;
case 'y': /* omit F & ADDR, report RSS & SZ in Kby */
yflg++;
break;
case 'n': /* no longer needed; retain as no-op */
(void) fprintf(stderr,
*** 1055,1065 ****
{
struct def_field *df, *sorted[NFIELDS];
int pos = 80, i = 0;
static char usage1[] =
! "ps [ -aAdefHlcjLPyZ ] [ -o format ] [ -t termlist ]";
static char usage2[] =
"\t[ -u userlist ] [ -U userlist ] [ -G grouplist ]";
static char usage3[] =
"\t[ -p proclist ] [ -g pgrplist ] [ -s sidlist ]";
static char usage4[] =
--- 1062,1072 ----
{
struct def_field *df, *sorted[NFIELDS];
int pos = 80, i = 0;
static char usage1[] =
! "ps [ -aAdefHlcjLPWyZ ] [ -o format ] [ -t termlist ]";
static char usage2[] =
"\t[ -u userlist ] [ -U userlist ] [ -G grouplist ]";
static char usage3[] =
"\t[ -p proclist ] [ -g pgrplist ] [ -s sidlist ]";
static char usage4[] =
*** 1393,1414 ****
}
if (Zflg) { /* ZONE */
if (getzonenamebyid(psinfo->pr_zoneid, zonename,
sizeof (zonename)) < 0) {
! (void) printf(" %7.7d ", ((int)psinfo->pr_zoneid));
} else {
(void) printf("%8.8s ", zonename);
}
}
if (fflg) { /* UID */
! if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
(void) printf("%8.8s ", pwd->pw_name);
else
(void) printf(" %7.7u ", psinfo->pr_euid);
} else if (lflg) {
(void) printf("%6u ", psinfo->pr_euid);
}
(void) printf("%*d", pidwidth, (int)psinfo->pr_pid); /* PID */
if (lflg || fflg)
(void) printf(" %*d", pidwidth,
--- 1400,1442 ----
}
if (Zflg) { /* ZONE */
if (getzonenamebyid(psinfo->pr_zoneid, zonename,
sizeof (zonename)) < 0) {
! if (snprintf(NULL, 0, "%d",
! ((int)psinfo->pr_zoneid)) > 7)
! (void) printf(" %6.6d%c ",
! ((int)psinfo->pr_zoneid), '*');
! else
! (void) printf(" %7.7d ",
! ((int)psinfo->pr_zoneid));
} else {
+ if (strlen(zonename) > 8)
+ (void) printf("%7.7s%c ", zonename, '*');
+ else
(void) printf("%8.8s ", zonename);
}
}
if (fflg) { /* UID */
! if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
! if (strlen(pwd->pw_name) > 8)
! (void) printf("%7.7s%c ", pwd->pw_name, '*');
! else
(void) printf("%8.8s ", pwd->pw_name);
+ } else {
+ if (snprintf(NULL, 0, "%u",
+ ((int)psinfo->pr_euid)) > 7)
+ (void) printf(" %6.6u%c ", psinfo->pr_euid,
+ '*');
else
(void) printf(" %7.7u ", psinfo->pr_euid);
+ }
} else if (lflg) {
+ if (snprintf(NULL, 0, "%u", ((int)psinfo->pr_euid)) > 6)
+ (void) printf("%5.5u%c ", psinfo->pr_euid, '*');
+ else
(void) printf("%6u ", psinfo->pr_euid);
}
(void) printf("%*d", pidwidth, (int)psinfo->pr_pid); /* PID */
if (lflg || fflg)
(void) printf(" %*d", pidwidth,
*** 1626,1645 ****
zombie_lwp = (Lflg && psinfo->pr_lwp.pr_sname == 'Z');
switch (f->fname) {
case F_RUSER:
! if ((pwd = getpwuid(psinfo->pr_uid)) != NULL)
(void) printf("%*s", width, pwd->pw_name);
else
(void) printf("%*u", width, psinfo->pr_uid);
break;
case F_USER:
! if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
(void) printf("%*s", width, pwd->pw_name);
else
(void) printf("%*u", width, psinfo->pr_euid);
break;
case F_RGROUP:
if ((grp = getgrgid(psinfo->pr_gid)) != NULL)
(void) printf("%*s", width, grp->gr_name);
else
--- 1654,1695 ----
zombie_lwp = (Lflg && psinfo->pr_lwp.pr_sname == 'Z');
switch (f->fname) {
case F_RUSER:
! if ((pwd = getpwuid(psinfo->pr_uid)) != NULL) {
! if (Wflg && strlen(pwd->pw_name) > width)
! (void) printf("%.*s%c", width - 1,
! pwd->pw_name, '*');
! else
(void) printf("%*s", width, pwd->pw_name);
+ } else {
+ if (Wflg && snprintf(NULL, 0, "%u",
+ ((int)psinfo->pr_uid)) > width)
+
+ (void) printf("%*u%c", width - 1,
+ psinfo->pr_uid, '*');
else
(void) printf("%*u", width, psinfo->pr_uid);
+ }
break;
case F_USER:
! if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
! if (Wflg && strlen(pwd->pw_name) > width)
! (void) printf("%.*s%c", width - 1,
! pwd->pw_name, '*');
! else
(void) printf("%*s", width, pwd->pw_name);
+ } else {
+ if (Wflg && snprintf(NULL, 0, "%u",
+ ((int)psinfo->pr_euid)) > width)
+
+ (void) printf("%*u%c", width - 1,
+ psinfo->pr_euid, '*');
else
(void) printf("%*u", width, psinfo->pr_euid);
+ }
break;
case F_RGROUP:
if ((grp = getgrgid(psinfo->pr_gid)) != NULL)
(void) printf("%*s", width, grp->gr_name);
else
*** 1877,1894 ****
{
struct project cproj;
char proj_buf[PROJECT_BUFSZ];
if ((getprojbyid(psinfo->pr_projid, &cproj,
! (void *)&proj_buf, PROJECT_BUFSZ)) == NULL)
(void) printf("%*d", width,
(int)psinfo->pr_projid);
else
(void) printf("%*s", width,
(cproj.pj_name != NULL) ?
cproj.pj_name : "---");
}
break;
case F_PSET:
if (zombie_lwp || psinfo->pr_lwp.pr_bindpset == PS_NONE)
(void) printf("%*s", width, "-");
else
--- 1927,1955 ----
{
struct project cproj;
char proj_buf[PROJECT_BUFSZ];
if ((getprojbyid(psinfo->pr_projid, &cproj,
! (void *)&proj_buf, PROJECT_BUFSZ)) == NULL) {
! if (Wflg && snprintf(NULL, 0, "%d",
! ((int)psinfo->pr_projid)) > width)
! (void) printf("%.*d%c", width - 1,
! ((int)psinfo->pr_projid), '*');
! else
(void) printf("%*d", width,
(int)psinfo->pr_projid);
+ } else {
+ if (Wflg && cproj.pj_name != NULL &&
+ strlen(cproj.pj_name) > width)
+ (void) printf("%.*s%c", width - 1,
+ cproj.pj_name, '*');
else
(void) printf("%*s", width,
(cproj.pj_name != NULL) ?
cproj.pj_name : "---");
}
+ }
break;
case F_PSET:
if (zombie_lwp || psinfo->pr_lwp.pr_bindpset == PS_NONE)
(void) printf("%*s", width, "-");
else
*** 1901,1913 ****
{
char zonename[ZONENAME_MAX];
if (getzonenamebyid(psinfo->pr_zoneid, zonename,
sizeof (zonename)) < 0) {
(void) printf("%*d", width,
! ((int)psinfo->pr_zoneid));
} else {
(void) printf("%*s", width, zonename);
}
}
break;
case F_CTID:
--- 1962,1983 ----
{
char zonename[ZONENAME_MAX];
if (getzonenamebyid(psinfo->pr_zoneid, zonename,
sizeof (zonename)) < 0) {
+ if (Wflg && snprintf(NULL, 0, "%d",
+ ((int)psinfo->pr_zoneid)) > width)
+ (void) printf("%.*d%c", width - 1,
+ ((int)psinfo->pr_zoneid), '*');
+ else
(void) printf("%*d", width,
! (int)psinfo->pr_zoneid);
} else {
+ if (Wflg && strlen(zonename) > width)
+ (void) printf("%.*s%c", width - 1,
+ zonename, '*');
+ else
(void) printf("%*s", width, zonename);
}
}
break;
case F_CTID:
*** 2179,2204 ****
(void) printf("%c ", psinfo->pr_lwp.pr_sname); /* S */
}
if (Zflg) {
if (getzonenamebyid(psinfo->pr_zoneid, zonename,
sizeof (zonename)) < 0) {
! (void) printf(" %7.7d ", ((int)psinfo->pr_zoneid));
} else {
(void) printf("%8.8s ", zonename);
}
}
if (Hflg) {
/* Display home lgroup */
(void) printf(" %6d", (int)psinfo->pr_lwp.pr_lgrp); /* LGRP */
}
if (fflg) {
! if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
(void) printf("%8.8s ", pwd->pw_name);
else
(void) printf(" %7.7u ", psinfo->pr_euid);
! } else if (lflg)
(void) printf("%6u ", psinfo->pr_euid);
(void) printf("%*d", pidwidth, (int)psinfo->pr_pid); /* PID */
if (lflg || fflg)
(void) printf(" %*d", pidwidth,
(int)psinfo->pr_ppid); /* PPID */
--- 2249,2296 ----
(void) printf("%c ", psinfo->pr_lwp.pr_sname); /* S */
}
if (Zflg) {
if (getzonenamebyid(psinfo->pr_zoneid, zonename,
sizeof (zonename)) < 0) {
! if (snprintf(NULL, 0, "%d",
! ((int)psinfo->pr_zoneid)) > 7)
! (void) printf(" %6.6d%c ",
! ((int)psinfo->pr_zoneid), '*');
! else
! (void) printf(" %7.7d ",
! ((int)psinfo->pr_zoneid));
} else {
+ if (strlen(zonename) > 8)
+ (void) printf("%7.7s%c ", zonename, '*');
+ else
(void) printf("%8.8s ", zonename);
}
}
if (Hflg) {
/* Display home lgroup */
(void) printf(" %6d", (int)psinfo->pr_lwp.pr_lgrp); /* LGRP */
}
if (fflg) {
! if ((pwd = getpwuid(psinfo->pr_euid)) != NULL) {
! if (strlen(pwd->pw_name) > 8)
! (void) printf("%7.7s%c ", pwd->pw_name, '*');
! else
(void) printf("%8.8s ", pwd->pw_name);
+ } else {
+ if (snprintf(NULL, 0, "%u",
+ ((int)psinfo->pr_euid)) > 7)
+ (void) printf(" %6.6u%c ", psinfo->pr_euid,
+ '*');
else
(void) printf(" %7.7u ", psinfo->pr_euid);
! }
! } else if (lflg) {
! if (snprintf(NULL, 0, "%u", ((int)psinfo->pr_euid)) > 6)
! (void) printf("%5.5u%c ", psinfo->pr_euid, '*');
! else
(void) printf("%6u ", psinfo->pr_euid);
+ }
(void) printf("%*d", pidwidth, (int)psinfo->pr_pid); /* PID */
if (lflg || fflg)
(void) printf(" %*d", pidwidth,
(int)psinfo->pr_ppid); /* PPID */