bin/57833: PATCH: ps cannot change title for keywords that are aliases

Jilles Tjoelker jilles at stack.nl
Fri Oct 10 06:00:42 PDT 2003


>Number:         57833
>Category:       bin
>Synopsis:       PATCH: ps cannot change title for keywords that are aliases
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 10 06:00:36 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Jilles Tjoelker
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
Eindhoven University of Technology
>Environment:
System: FreeBSD turtle.stack.nl 5.1-CURRENT FreeBSD 5.1-CURRENT #15: Thu Oct 9 11:43:55 CEST 2003 jilles at turtle.stack.nl:/usr/obj/usr/src/sys/TURTLE i386
(The world is a few days older than that.)

>Description:
Some keywords of the -o option of ps have aliases. Changing the header text
for aliases (by adding =text after the keyword) does not work.
An example is that stat is an alias for state.
>How-To-Repeat:
jilles at turtle /home/jilles$ ps -o stat=S -p $$
ps: stat: illegal keyword specification
STAT
Ss  
jilles at turtle /home/jilles$ ps -o state=S -p $$
   S
Ss  

(A useful special case is that setting all header texts to the empty string
removes the header line altogether.)

>Fix:

I have a patch.

This removes the possibility of aliases for multiple other keywords (e.g. an
alias virt for pid,state,time,sl,re,pagein,vsz,rss,lim,tsiz,%cpu,%mem,command
could make ps -o virt do the same as ps -v).  These do not exist currently,
though, and don't seem very useful to me. If it is required, the old
parsefmt(v->alias, user); return NULL; code can be added instead of errx(1,
"%s: keyword not found (alias)", p);

The user argument to findvar() is no longer used.

--- keyword.c.patch begins here ---
--- /usr/src/bin/ps/keyword.c.orig	Wed Aug 13 20:37:33 2003
+++ /usr/src/bin/ps/keyword.c	Fri Oct 10 14:09:29 2003
@@ -296,6 +296,7 @@
 	VAR *v, key;
 	char *hp;
 
+	(void)user;
 	hp = strchr(p, '=');
 	if (hp)
 		*hp++ = '\0';
@@ -304,12 +305,11 @@
 	v = bsearch(&key, var, sizeof(var)/sizeof(VAR) - 1, sizeof(VAR), vcmp);
 
 	if (v && v->alias) {
-		if (hp) {
-			warnx("%s: illegal keyword specification", p);
-			eval = 1;
-		}
-		parsefmt(v->alias, user);
-		return ((VAR *)NULL);
+		key.name = v->alias;
+		v = bsearch(&key, var, sizeof(var)/sizeof(VAR) - 1,
+			sizeof(VAR), vcmp);
+		if (v == NULL)
+			errx(1, "%s: keyword not found (alias)", p);
 	}
 	if (!v) {
 		warnx("%s: keyword not found", p);
--- keyword.c.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list