aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2020-07-28 15:26:19 +0000
committerMark Johnston <markj@FreeBSD.org>2020-07-28 15:26:19 +0000
commitc7f893a42b9572f1152d163290202b855953a768 (patch)
treeb4cff4c4a8b225a2498ddcf36f0c032c79dcc1db
parentce69217c7b8f81e5bcdf1337ceb729100acf8747 (diff)
downloadsrc-c7f893a42b9572f1152d163290202b855953a768.tar.gz
src-c7f893a42b9572f1152d163290202b855953a768.zip
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
Notes
Notes: svn path=/head/; revision=363649
-rw-r--r--bin/ps/ps.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index f6d32e5411fe..d3cfc669d581 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -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;
}