From a65de0fd7337116ef43e9e5597ea507e910f5c8b Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Mon, 17 Sep 2012 15:30:45 -0500 Subject: [PATCH] ps: favor truncation of long names over POSIX/UNIX standard The UNIX and POSIX standards require that user and group names be printed as decimal integers when there is insufficient room. This has led to a constant stream of bug reports. With this commit, long names will be truncated and displayed with a trailing visual clue. To avoid truncation. the UNIX and POSIX way to change column width is to rename the column: ps -o pid,user=CumbersomeUserNames -o comm The easy way is to directly specify the desired width: ps -o pid,user:19,comm Reference: http://www.freelists.org/post/procps/rhbz737215-ps-does-not-resolve-some-user-names Signed-off-by: Jim Warner --- ps/output.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ps/output.c b/ps/output.c index cf02e0a1..9644ed3b 100644 --- a/ps/output.c +++ b/ps/output.c @@ -1075,7 +1075,9 @@ static int pr_fuid(char *restrict const outbuf, const proc_t *restrict const pp) // The Open Group Base Specifications Issue 6 (IEEE Std 1003.1, 2004 Edition) // requires that user and group names print as decimal numbers if there is -// not enough room in the column, so tough luck if you don't like it. +// not enough room in the column. However, we will now truncate such names +// and provide a visual hint of such truncation. Hopefully, this will reduce +// the volume of bug reports regarding that former 'feature'. // // The UNIX and POSIX way to change column width is to rename it: // ps -o pid,user=CumbersomeUserNames -o comm @@ -1092,6 +1094,11 @@ static int do_pr_name(char *restrict const outbuf, const char *restrict const na if(len <= (int)max_rightward) return len; /* returns number of cells */ + + len = max_rightward-1; + outbuf[len++] = '+'; + outbuf[len] = 0; + return len; } return snprintf(outbuf, COLWID, "%u", u); } @@ -1108,7 +1115,6 @@ static int pr_fuser(char *restrict const outbuf, const proc_t *restrict const pp static int pr_suser(char *restrict const outbuf, const proc_t *restrict const pp){ return do_pr_name(outbuf, pp->suser, pp->suid); } - static int pr_egroup(char *restrict const outbuf, const proc_t *restrict const pp){ return do_pr_name(outbuf, pp->egroup, pp->egid); } -- 2.40.0