From 9915ae30baea58608c15ce277c66172f12288ce0 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 10 Jan 2008 14:18:39 +0000 Subject: [PATCH] Warn the user if he uses -e and procfs(5) is not mounted. Obtained-from: FreeBSD --- bin/ps/ps.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 5024b795f5..337b00e57e 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1990, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)ps.c 8.4 (Berkeley) 4/2/94 * $FreeBSD: src/bin/ps/ps.c,v 1.30.2.6 2002/07/04 08:30:37 sobomax Exp $ - * $DragonFly: src/bin/ps/ps.c,v 1.24 2007/12/27 13:31:42 matthias Exp $ + * $DragonFly: src/bin/ps/ps.c,v 1.25 2008/01/10 14:18:39 matthias Exp $ */ #include @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,7 @@ static void saveuser (KINFO *); static void scanvars (void); static void dynsizevars (KINFO *); static void sizevars (void); +static int check_procfs(void); static void usage (void); static uid_t *getuids(const char *, int *); @@ -293,6 +295,15 @@ 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)"); + #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { @@ -643,6 +654,18 @@ kludge_oldps_options(char *s) return (newopts); } +static int +check_procfs(void) +{ + struct statfs mnt; + + if (statfs("/proc", &mnt) < 0) + return (0); + if (strcmp(mnt.f_fstypename, "procfs") != 0) + return (0); + return (1); +} + static void usage(void) { -- 2.41.0