diff options
author | John Baldwin <jhb@FreeBSD.org> | 2013-03-01 01:02:44 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2013-03-01 01:02:44 +0000 |
commit | b97869835244d025ef81b02208e6b5e6a355ca52 (patch) | |
tree | 36ed50b1c4ad72985b3dd01ec44800a547e72cc6 | |
parent | 7bc6666542984e13f607743553f0d2510fffffcb (diff) | |
download | src-b97869835244d025ef81b02208e6b5e6a355ca52.tar.gz src-b97869835244d025ef81b02208e6b5e6a355ca52.zip |
MFC 245610,245633,245635:
Include the thread name along with the command name when displaying the
command name of a thread from a multi-threaded process that doesn't have
an available argument list (such as kernel processes) and threads display
is enabled via -H.
Notes
Notes:
svn path=/stable/8/; revision=247517
-rw-r--r-- | bin/ps/extern.h | 2 | ||||
-rw-r--r-- | bin/ps/fmt.c | 13 | ||||
-rw-r--r-- | bin/ps/ps.c | 11 | ||||
-rw-r--r-- | usr.bin/w/w.c | 6 |
4 files changed, 19 insertions, 13 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h index 7d261276b1fd..76861f1218ff 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -50,7 +50,7 @@ int donlist(void); void elapsed(KINFO *, VARENT *); void emulname(KINFO *, VARENT *); VARENT *find_varentry(VAR *); -const char *fmt_argv(char **, char *, size_t); +const char *fmt_argv(char **, char *, char *, size_t); double getpcpu(const KINFO *); void kvar(KINFO *, VARENT *); void label(KINFO *, VARENT *); diff --git a/bin/ps/fmt.c b/bin/ps/fmt.c index 1e9fed8710f0..4db6b8d1d33f 100644 --- a/bin/ps/fmt.c +++ b/bin/ps/fmt.c @@ -105,7 +105,7 @@ cmdpart(char *arg0) } const char * -fmt_argv(char **argv, char *cmd, size_t maxlen) +fmt_argv(char **argv, char *cmd, char *thread, size_t maxlen) { size_t len; char *ap, *cp; @@ -122,9 +122,14 @@ fmt_argv(char **argv, char *cmd, size_t maxlen) cp = malloc(len); if (cp == NULL) errx(1, "malloc failed"); - if (ap == NULL) - sprintf(cp, "[%.*s]", (int)maxlen, cmd); - else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0) + if (ap == NULL) { + if (thread != NULL) { + asprintf(&ap, "%s/%s", cmd, thread); + sprintf(cp, "[%.*s]", (int)maxlen, ap); + free(ap); + } else + sprintf(cp, "[%.*s]", (int)maxlen, cmd); + } else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0) sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd); else strcpy(cp, ap); diff --git a/bin/ps/ps.c b/bin/ps/ps.c index ab511d108775..c5b6e16803f6 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -143,7 +143,7 @@ static void dynsizevars(KINFO *); static void *expand_list(struct listinfo *); static const char * fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int), - KINFO *, char *, int); + KINFO *, char *, char *, int); static void free_list(struct listinfo *); static void init_list(struct listinfo *, addelem_rtn, int, const char *); static char *kludge_oldps_options(const char *, char *, const char *); @@ -1127,11 +1127,12 @@ sizevars(void) static const char * fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki, - char *comm, int maxlen) + char *comm, char *thread, int maxlen) { const char *s; - s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen); + s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, + showthreads && ki->ki_p->ki_numthreads > 1 ? thread : NULL, maxlen); return (s); } @@ -1159,7 +1160,7 @@ saveuser(KINFO *ki) ki->ki_args = strdup("<defunct>"); else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL)) ki->ki_args = strdup(fmt(kvm_getargv, ki, - ki->ki_p->ki_comm, MAXCOMLEN)); + ki->ki_p->ki_comm, ki->ki_p->ki_ocomm, MAXCOMLEN)); else asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm); if (ki->ki_args == NULL) @@ -1170,7 +1171,7 @@ saveuser(KINFO *ki) if (needenv) { if (UREADOK(ki)) ki->ki_env = strdup(fmt(kvm_getenvv, ki, - (char *)NULL, 0)); + (char *)NULL, (char *)NULL, 0)); else ki->ki_env = strdup("()"); if (ki->ki_env == NULL) diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index dbd41ff60b1b..32f7696da45d 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -127,7 +127,7 @@ static struct stat *ttystat(char *, int); static void usage(int); static int this_is_uptime(const char *s); -char *fmt_argv(char **, char *, int); /* ../../bin/ps/fmt.c */ +char *fmt_argv(char **, char *, char *, size_t); /* ../../bin/ps/fmt.c */ int main(int argc, char *argv[]) @@ -325,7 +325,7 @@ main(int argc, char *argv[]) continue; } ep->args = fmt_argv(kvm_getargv(kd, ep->kp, argwidth), - ep->kp->ki_comm, MAXCOMLEN); + ep->kp->ki_comm, NULL, MAXCOMLEN); if (ep->args == NULL) err(1, NULL); } @@ -392,7 +392,7 @@ main(int argc, char *argv[]) const char *ptr; ptr = fmt_argv(kvm_getargv(kd, dkp, argwidth), - dkp->ki_comm, MAXCOMLEN); + dkp->ki_comm, NULL, MAXCOMLEN); if (ptr == NULL) ptr = "-"; (void)printf("\t\t%-9d %s\n", |