mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-03 14:48:57 +00:00
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. Reviewed by: alfred, delphij, eric@vangyzen.net MFC after: 1 week
This commit is contained in:
parent
38d90616e6
commit
1c67ef129f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=245610
@ -51,7 +51,7 @@ char *elapsed(KINFO *, VARENT *);
|
||||
char *elapseds(KINFO *, VARENT *);
|
||||
char *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 *);
|
||||
char *kvar(KINFO *, VARENT *);
|
||||
char *label(KINFO *, VARENT *);
|
||||
|
13
bin/ps/fmt.c
13
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 (showthreads && 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);
|
||||
|
11
bin/ps/ps.c
11
bin/ps/ps.c
@ -141,7 +141,7 @@ static void format_output(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 *);
|
||||
@ -1163,11 +1163,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,
|
||||
ki->ki_p->ki_numthreads > 1 ? thread : NULL, maxlen);
|
||||
return (s);
|
||||
}
|
||||
|
||||
@ -1195,7 +1196,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_tdname, MAXCOMLEN));
|
||||
else
|
||||
asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm);
|
||||
if (ki->ki_args == NULL)
|
||||
@ -1206,7 +1207,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)
|
||||
|
Loading…
Reference in New Issue
Block a user