CVS commit: [netbsd-8] src/bin/ps

2021-04-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Apr  6 18:09:52 UTC 2021

Modified Files:
src/bin/ps [netbsd-8]: print.c

Log Message:
Pull up following revision(s) (requested by simonb in ticket #1669):

bin/ps/print.c: revision 1.133

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.127 -r1.127.6.1 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.127 src/bin/ps/print.c:1.127.6.1
--- src/bin/ps/print.c:1.127	Mon Dec 12 20:35:36 2016
+++ src/bin/ps/print.c	Tue Apr  6 18:09:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: print.c,v 1.127 2016/12/12 20:35:36 christos Exp $	*/
+/*	$NetBSD: print.c,v 1.127.6.1 2021/04/06 18:09:52 martin 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.127 2016/12/12 20:35:36 christos Exp $");
+__RCSID("$NetBSD: print.c,v 1.127.6.1 2021/04/06 18:09:52 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -810,22 +810,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());
+			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());
-		strprintorsetwidth(v, buf, mode);
+		} else {
+			(void)strftime(buf, sizeof(buf) -1, "%c",
+			localtime());
+			strprintorsetwidth(v, buf, mode);
+		}
 	}
 }
 



CVS commit: [netbsd-8] src/bin/ps

2021-04-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Apr  6 18:09:52 UTC 2021

Modified Files:
src/bin/ps [netbsd-8]: print.c

Log Message:
Pull up following revision(s) (requested by simonb in ticket #1669):

bin/ps/print.c: revision 1.133

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.127 -r1.127.6.1 src/bin/ps/print.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: [netbsd-8] src/bin/ps

2018-02-03 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sat Feb  3 22:11:36 UTC 2018

Modified Files:
src/bin/ps [netbsd-8]: ps.c

Log Message:
Pull up following revision(s) (requested by kamil in ticket #515):
bin/ps/ps.c: revision 1.89
Fix an unitialized memory read bug in ps(1)
rawcpu of type int, is declared inside main(){} and it can be passed as
uninitialized to setpinfo().
The setpinfo() function has a switch checking the value of rawcpu:
  if (!rawcpu)
pi[i].pcpu /= 1.0 - exp(ki[i].p_swtime * log_ccpu);
rawcpu is set to 1 with the command line argument "-C".
   -C   Change the way the CPU percentage is calculated by using a
"raw" CPU calculation that ignores "resident" time (this
normally has no effect).
Bug reproducible with an invocation: "ps u". It hides with "ps uC".
Initialize rawcpu by default to 0, before the getopt(3) machinery.
Detected with MSan running on NetBSD/amd64.
Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.88.6.1 src/bin/ps/ps.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: [netbsd-8] src/bin/ps

2018-02-03 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sat Feb  3 22:11:36 UTC 2018

Modified Files:
src/bin/ps [netbsd-8]: ps.c

Log Message:
Pull up following revision(s) (requested by kamil in ticket #515):
bin/ps/ps.c: revision 1.89
Fix an unitialized memory read bug in ps(1)
rawcpu of type int, is declared inside main(){} and it can be passed as
uninitialized to setpinfo().
The setpinfo() function has a switch checking the value of rawcpu:
  if (!rawcpu)
pi[i].pcpu /= 1.0 - exp(ki[i].p_swtime * log_ccpu);
rawcpu is set to 1 with the command line argument "-C".
   -C   Change the way the CPU percentage is calculated by using a
"raw" CPU calculation that ignores "resident" time (this
normally has no effect).
Bug reproducible with an invocation: "ps u". It hides with "ps uC".
Initialize rawcpu by default to 0, before the getopt(3) machinery.
Detected with MSan running on NetBSD/amd64.
Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.88.6.1 src/bin/ps/ps.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/ps.c
diff -u src/bin/ps/ps.c:1.88 src/bin/ps/ps.c:1.88.6.1
--- src/bin/ps/ps.c:1.88	Mon Dec 26 20:52:39 2016
+++ src/bin/ps/ps.c	Sat Feb  3 22:11:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ps.c,v 1.88 2016/12/26 20:52:39 rin Exp $	*/
+/*	$NetBSD: ps.c,v 1.88.6.1 2018/02/03 22:11:36 snj Exp $	*/
 
 /*
  * Copyright (c) 2000-2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 19
 #if 0
 static char sccsid[] = "@(#)ps.c	8.4 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: ps.c,v 1.88 2016/12/26 20:52:39 rin Exp $");
+__RCSID("$NetBSD: ps.c,v 1.88.6.1 2018/02/03 22:11:36 snj Exp $");
 #endif
 #endif /* not lint */
 
@@ -224,7 +224,7 @@ main(int argc, char *argv[])
 	if (argc > 1)
 		argv[1] = kludge_oldps_options(argv[1]);
 
-	descendancy = fmt = prtheader = wflag = xflg = showlwps = 0;
+	descendancy = fmt = prtheader = wflag = xflg = rawcpu = showlwps = 0;
 	what = KERN_PROC_UID;
 	flag = myuid = getuid();
 	memf = nlistf = swapf = NULL;