Module Name: src
Committed By: simonb
Date: Tue Apr 6 05:13:24 UTC 2021
Modified Files:
src/bin/ps: print.c
Log Message:
Fix the column width calculation for the lstart column if an empty
column header is specified.
Fixes bug pointed out by Ted Spradley in
https://mail-index.netbsd.org/netbsd-users/2021/04/05/msg026808.html .
To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/bin/ps/print.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/ps/print.c
diff -u src/bin/ps/print.c:1.132 src/bin/ps/print.c:1.133
--- src/bin/ps/print.c:1.132 Wed Jun 19 21:25:50 2019
+++ src/bin/ps/print.c Tue Apr 6 05:13:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: print.c,v 1.132 2019/06/19 21:25:50 kamil Exp $ */
+/* $NetBSD: print.c,v 1.133 2021/04/06 05:13:24 simonb Exp $ */
/*
* Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
#if 0
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
#else
-__RCSID("$NetBSD: print.c,v 1.132 2019/06/19 21:25:50 kamil Exp $");
+__RCSID("$NetBSD: print.c,v 1.133 2021/04/06 05:13:24 simonb Exp $");
#endif
#endif /* not lint */
@@ -815,22 +815,33 @@ lstarted(struct pinfo *pi, VARENT *ve, e
char buf[100];
v = ve->var;
- if (!k->p_uvalid) {
+ startt = k->p_ustart_sec;
+
+ if (mode == WIDTHMODE) {
/*
- * Minimum width is less than header - we don't
- * need to check it every time.
+ * We only need to set the width once, as we assume
+ * that all times are the same length. We do need to
+ * check against the header length as well, as "no
+ * header" mode for this variable will set the field
+ * width to the length of the header anyway (ref: the
+ * P1003.1-2004 comment in findvar()).
+ *
+ * XXX: The hardcoded "STARTED" string. Better or
+ * worse than a "<= 7" or some other arbitary number?
*/
- if (mode == PRINTMODE)
+ if (v->width <= (int)strlen("STARTED")) {
+ (void)strftime(buf, sizeof(buf) -1, "%c",
+ localtime(&startt));
+ strprintorsetwidth(v, buf, mode);
+ }
+ } else {
+ if (!k->p_uvalid) {
(void)printf("%*s", v->width, "-");
- return;
- }
- startt = k->p_ustart_sec;
-
- /* assume all times are the same length */
- if (mode != WIDTHMODE || v->width == 0) {
- (void)strftime(buf, sizeof(buf) -1, "%c",
- localtime(&startt));
- strprintorsetwidth(v, buf, mode);
+ } else {
+ (void)strftime(buf, sizeof(buf) -1, "%c",
+ localtime(&startt));
+ strprintorsetwidth(v, buf, mode);
+ }
}
}