ps(1): Fix formatting of the "command" field for kernel threads.

When -H is specified, for kernel threads the command is formatted as
"<proc name>/<td name>" and truncated to MAXCOMLEN.  But each of the
proc name and td name may be up to MAXCOMLEN bytes in length.

Also handle the ki_moretdname field to ensure that the full thread name
gets printed.  This is already handled correctly when formatting for
"-o tdname".

Reported by:	freqlabs
Reviewed by:	freqlabs
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D25840
This commit is contained in:
Mark Johnston 2020-07-28 15:26:19 +00:00
parent ce69217c7b
commit c7f893a42b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=363649

View file

@ -1264,6 +1264,7 @@ fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki,
static void
saveuser(KINFO *ki)
{
char tdname[COMMLEN + 1];
char *argsp;
if (ki->ki_p->ki_flag & P_INMEM) {
@ -1280,12 +1281,14 @@ saveuser(KINFO *ki)
* save arguments if needed
*/
if (needcomm) {
if (ki->ki_p->ki_stat == SZOMB)
if (ki->ki_p->ki_stat == SZOMB) {
ki->ki_args = strdup("<defunct>");
else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL))
} else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL)) {
(void)snprintf(tdname, sizeof(tdname), "%s%s",
ki->ki_p->ki_tdname, ki->ki_p->ki_moretdname);
ki->ki_args = fmt(kvm_getargv, ki,
ki->ki_p->ki_comm, ki->ki_p->ki_tdname, MAXCOMLEN);
else {
ki->ki_p->ki_comm, tdname, COMMLEN * 2 + 1);
} else {
asprintf(&argsp, "(%s)", ki->ki_p->ki_comm);
ki->ki_args = argsp;
}