summaryrefslogtreecommitdiffstats
path: root/bin/ps
diff options
context:
space:
mode:
authorcsjp <csjp@FreeBSD.org>2004-11-14 19:30:02 +0000
committercsjp <csjp@FreeBSD.org>2004-11-14 19:30:02 +0000
commit27bff94fe5462b95315e20dd0b2a7c8d6da8677f (patch)
tree39318b6578337c6d25e119430005ba4d654d75a2 /bin/ps
parent89e05e38ca35e42f70b77dc81498521299be3610 (diff)
downloadFreeBSD-src-27bff94fe5462b95315e20dd0b2a7c8d6da8677f.zip
FreeBSD-src-27bff94fe5462b95315e20dd0b2a7c8d6da8677f.tar.gz
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
Diffstat (limited to 'bin/ps')
-rw-r--r--bin/ps/ps.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index dcb7018..6455ea6 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -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 *);
@@ -402,6 +404,14 @@ main(int argc, char *argv[])
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)
{
OpenPOWER on IntegriCloud