rc-status: add -m/--manual option to show manually started services

X-Gentoo-Bug: 585906
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=585906
This commit is contained in:
William Hubbs 2016-07-15 11:37:54 -05:00
parent c962678dd6
commit 695be59083
2 changed files with 27 additions and 2 deletions

View File

@ -33,6 +33,8 @@ Show all runlevels and their services.
List all services that have crashed. List all services that have crashed.
.It Fl l , -list .It Fl l , -list
List all defined runlevels. List all defined runlevels.
.It Fl m , -manual
Show all manually started services.
.It Fl r , -runlevel .It Fl r , -runlevel
Print the current runlevel name. Print the current runlevel name.
.It Fl s , -servicelist .It Fl s , -servicelist

View File

@ -29,11 +29,12 @@
const char *applet = NULL; const char *applet = NULL;
const char *extraopts = NULL; const char *extraopts = NULL;
const char *getoptstring = "aclrsu" getoptstring_COMMON; const char *getoptstring = "aclmrsu" getoptstring_COMMON;
const struct option longopts[] = { const struct option longopts[] = {
{"all", 0, NULL, 'a'}, {"all", 0, NULL, 'a'},
{"crashed", 0, NULL, 'c'}, {"crashed", 0, NULL, 'c'},
{"list", 0, NULL, 'l'}, {"list", 0, NULL, 'l'},
{"manual", 0, NULL, 'm'},
{"runlevel", 0, NULL, 'r'}, {"runlevel", 0, NULL, 'r'},
{"servicelist", 0, NULL, 's'}, {"servicelist", 0, NULL, 's'},
{"unused", 0, NULL, 'u'}, {"unused", 0, NULL, 'u'},
@ -43,6 +44,7 @@ const char * const longopts_help[] = {
"Show services from all run levels", "Show services from all run levels",
"Show crashed services", "Show crashed services",
"Show list of run levels", "Show list of run levels",
"Show manually started services",
"Show the name of the current runlevel", "Show the name of the current runlevel",
"Show service list", "Show service list",
"Show services not assigned to any runlevel", "Show services not assigned to any runlevel",
@ -50,7 +52,7 @@ const char * const longopts_help[] = {
}; };
const char *usagestring = "" \ const char *usagestring = "" \
"Usage: rc-status [options] <runlevel>...\n" \ "Usage: rc-status [options] <runlevel>...\n" \
" or: rc-status [options] [-a | -c | -l | -r | -s | -u]"; " or: rc-status [options] [-a | -c | -l | -m | -r | -s | -u]";
static bool test_crashed = false; static bool test_crashed = false;
static RC_DEPTREE *deptree; static RC_DEPTREE *deptree;
@ -205,6 +207,27 @@ int main(int argc, char **argv)
TAILQ_FOREACH(l, levels, entries) TAILQ_FOREACH(l, levels, entries)
printf("%s\n", l->value); printf("%s\n", l->value);
goto exit; goto exit;
case 'm':
services = rc_services_in_runlevel(NULL);
levels = rc_runlevel_list();
TAILQ_FOREACH_SAFE(s, services, entries, t) {
TAILQ_FOREACH(l, levels, entries)
if (rc_service_in_runlevel(s->value, l->value)) {
TAILQ_REMOVE(services, s, entries);
free(s->value);
free(s);
break;
}
}
TAILQ_FOREACH_SAFE(s, services, entries, t)
if (rc_service_state(s->value) &
(RC_SERVICE_STOPPED | RC_SERVICE_HOTPLUGGED)) {
TAILQ_REMOVE(services, s, entries);
free(s->value);
free(s);
}
print_services(NULL, services);
goto exit;
case 'r': case 'r':
runlevel = rc_runlevel_get(); runlevel = rc_runlevel_get();
printf("%s\n", runlevel); printf("%s\n", runlevel);