diff options
-rw-r--r-- | bin/ps/ps.c | 25 |
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) { |