[net.bugs.v7] making ps work better

henry (06/16/82)

The standard V7 ps can't find a process's argument list to print it
when the size of the argument list plus the environment exceeds 512
bytes.  One could do various things to ps to improve this, but it's
simpler to take advantage of an undocumented feature of ps:  the
topmost word in a process's data, if nonNULL, is taken to be a pointer
to argv.  This is how things like the shell alter their appearance
to ps.  We documented this some time ago and find it useful.  Anyway,
it is very straightforward to change the kernel so this pointer is
initialized not to NULL (which is how the standard V7 does it) but
to a real live pointer to argv.

To make the change, add the following local declaration in sys1.c/exece():

 	int sexecargs;			/* Value for *execargs. */

Add the following just after the "suword((caddr_t)ap, na-ne);" which
supplies argc to the process:

 	sexecargs = ap + NBPW;		/* Remember location of argv. */

And add the following just after the "suword((caddr_t)ucp, 0);" at the
tail end of the argument recopying:

 	suword((caddr_t)(-NBPW), sexecargs);	/* *execargs. */

The following is a *correct* version of /usr/include/execargs.h (the
Bell version has the type wrong):

	char ***execargs = (char***)(-2);

And here is a locally-written manual page, execargs.3:

-----
.TH EXECARGS 3 PDP11,local
.DA 15 June 1982
.SH NAME
execargs \- change argument string displayed to world
.SH SYNOPSIS
.B #include <execargs.h>
.PP
.BR "*execargs = " newargv ;
.SH DESCRIPTION
The variable
.I execargs
points to (on the PDP11) the highest location in memory.
.IR Exec (2)
initializes this location to
.IR argv .
.IR Ps (1)
and its brethren
use
the value in this location as a pointer
to the argument list to be displayed
(unless it is NULL, in which case
.I ps
uses heuristics to try to locate the original argument list).
.PP
Altering
.I *execargs
is of use to programs which wish to either hide
the original argument list
or display an argument list different from the one they were
invoked with.
The former is useful to things like encryption programs, although
it should be noted that there is still a ``window'' between process
initialization and process startup during which the original
argument list will be visible.
The latter is handy for programs that wish to present more detailed
or more selective information.
.SH SEE ALSO
ps(1)
.SH HISTORY
A Bell feature, but undocumented.
The Bell kernel initialized
.I *execargs
to NULL, not
.IR argv .
.PP
The Bell version had the type declared wrong;  fixed.
.SH BUGS
Not portable.
-----