summaryrefslogtreecommitdiffstats
path: root/bin/ps
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2009-02-26 18:01:07 +0000
committerattilio <attilio@FreeBSD.org>2009-02-26 18:01:07 +0000
commitdfd6f02e2ffd77ba010288c4ecd81941adcc4c65 (patch)
treececbf3e7beb3f5346722ae648d54aad25d34c05f /bin/ps
parentb029979bbce1b14ee2a80e416c909c077168e0f0 (diff)
downloadFreeBSD-src-dfd6f02e2ffd77ba010288c4ecd81941adcc4c65.zip
FreeBSD-src-dfd6f02e2ffd77ba010288c4ecd81941adcc4c65.tar.gz
[1] When showing threads, the thread name just appears if the comm
label is choosen as last printout (ucomm suffers of this such bug too). That bug is caused by the fact that the fixed size of printout doesn't leave enough space for them to be printed out. Implement ucomm and comm commands with a dynamic size lenght for buffers. [2] On AMD64 architecture pointers don't have enough chars space to be shown (8 chars while they need 16). Fix them by providing a variadic space so that it fits well on both 64 and 32 bits architectures. [3] Check a return value of malloc() that wasn't checked before. PR: bin/128841, bin/128842 Reviewed by: jhb, emaste Sponsored by: Sandvine Incorporated
Diffstat (limited to 'bin/ps')
-rw-r--r--bin/ps/extern.h1
-rw-r--r--bin/ps/keyword.c21
-rw-r--r--bin/ps/print.c26
3 files changed, 37 insertions, 11 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h
index 89b5835..c441278 100644
--- a/bin/ps/extern.h
+++ b/bin/ps/extern.h
@@ -71,6 +71,7 @@ void priorityr(KINFO *, VARENT *);
void rgroupname(KINFO *, VARENT *);
void runame(KINFO *, VARENT *);
void rvar(KINFO *, VARENT *);
+int s_comm(KINFO *);
int s_label(KINFO *);
int s_rgroupname(KINFO *);
int s_runame(KINFO *);
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index c0d55c6..ade8123 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -79,8 +79,8 @@ static VAR var[] = {
CHAR, NULL, 0},
{"blocked", "", "sigmask", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"caught", "", "sigcatch", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
- {"comm", "COMMAND", NULL, LJUST, ucomm, NULL, MAXCOMLEN, 0, CHAR,
- NULL, 0},
+ {"comm", "COMMAND", NULL, LJUST|DSIZ, ucomm, s_comm,
+ COMMLEN + OCOMMLEN + 1, 0, CHAR, NULL, 0},
{"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16, 0,
CHAR, NULL, 0},
{"cpu", "CPU", NULL, 0, kvar, NULL, 3, KOFF(ki_estcpu), UINT, "d",
@@ -135,12 +135,13 @@ static VAR var[] = {
LONG, "ld", 0},
{"nvcsw", "NVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nvcsw),
LONG, "ld", 0},
- {"nwchan", "NWCHAN", NULL, LJUST, nwchan, NULL, 8, 0, CHAR, NULL, 0},
+ {"nwchan", "NWCHAN", NULL, LJUST, nwchan, NULL, sizeof(void *) * 2, 0,
+ CHAR, NULL, 0},
{"oublk", "OUBLK", NULL, USER, rvar, NULL, 4, ROFF(ru_oublock),
LONG, "ld", 0},
{"oublock", "", "oublk", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
- {"paddr", "PADDR", NULL, 0, kvar, NULL, 8, KOFF(ki_paddr), KPTR,
- "lx", 0},
+ {"paddr", "PADDR", NULL, 0, kvar, NULL, sizeof(void *) * 2,
+ KOFF(ki_paddr), KPTR, "lx", 0},
{"pagein", "PAGEIN", NULL, USER, pagein, NULL, 6, 0, CHAR, NULL, 0},
{"pcpu", "", "%cpu", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
{"pending", "", "sig", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
@@ -195,13 +196,13 @@ static VAR var[] = {
{"tsiz", "TSIZ", NULL, 0, kvar, NULL, 4, KOFF(ki_tsize), PGTOK, "ld", 0},
{"tt", "TT ", NULL, 0, tname, NULL, 4, 0, CHAR, NULL, 0},
{"tty", "TTY", NULL, LJUST, longtname, NULL, 8, 0, CHAR, NULL, 0},
- {"ucomm", "UCOMM", NULL, LJUST, ucomm, NULL, MAXCOMLEN, 0, CHAR, NULL,
- 0},
+ {"ucomm", "UCOMM", NULL, LJUST|DSIZ, ucomm, s_comm,
+ COMMLEN + OCOMMLEN + 1, 0, CHAR, NULL, 0},
{"uid", "UID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_uid), UINT,
UIDFMT, 0},
{"upr", "UPR", NULL, 0, upr, NULL, 3, 0, CHAR, NULL, 0},
- {"uprocp", "UPROCP", NULL, 0, kvar, NULL, 8, KOFF(ki_paddr), KPTR,
- "lx", 0},
+ {"uprocp", "UPROCP", NULL, 0, kvar, NULL, sizeof(void *) * 2,
+ KOFF(ki_paddr), KPTR, "lx", 0},
{"user", "USER", NULL, LJUST|DSIZ, uname, s_uname, USERLEN, 0, CHAR,
NULL, 0},
{"usrpri", "", "upr", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
@@ -325,6 +326,8 @@ findvar(char *p, int user, char **header)
*/
rflen = strlen(v->alias) + strlen(hp) + 2;
realfmt = malloc(rflen);
+ if (realfmt == NULL)
+ errx(1, "malloc failed");
snprintf(realfmt, rflen, "%s=%s", v->alias, hp);
parsefmt(realfmt, user);
}
diff --git a/bin/ps/print.c b/bin/ps/print.c
index c54df4b..3ae37fc 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -177,6 +177,7 @@ command(KINFO *k, VARENT *ve)
void
ucomm(KINFO *k, VARENT *ve)
{
+ char tmpbuff[COMMLEN + OCOMMLEN + 2];
VAR *v;
v = ve->var;
@@ -184,8 +185,15 @@ ucomm(KINFO *k, VARENT *ve)
(void)printf("%s", k->ki_p->ki_comm);
if (showthreads && k->ki_p->ki_numthreads > 1)
printf("/%s", k->ki_p->ki_ocomm);
- } else
- (void)printf("%-*s", v->width, k->ki_p->ki_comm);
+ } else {
+ bzero(tmpbuff, sizeof(tmpbuff));
+ if (showthreads && k->ki_p->ki_numthreads > 1)
+ sprintf(tmpbuff, "%s/%s", k->ki_p->ki_comm,
+ k->ki_p->ki_ocomm);
+ else
+ sprintf(tmpbuff, "%s", k->ki_p->ki_comm);
+ (void)printf("%-*s", v->width, tmpbuff);
+ }
}
void
@@ -821,6 +829,20 @@ out:
}
int
+s_comm(KINFO *k)
+{
+ char tmpbuff[COMMLEN + OCOMMLEN + 2];
+
+ bzero(tmpbuff, sizeof(tmpbuff));
+ if (showthreads && k->ki_p->ki_numthreads > 1)
+ sprintf(tmpbuff, "%s/%s", k->ki_p->ki_comm,
+ k->ki_p->ki_ocomm);
+ else
+ sprintf(tmpbuff, "%s", k->ki_p->ki_comm);
+ return (strlen(tmpbuff));
+}
+
+int
s_label(KINFO *k)
{
char *string = NULL;
OpenPOWER on IntegriCloud