From bb1da2bd7c86b438e8132e93e2a427689b28e4c5 Mon Sep 17 00:00:00 2001 From: jhb Date: Fri, 1 Mar 2013 01:02:44 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.freebsd.org/base/stable/8@247517 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- bin/ps/extern.h | 2 +- bin/ps/fmt.c | 13 +++++++++---- bin/ps/ps.c | 11 ++++++----- 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 7d261276b..76861f121 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 1e9fed871..4db6b8d1d 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 ab511d108..c5b6e1680 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(""); 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 dbd41ff60..32f7696da 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", -- 2.45.0