[procps] [PATCH] top: check for /proc before running

  • From: Mike Frysinger <vapier@xxxxxxxxxx>
  • To: procps@xxxxxxxxxxxxx
  • Date: Tue, 24 Apr 2012 22:48:26 -0400

If /proc is not mounted when someone runs top, the console is left in
a bad state (which `reset` doesn't fully restore).  So add a sanity
check when starting up.

I think this dates back to a Fedora patch, but I've updated it to the
current git.

Signed-off-by: Mike Frysinger <vapier@xxxxxxxxxx>
---
 top/top.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/top/top.c b/top/top.c
index 41b69a7..522f4d1 100644
--- a/top/top.c
+++ b/top/top.c
@@ -3904,6 +3904,10 @@ int main (int dont_care_argc, char **argv) {
    (void)dont_care_argc;
    atexit(close_stdout);
    before(*argv);
+
+   if (access("/proc/stat", F_OK))
+      error_exit("/proc is not mounted, required for output data");
+
                                         //                 +-------------+
    wins_stage_1();                      //                 top (sic) slice
    configs_read();                      //                 > spread etc, <
-- 
1.7.8.5


Other related posts: