We should show hotplugged services, needed services and manually started services in rc-status.

This commit is contained in:
Roy Marples 2008-10-30 14:59:14 +00:00
parent 53ddd6ca96
commit 2ff0838abb
3 changed files with 97 additions and 49 deletions

7
src/rc/.gitignore vendored
View File

@ -13,12 +13,12 @@ eerrorn
eerror eerror
ebegin ebegin
eend eend
ewaitfile
ewend ewend
eindent eindent
eoutdent eoutdent
esyslog esyslog
eval_ecolors eval_ecolors
ewaitfile
veinfo veinfo
vewarn vewarn
vebegin vebegin
@ -32,7 +32,7 @@ service_stopping
service_stopped service_stopped
service_inactive service_inactive
service_wasinactive service_wasinactive
service_coldplugged service_hotplugged
service_started_daemon service_started_daemon
checkpath checkpath
fstabinfo fstabinfo
@ -51,7 +51,7 @@ mark_service_stopping
mark_service_stopped mark_service_stopped
mark_service_inactive mark_service_inactive
mark_service_wasinactive mark_service_wasinactive
mark_service_coldplugged mark_service_hotplugged
mark_service_failed mark_service_failed
rc-abort rc-abort
checkpath.o checkpath.o
@ -68,6 +68,5 @@ rc-status.o
rc-update.o rc-update.o
runscript.o runscript.o
rc.o rc.o
rc.core
rc rc
.depend .depend

View File

@ -18,14 +18,14 @@ RC_BINLINKS= einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \
service_starting service_started \ service_starting service_started \
service_stopping service_stopped \ service_stopping service_stopped \
service_inactive service_wasinactive \ service_inactive service_wasinactive \
service_coldplugged service_started_daemon \ service_hotplugged service_started_daemon \
checkpath fstabinfo mountinfo rc-depend \ checkpath fstabinfo mountinfo rc-depend \
service_get_value service_set_value get_options save_options \ service_get_value service_set_value get_options save_options \
shell_var is_newer_than is_older_than shell_var is_newer_than is_older_than
RC_SBINLINKS= mark_service_starting mark_service_started \ RC_SBINLINKS= mark_service_starting mark_service_started \
mark_service_stopping mark_service_stopped \ mark_service_stopping mark_service_stopped \
mark_service_inactive mark_service_wasinactive \ mark_service_inactive mark_service_wasinactive \
mark_service_coldplugged mark_service_failed \ mark_service_hotplugged mark_service_failed \
rc-abort rc-abort
ALL_LINKS= ${BINLINKS} ${SBINLINKS} ${RC_BINLINKS} ${RC_SBINLINKS} ALL_LINKS= ${BINLINKS} ${SBINLINKS} ${RC_BINLINKS} ${RC_SBINLINKS}
CLEANFILES+= ${ALL_LINKS} CLEANFILES+= ${ALL_LINKS}

View File

@ -42,10 +42,14 @@
extern const char *applet; extern const char *applet;
static bool test_crashed = false; static bool test_crashed = false;
static RC_DEPTREE *deptree = NULL; static RC_DEPTREE *deptree;
static RC_STRINGLIST *types = NULL; static RC_STRINGLIST *types;
bool _rc_can_find_pids(void) static RC_STRINGLIST *levels, *services, *tmp, *alist;
static RC_STRINGLIST *sservices, *nservices, *needsme;
bool
_rc_can_find_pids(void)
{ {
RC_PIDLIST *pids; RC_PIDLIST *pids;
RC_PID *pid; RC_PID *pid;
@ -70,11 +74,11 @@ bool _rc_can_find_pids(void)
} }
free(pids); free(pids);
} }
return retval; return retval;
} }
static void print_level(const char *level) static void
print_level(const char *level)
{ {
printf ("Runlevel: "); printf ("Runlevel: ");
if (isatty(fileno(stdout))) if (isatty(fileno(stdout)))
@ -86,7 +90,8 @@ static void print_level(const char *level)
printf("%s\n", level); printf("%s\n", level);
} }
static void print_service(const char *service) static void
print_service(const char *service)
{ {
char status[10]; char status[10];
int cols = printf(" %s", service); int cols = printf(" %s", service);
@ -125,18 +130,19 @@ static void print_service(const char *service)
ebracket(cols, color, status); ebracket(cols, color, status);
} }
static void print_services(const char *runlevel, RC_STRINGLIST *services) static void
print_services(const char *runlevel, RC_STRINGLIST *svcs)
{ {
RC_STRINGLIST *l = NULL; RC_STRINGLIST *l = NULL;
RC_STRING *s; RC_STRING *s;
char *r = NULL; char *r = NULL;
if (! services) if (!svcs)
return; return;
if (!deptree) if (!deptree)
deptree = _rc_deptree_load(NULL); deptree = _rc_deptree_load(NULL);
if (!deptree) { if (!deptree) {
TAILQ_FOREACH(s, services, entries) TAILQ_FOREACH(s, svcs, entries)
if (!runlevel || if (!runlevel ||
rc_service_in_runlevel(s->value, runlevel)) rc_service_in_runlevel(s->value, runlevel))
print_service(s->value); print_service(s->value);
@ -150,13 +156,13 @@ static void print_services(const char *runlevel, RC_STRINGLIST *services)
} }
if (!runlevel) if (!runlevel)
r = rc_runlevel_get(); r = rc_runlevel_get();
l = rc_deptree_depends(deptree, types, services, r ? r : runlevel, l = rc_deptree_depends(deptree, types, svcs, r ? r : runlevel,
RC_DEP_STRICT | RC_DEP_TRACE | RC_DEP_START); RC_DEP_STRICT | RC_DEP_TRACE | RC_DEP_START);
free(r); free(r);
if (!l) if (!l)
return; return;
TAILQ_FOREACH(s, l, entries) { TAILQ_FOREACH(s, l, entries) {
if (!rc_stringlist_find(services, s->value)) if (!rc_stringlist_find(svcs, s->value))
continue; continue;
if (!runlevel || rc_service_in_runlevel(s->value, runlevel)) if (!runlevel || rc_service_in_runlevel(s->value, runlevel))
print_service(s->value); print_service(s->value);
@ -185,13 +191,12 @@ static const char * const longopts_help[] = {
}; };
#include "_usage.c" #include "_usage.c"
int rc_status(int argc, char **argv) int
rc_status(int argc, char **argv)
{ {
RC_STRINGLIST *levels = NULL;
RC_STRINGLIST *services = NULL;
RC_STRING *s, *l, *t; RC_STRING *s, *l, *t;
char *p; char *p, *runlevel = NULL;
int opt; int opt, aflag = 0;
test_crashed = _rc_can_find_pids(); test_crashed = _rc_can_find_pids();
@ -199,6 +204,7 @@ int rc_status(int argc, char **argv)
(int *) 0)) != -1) (int *) 0)) != -1)
switch (opt) { switch (opt) {
case 'a': case 'a':
aflag++;
levels = rc_runlevel_list(); levels = rc_runlevel_list();
break; break;
case 'l': case 'l':
@ -208,9 +214,8 @@ int rc_status(int argc, char **argv)
goto exit; goto exit;
/* NOTREACHED */ /* NOTREACHED */
case 'r': case 'r':
p = rc_runlevel_get(); runlevel = rc_runlevel_get();
printf("%s\n", p); printf("%s\n", runlevel);
free(p);
goto exit; goto exit;
/* NOTREACHED */ /* NOTREACHED */
case 's': case 's':
@ -242,9 +247,8 @@ int rc_status(int argc, char **argv)
while (optind < argc) while (optind < argc)
rc_stringlist_add(levels, argv[optind++]); rc_stringlist_add(levels, argv[optind++]);
if (!TAILQ_FIRST(levels)) { if (!TAILQ_FIRST(levels)) {
p = rc_runlevel_get(); runlevel = rc_runlevel_get();
rc_stringlist_add(levels, p); rc_stringlist_add(levels, runlevel);
free(p);
} }
/* Output the services in the order in which they would start */ /* Output the services in the order in which they would start */
@ -258,33 +262,78 @@ int rc_status(int argc, char **argv)
services = NULL; services = NULL;
} }
/* Show unassigned running too */ if (aflag || argc < 2) {
if (argc < 2 && /* Show hotplugged services */
(services = rc_services_in_runlevel(NULL))) print_level("hotplugged");
{ services = rc_services_in_state(RC_SERVICE_HOTPLUGGED);
print_level("UNASSIGNED"); print_services(NULL, nservices);
rc_stringlist_free(services);
services = NULL;
/* Show manually started and unassigned depended services */
if (aflag) {
rc_stringlist_free(levels); rc_stringlist_free(levels);
levels = rc_runlevel_list(); levels = rc_stringlist_new();
TAILQ_FOREACH_SAFE(s, services, entries, t) { if (!runlevel)
runlevel = rc_runlevel_get();
rc_stringlist_add(levels, runlevel);
}
rc_stringlist_add(levels, RC_LEVEL_SYSINIT);
rc_stringlist_add(levels, RC_LEVEL_BOOT);
services = rc_services_in_runlevel(NULL);
sservices = rc_stringlist_new();
TAILQ_FOREACH(l, levels, entries) { TAILQ_FOREACH(l, levels, entries) {
if (rc_service_in_runlevel(s->value, l->value) || nservices = rc_services_in_runlevel(l->value);
TAILQ_CONCAT(sservices, nservices, entries);
free(nservices);
}
TAILQ_FOREACH_SAFE(s, services, entries, t) {
if (rc_stringlist_find(sservices, s->value) ||
rc_service_state(s->value) & RC_SERVICE_STOPPED) rc_service_state(s->value) & RC_SERVICE_STOPPED)
{ {
TAILQ_REMOVE(services, s, entries); TAILQ_REMOVE(services, s, entries);
free(s->value); free(s->value);
free(s); free(s);
break;
} }
} }
needsme = rc_stringlist_new();
rc_stringlist_add(needsme, "needsme");
nservices = rc_stringlist_new();
alist = rc_stringlist_new();
l = rc_stringlist_add(alist, "");
p = l->value;
if (!runlevel)
runlevel = rc_runlevel_get();
TAILQ_FOREACH_SAFE(s, services, entries, t) {
l->value = s->value;
unsetenv("RC_SVCNAME");
setenv("RC_SVCNAME", l->value, 1);
tmp = rc_deptree_depends(deptree, needsme, alist, runlevel, RC_DEP_TRACE);
if (TAILQ_FIRST(tmp)) {
TAILQ_REMOVE(services, s, entries);
TAILQ_INSERT_TAIL(nservices, s, entries);
} }
rc_stringlist_free(tmp);
}
l->value = p;
print_level("needed");
print_services(NULL, nservices);
print_level("manual");
print_services(NULL, services); print_services(NULL, services);
} }
exit: exit:
free(runlevel);
#ifdef DEBUG_MEMORY
rc_stringlist_free(alist);
rc_stringlist_free(needsme);
rc_stringlist_free(sservices);
rc_stringlist_free(nservices);
rc_stringlist_free(services); rc_stringlist_free(services);
rc_stringlist_free(types); rc_stringlist_free(types);
rc_stringlist_free(levels); rc_stringlist_free(levels);
rc_deptree_free(deptree); rc_deptree_free(deptree);
#endif
return(EXIT_SUCCESS); return(EXIT_SUCCESS);
} }