Currently if the user specifies -e and procfs is not mounted on /proc,

printing of the process environment will fail silently.

-define a function which will check to see if procfs is mounted on /proc
-Implement this test if the user specified -e
-If procfs is not mounted on /proc and -e was specified, print a warning.
 informing the user that procfs(5) is required.

Reviewed by:	wes, rwatson
This commit is contained in:
Christian S.J. Peron 2004-11-14 19:30:02 +00:00
parent 2346577455
commit a951d1f83b

View File

@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/sysctl.h>
#include <sys/mount.h>
#include <ctype.h>
#include <err.h>
@ -128,6 +129,7 @@ struct listinfo {
} l;
};
static int check_procfs(void);
static int addelem_gid(struct listinfo *, const char *);
static int addelem_pid(struct listinfo *, const char *);
static int addelem_tty(struct listinfo *, const char *);
@ -401,6 +403,14 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
/*
* If the user specified ps -e then they want a copy of the process
* environment kvm_getenvv(3) attempts to open /proc/<pid>/mem.
* Check to make sure that procfs is mounted on /proc, otherwise
* print a warning informing the user that output will be incomplete.
*/
if (needenv == 1 && check_procfs() == 0)
warnx("Process environment requires procfs(5)");
/*
* If there arguments after processing all the options, attempt
* to treat them as a list of process ids.
@ -1166,6 +1176,21 @@ kludge_oldps_options(const char *optlist, char *origval, const char *nextarg)
return (newopts);
}
static int
check_procfs(void)
{
struct statfs *mntbuf;
size_t mntsize, i;
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
for (i = 0; i < mntsize; i++)
if (strcmp(mntbuf[i].f_mntonname, "/proc") == 0 &&
strcmp(mntbuf[i].f_fstypename, "procfs") == 0) {
return (1);
}
return (0);
}
static void
usage(void)
{