Bug 26057

Summary: [PATCH] Minor ps(1) fixes
Product: Base System Reporter: dd <dd>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description dd freebsd_committer freebsd_triage 2001-03-25 00:10:01 UTC
When the kinfo_proc structure was introduced, the ps(1) manual page
was not updated.  Thus, it still talks about keywords that don't
exist.  Also, one line in ps.c was forgotten.  The latter results in
an annoying warning when using ps(1) with the -j flag (see
how-to-repeat).

Fix: The following patch fixes the warning and updates the man page.  I'm
only a doc committer, so someone else needs to commit the src/ part.
How-To-Repeat: 
        dd@ref5% ps -j
        ps: sess: keyword not found
        [ normal ps(1) output follows ]
Comment 1 Bruce Evans 2001-03-25 05:40:31 UTC
On Sat, 24 Mar 2001 dd@FreeBSD.ORG wrote:

> >Description:
> 
> When the kinfo_proc structure was introduced, the ps(1) manual page
> was not updated.  Thus, it still talks about keywords that don't
> exist.  Also, one line in ps.c was forgotten.  The latter results in
> an annoying warning when using ps(1) with the -j flag (see
> how-to-repeat).

Some of the bugs are in kinfo_proc, not in ps.

> Index: ps.1
> ===================================================================
> RCS file: /st/src/FreeBSD/src/bin/ps/ps.1,v
> retrieving revision 1.30
> diff -u -r1.30 ps.1
> --- ps.1	2001/02/01 16:24:50	1.30
> +++ ps.1	2001/03/20 03:34:55
> @@ -99,7 +99,7 @@
>  header per page of information.
>  .It Fl j
>  Print information associated with the following keywords:
> -user, pid, ppid, pgid, sess, jobc, state, tt, time and command.
> +user, pid, ppid, pgid, jobc, state, tt, time and command.

I think the seesion pointer can be used to distinguish sessions.
pstat(8) still prints it (pstat gets it in a different way).

>...
> -.It ktracep
> -tracing vnode
>...
> -.It p_ru
> -resource usage (valid only for zombie)

Other pointers may be useful for groping in kmem or in panic dumps, but
gdb is better for that.

I hacked my ps to show the cputime() resource usage for zombies in all
cases.  It's not very useful to print it as 0.

> -.It rsz
> -resident set size + (text size / text use count) (alias rssize)

Hopefully no one uses this any more.

Bruce
Comment 2 dima 2001-03-25 07:42:08 UTC
Bruce Evans <bde@zeta.org.au> writes:
> On Sat, 24 Mar 2001 dd@FreeBSD.ORG wrote:
> > Index: ps.1
> > ===================================================================
> > RCS file: /st/src/FreeBSD/src/bin/ps/ps.1,v
> > retrieving revision 1.30
> > diff -u -r1.30 ps.1
> > --- ps.1	2001/02/01 16:24:50	1.30
> > +++ ps.1	2001/03/20 03:34:55
> > @@ -99,7 +99,7 @@
> >  header per page of information.
> >  .It Fl j
> >  Print information associated with the following keywords:
> > -user, pid, ppid, pgid, sess, jobc, state, tt, time and command.
> > +user, pid, ppid, pgid, jobc, state, tt, time and command.
> 
> I think the seesion pointer can be used to distinguish sessions.
> pstat(8) still prints it (pstat gets it in a different way).

This is trivial to fix.  See the patch below.

> 
> >...
> > -.It ktracep
> > -tracing vnode
> >...
> > -.It p_ru
> > -resource usage (valid only for zombie)
> 
> Other pointers may be useful for groping in kmem or in panic dumps, but
> gdb is better for that.
> 
> I hacked my ps to show the cputime() resource usage for zombies in all
> cases.  It's not very useful to print it as 0.

struct rusage is exported in kinfo_proc as ki_rusage, but I don't
think ps knows about it.  I guess this is also trivial to fix, but I
haven't tried.  I'll supply a patch for this if you want, too.

The patch below adds the 'sess' option back to ps.  Mckusick
explicitly said he was removing it in his kinfo_proc commit, but
didn't specify a reason.

Regards

					Dima Dorfman
					dima@unixfreak.org

Index: bin/ps/keyword.c
===================================================================
RCS file: /st/src/FreeBSD/src/bin/ps/keyword.c,v
retrieving revision 1.29
diff -u -r1.29 keyword.c
--- bin/ps/keyword.c	2001/02/14 18:54:34	1.29
+++ bin/ps/keyword.c	2001/03/25 06:35:03
@@ -148,6 +148,7 @@
 	{"ruid", "RUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_ruid),
 		UINT, UIDFMT},
 	{"ruser", "RUSER", NULL, LJUST|DSIZ, runame, s_runame, USERLEN},
+	{"sess", "SESS", NULL, 0, kvar, NULL, 6, KOFF(ki_sess), KPTR, "lx"},
 	{"sig", "PENDING", NULL, 0, kvar, NULL, 8, KOFF(ki_siglist), INT, "x"},
 	{"sigcatch", "CAUGHT",
 		NULL, 0, kvar, NULL, 8, KOFF(ki_sigcatch), UINT, "x"},
Index: lib/libkvm/kvm_proc.c
===================================================================
RCS file: /st/src/FreeBSD/src/lib/libkvm/kvm_proc.c,v
retrieving revision 1.32
diff -u -r1.32 kvm_proc.c
--- lib/libkvm/kvm_proc.c	2001/02/12 00:21:09	1.32
+++ lib/libkvm/kvm_proc.c	2001/03/25 06:35:03
@@ -320,6 +320,7 @@
 		kp->ki_rqindex = proc.p_rqindex;
 		kp->ki_oncpu = proc.p_oncpu;
 		kp->ki_lastcpu = proc.p_lastcpu;
+		kp->ki_sess = proc.p_session;
 		bcopy(&kinfo_proc, bp, sizeof(kinfo_proc));
 		++bp;
 		++cnt;
Index: sys/kern/kern_proc.c
===================================================================
RCS file: /st/src/FreeBSD/src/sys/kern/kern_proc.c,v
retrieving revision 1.89
diff -u -r1.89 kern_proc.c
--- sys/kern/kern_proc.c	2001/03/07 06:52:12	1.89
+++ sys/kern/kern_proc.c	2001/03/25 06:35:03
@@ -509,6 +509,7 @@
 	kp->ki_lock = p->p_lock;
 	if (p->p_pptr)
 		kp->ki_ppid = p->p_pptr->p_pid;
+	kp->ki_sess = p->p_session;
 	PROC_UNLOCK(p);
 } 
 
Index: sys/sys/user.h
===================================================================
RCS file: /st/src/FreeBSD/src/sys/sys/user.h,v
retrieving revision 1.35
diff -u -r1.35 user.h
--- sys/sys/user.h	2001/03/09 11:34:29	1.35
+++ sys/sys/user.h	2001/03/25 06:35:03
@@ -149,7 +149,8 @@
 	struct	rusage ki_rusage;	/* process rusage statistics */
 	long	ki_sflag;		/* PS_* flags */
 	struct	priority ki_pri;	/* process priority */
-	long	ki_spare[25];		/* spare constants */
+	struct	session *ki_sess;	/* session pointer */
+	long	ki_spare[24];		/* spare constants */
 };
 void fill_kinfo_proc __P((struct proc *, struct kinfo_proc *));
Comment 3 Poul-Henning Kamp freebsd_committer freebsd_triage 2001-03-28 19:27:20 UTC
State Changed
From-To: open->closed

I think the reason for the 'w' option in the first place is 
to disable the default window-width setting. 

As Wollman notes, breaking a very common case would hurt POLA.
Comment 4 dima 2001-03-28 20:03:46 UTC
<phk@FreeBSD.org> writes:
> Synopsis: [PATCH] Minor ps(1) fixes
> 
> State-Changed-From-To: open->closed
> State-Changed-By: phk
> State-Changed-When: Wed Mar 28 10:27:20 PST 2001
> State-Changed-Why: 
> I think the reason for the 'w' option in the first place is
> to disable the default window-width setting.
> 
> As Wollman notes, breaking a very common case would hurt POLA.

Um, I think you closed the wrong PR.  This one does not talk about the
'w' option.  PR 25855 does.  This one fixes this:

	dd@ref5% ps j
	ps: sess: keyword not found
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	[ normal ps output ]

and some stuff in a man page.  Also note that Wollman never said
anything about this PR.

Please re-open (and/or commit :-) it.

Regards

					Dima Dorfman
					dima@unixfreak.org
Comment 5 Poul-Henning Kamp freebsd_committer freebsd_triage 2001-03-28 20:07:08 UTC
State Changed
From-To: closed->open

Dang, wrong PR.  Ignore last entry.
Comment 6 Poul-Henning Kamp 2001-03-28 20:08:31 UTC
Thanks for noticing my cut&paste-o :-!

In message <20010328190346.F3D1C3E09@bazooka.unixfreak.org>, Dima Dorfman write
s:
><phk@FreeBSD.org> writes:
>> Synopsis: [PATCH] Minor ps(1) fixes
>> 
>> State-Changed-From-To: open->closed
>> State-Changed-By: phk
>> State-Changed-When: Wed Mar 28 10:27:20 PST 2001
>> State-Changed-Why: 
>> I think the reason for the 'w' option in the first place is
>> to disable the default window-width setting.
>> 
>> As Wollman notes, breaking a very common case would hurt POLA.
>
>Um, I think you closed the wrong PR.  This one does not talk about the
>'w' option.  PR 25855 does.  This one fixes this:
>
>	dd@ref5% ps j
>	ps: sess: keyword not found
>       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>	[ normal ps output ]
>
>and some stuff in a man page.  Also note that Wollman never said
>anything about this PR.
>
>Please re-open (and/or commit :-) it.
>
>Regards
>
>					Dima Dorfman
>					dima@unixfreak.org
>
>

--
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.
Comment 7 dd freebsd_committer freebsd_triage 2001-04-07 04:19:09 UTC
State Changed
From-To: open->closed

ps.c part committed by brian (1.37 of bin/ps/ps.c).  I'll update the 
man page later today.
Comment 8 Bruce Evans 2001-04-07 09:13:38 UTC
On Fri, 6 Apr 2001 dd@FreeBSD.ORG wrote:

> Synopsis: [PATCH] Minor ps(1) fixes
> 
> State-Changed-From-To: open->closed
> State-Changed-By: dd
> State-Changed-When: Fri Apr 6 20:19:09 PDT 2001
> State-Changed-Why: 
> ps.c part committed by brian (1.37 of bin/ps/ps.c).  I'll update the
> man page later today.

The committed fix is half-baked at best.  It does't even remove the
session keyword like the first version of the PR does.

Kirk also removed the tsess pointer and keyword from everywhere except
ps.1, but the PR doesn't mention it.  The log message for rev.1.25 of
keyword.c says the following about the removal:

    kernel/user interface, specifically rusage and rtprio. It no
    longer contains proc, session, pcred, ucred, procsig, vmspace,
    pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
    any of these changed in size, ps, w, fstat, gcore, systat, and
    top would all stop working. The new structure has over 200 bytes

This is incorrect for "session" in ps at least.  ps would not have
stopped working if sizeof(struct session) changed, since it just
printed the session pointer.

Bruce