Subject: Re: fork1(), uvm_fork() and cpu_fork()
To: Alan Barrett <apb@cequrux.com>
From: Greg A. Woods <woods@weird.com>
List: tech-kern
Date: 11/30/2002 17:12:05
[ On Saturday, November 30, 2002 at 13:00:35 (+0200), Alan Barrett wrote: ]
> Subject: Re: fork1(), uvm_fork() and cpu_fork()
>
> On Fri, 29 Nov 2002, David Laight wrote:
> > However something so that 'ps' could display more of the
> > information might be useful.
> 
> FreeBSD's "ps" has a "-f" option for this.  The man page says:
> 
>      -f      Show commandline and environment information about swapped
>              out processes.  This option is honored only if the uid of
>              the user is 0.

the code starts out being quite confusing:

#if defined(LAZY_PS)
                case 'f':
                        if (getuid() == 0 || getgid() == 0)
                            forceuread = 1;
                        break;
#endif


Hmmm -- I wonder why it is restricted to root....  If you don't define
LAZY_PS when compiling then forceuread defaults to '1' all the time.

From the code that uses 'forceuread' I'm not sure it actually means what
it says......  In FreeBSD, at least up to and including 4.7, 'ps' uses
kvm_getprocs() to get the proc structure and user areas, which reads
from /dev/kmem.  In the end though '-f' (or #undef LAZY_PS) only allows
the presentation of command-line args and environment variables, which
are always read from procfs iff the system is live.  How confusing!

It looks like restricting '-f' to root or wheel members is simply a
policy decision to hide command-line args and environment values from
unprivileged users (as per what the manual text you quote says), which
seems a bit silly, especially given the interaction with -DLAZY_PS.

-- 
								Greg A. Woods

+1 416 218-0098;            <g.a.woods@ieee.org>;           <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>