From 85a6addd235e1c13d2e67e5e9b6d4c963b47140d Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 21 Mar 2008 13:04:29 +0000 Subject: Only test crashed services if we can see pid 1. --- src/rc/rc-status.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/rc/rc-status.c') diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c index c7173e2..ef58a14 100644 --- a/src/rc/rc-status.c +++ b/src/rc/rc-status.c @@ -41,9 +41,35 @@ #include "rc-misc.h" extern const char *applet; - +static bool test_crashed = false; static const char *const types_nua[] = { "ineed", "iuse", "iafter", NULL }; +bool _rc_findpid1(void) +{ + RC_PIDLIST *pids; + RC_PID *pid; + RC_PID *pid2; + bool retval = false; + + /* If we cannot see process 1, then we don't test to see if + * services crashed or not */ + pids = rc_find_pids(NULL, NULL, 0, 1); + if (pids) { + pid = LIST_FIRST(pids); + if (pid) { + retval = true; + while (pid) { + pid2 = LIST_NEXT(pid, entries); + free(pid); + pid = pid2; + } + } + free(pids); + } + + return retval; +} + static void print_level(char *level) { printf ("Runlevel: "); @@ -73,7 +99,7 @@ static void print_service(char *service) snprintf(status, sizeof(status), "inactive "); color = ECOLOR_WARN; } else if (state & RC_SERVICE_STARTED) { - if (rc_service_daemons_crashed(service)) + if (test_crashed && rc_service_daemons_crashed(service)) snprintf(status, sizeof(status), " crashed "); else { snprintf(status, sizeof(status), " started "); @@ -112,7 +138,7 @@ static const char * const longopts_help[] = { }; #include "_usage.c" -int rc_status (int argc, char **argv) +int rc_status(int argc, char **argv) { RC_DEPTREE *deptree = NULL; RC_STRINGLIST *levels = NULL; @@ -125,6 +151,8 @@ int rc_status (int argc, char **argv) int opt; int depopts = RC_DEP_STRICT | RC_DEP_START | RC_DEP_TRACE; + test_crashed = _rc_findpid1(); + while ((opt = getopt_long(argc, argv, getoptstring, longopts, (int *) 0)) != -1) switch (opt) { -- cgit v1.2.3