From e02e41373ea3288b023e22629764ec02ce4aaee1 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 8 Jun 2016 20:30:08 -0500 Subject: Change the TNAME behavior to "Show parent argv[0]. If that's blank, showour argv[0]. If that's blank, show [stat2]." That way threads show their parents, parents show themselves, and kernel threads show the [stat2] name. --- toys/posix/ps.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/toys/posix/ps.c b/toys/posix/ps.c index def81c55..6a9676c0 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -443,13 +443,24 @@ static char *string_field(struct carveup *tb, struct strawberry *field) sl *= -1; // First string slot has offset 0, others are offset[-slot-2] if (--sl) out += tb->offset[--sl]; + // If TNAME is blank, show ARGS instead + if (which==PS_ARGS && !*out) + out = tb->str+tb->offset[-2-typos[which = PS_ARGS].slot]; if (which==PS_ARGS || which==PS_NAME) { - int i; + int i, j; s = out; for (i = 0; (which==PS_ARGS) ? i < slot[SLOT_argv0len] : out[i]; i++) if (out[i] == '/') s = out+i+1; + i = s - out; out = s; + if (which != field->which) { + j = slot[SLOT_argv0len]-i; + if (j > 259) j = 259; + memcpy(buf, out+i, j); + buf[j] = 0; + out = buf; + } } if (which>=PS_COMM && !*out) sprintf(out = buf, "[%s]", tb->str); -- cgit v1.2.3