diff --git a/bin/ps/ps.c b/bin/ps/ps.c index dcb701821f53..6455ea66202d 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -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//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) {