From jilles@stack.nl  Fri Oct 10 05:54:07 2003
Return-Path: <jilles@stack.nl>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id C137516A4B3
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 10 Oct 2003 05:54:07 -0700 (PDT)
Received: from hexagon.stack.nl (hexagon.stack.nl [131.155.140.144])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E35BE43FE1
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 10 Oct 2003 05:54:06 -0700 (PDT)
	(envelope-from jilles@stack.nl)
Received: from turtle.stack.nl (turtle.stack.nl [2001:610:1108:5010:2e0:81ff:fe22:51d8])
	by hexagon.stack.nl (Postfix) with ESMTP id EC7EF1C0F
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 10 Oct 2003 14:54:05 +0200 (CEST)
Received: by turtle.stack.nl (Postfix, from userid 1677)
	id DC33C1CC71; Fri, 10 Oct 2003 14:54:05 +0200 (CEST)
Message-Id: <20031010125405.DC33C1CC71@turtle.stack.nl>
Date: Fri, 10 Oct 2003 14:54:05 +0200 (CEST)
From: Jilles Tjoelker <jilles@stack.nl>
Reply-To: Jilles Tjoelker <jilles@stack.nl>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: PATCH: ps cannot change title for keywords that are aliases
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         57833
>Category:       bin
>Synopsis:       [PATCH] bin/ps cannot change title for keywords that are aliases
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gad
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 10 06:00:36 PDT 2003
>Closed-Date:    Tue Mar 07 15:34:07 GMT 2006
>Last-Modified:  Tue Mar 07 15:34:07 GMT 2006
>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@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@turtle /home/jilles$ ps -o stat=S -p $$
ps: stat: illegal keyword specification
STAT
Ss  
jilles@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:
Responsible-Changed-From-To: freebsd-bugs->gad 
Responsible-Changed-By: gad 
Responsible-Changed-When: Sat May 22 16:21:48 PDT 2004 
Responsible-Changed-Why:  
I will be looking into this as I work on other changes to `ps'. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=57833 

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, jilles@stack.nl, gad@freebsd.org
Cc:  
Subject: Re: bin/57833: [PATCH] bin/ps cannot change title for keywords that are aliases
Date: Tue, 7 Mar 2006 16:02:45 +0100

 As part of the changes to ps, this appears to have been fixed.
 Please close this PR.
 
 -- 
 Jilles Tjoelker
State-Changed-From-To: open->closed 
State-Changed-By: flz 
State-Changed-When: Tue Mar 7 15:34:06 UTC 2006 
State-Changed-Why:  
Committed some time ago, PR closed at submitters request. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=57833 
>Unformatted:
