[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openbsd-tech
Subject:    ps(1) cleanup
From:       Jacek Masiulaniec <jacekm () dobremiasto ! net>
Date:       2008-03-30 20:49:27
Message-ID: 20080330204927.GA21692 () lap ! my ! domain
[Download RAW message or body]

- remove repeated declarations (struct var, etc.)
- remove unused nlistread; donlist() is called only once.
- don't include headers that aren't needed.
- command(): make "left" variable assignment more readable.
- remove unused struct usave.

diff -ur ps2/extern.h ps3/extern.h
--- ps2/extern.h	Sun Mar 30 20:46:18 2008
+++ ps3/extern.h	Sun Mar 30 20:51:41 2008
@@ -33,11 +33,9 @@
  */
 
 struct nlist;
-struct var;
-struct varent;
 
 extern fixpt_t ccpu;
-extern int eval, fscale, nlistread, rawcpu, maxslp;
+extern int eval, fscale, rawcpu, maxslp;
 extern u_int mempages;
 extern int sumrusage, termwidth, totwidth;
 extern VAR var[];
diff -ur ps2/fmt.c ps3/fmt.c
--- ps2/fmt.c	Sun Mar 30 20:46:18 2008
+++ ps3/fmt.c	Sun Mar 30 20:55:28 2008
@@ -30,19 +30,12 @@
  */
 
 #include <sys/param.h>
-#include <sys/user.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <sys/proc.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/sysctl.h>
-#include <sys/types.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <vis.h>
+
 #include "ps.h"
 
 void
diff -ur ps2/nlist.c ps3/nlist.c
--- ps2/nlist.c	Sun Mar 30 20:46:18 2008
+++ ps3/nlist.c	Sun Mar 30 20:51:23 2008
@@ -67,7 +67,6 @@
 };
 
 fixpt_t	ccpu;				/* kernel _ccpu variable */
-int	nlistread;			/* if nlist already read. */
 u_int	mempages;			/* number of pages of phys. memory */
 int	fscale;				/* kernel _fscale variable */
 int	maxslp;
@@ -86,7 +85,6 @@
 	size_t siz;
 
 	rval = 0;
-	nlistread = 1;
 
 	if (kd != NULL && !kvm_sysctl_only) {
 		if (kvm_nlist(kd, psnl)) {
diff -ur ps2/print.c ps3/print.c
--- ps2/print.c	Sun Mar 30 20:46:18 2008
+++ ps3/print.c	Sun Mar 30 20:49:19 2008
@@ -107,12 +107,11 @@
 	char **argv, **p;
 
 	v = ve->var;
-	if (ve->next != NULL || termwidth != UNLIMITED) {
-		if (ve->next == NULL) {
-			left = termwidth - (totwidth - v->width);
-			if (left < 1) /* already wrapped, just use std width */
-				left = v->width;
-		} else
+	if (ve->next != NULL)
+		left = v->width;
+	else if (termwidth != UNLIMITED) {
+		left = termwidth - (totwidth - v->width);
+		if (left < 1) /* already wrapped, just use std width */
 			left = v->width;
 	} else
 		left = -1;
diff -ur ps2/ps.c ps3/ps.c
--- ps2/ps.c	Sun Mar 30 20:46:18 2008
+++ ps3/ps.c	Sun Mar 30 20:51:33 2008
@@ -296,7 +296,7 @@
 	 */
 	scanvars();
 
-	if (neednlist && !nlistread)
+	if (neednlist)
 		(void) donlist();
 
 	/*
diff -ur ps2/ps.h ps3/ps.h
--- ps2/ps.h	Sun Mar 30 20:51:59 2008
+++ ps3/ps.h	Sun Mar 30 20:56:30 2008
@@ -37,14 +37,6 @@
 	INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64
 };
 
-struct usave {
-	struct	timeval u_start;
-	struct	rusage u_ru;
-	struct	rusage u_cru;
-	char	u_acflag;
-	char	u_valid;
-};
-
 /* Variables. */
 typedef struct varent {
 	struct varent *next;

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic