From 3beec7e55f1b5a840fc8fe0868b84d2238779af6 Mon Sep 17 00:00:00 2001 From: JP Abgrall Date: Fri, 2 May 2014 21:14:29 -0700 Subject: [PATCH] init: add 'enable ' to negate "service ... disabled" enable Turns a disabled service into an enabled one as if the service did not specify disabled in the rc file. It will also start the service if needed. Bug: 14472973 Change-Id: Id0b49cc687a2bc74f6f92e066c617724cc94908d Signed-off-by: JP Abgrall --- init/builtins.c | 17 +++++++++++++++++ init/init.c | 4 ++-- init/init.h | 1 + init/init_parser.c | 1 + init/keywords.h | 2 ++ init/readme.txt | 10 ++++++++++ 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/init/builtins.c b/init/builtins.c index e2932d5d9..d973a6b64 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -196,6 +196,8 @@ static void service_start_if_not_disabled(struct service *svc) { if (!(svc->flags & SVC_DISABLED)) { service_start(svc, NULL); + } else { + svc->flags |= SVC_DISABLED_START; } } @@ -238,6 +240,21 @@ int do_domainname(int nargs, char **args) return write_file("/proc/sys/kernel/domainname", args[1]); } +int do_enable(int nargs, char **args) +{ + struct service *svc; + svc = service_find_by_name(args[1]); + if (svc) { + svc->flags &= ~(SVC_DISABLED | SVC_RC_DISABLED); + if (svc->flags & SVC_DISABLED_START) { + service_start(svc, NULL); + } + } else { + return -1; + } + return 0; +} + int do_exec(int nargs, char **args) { return -1; diff --git a/init/init.c b/init/init.c index 08842363d..fc201982e 100644 --- a/init/init.c +++ b/init/init.c @@ -164,7 +164,7 @@ void service_start(struct service *svc, const char *dynamic_args) * state and immediately takes it out of the restarting * state if it was in there */ - svc->flags &= (~(SVC_DISABLED|SVC_RESTARTING|SVC_RESET|SVC_RESTART)); + svc->flags &= (~(SVC_DISABLED|SVC_RESTARTING|SVC_RESET|SVC_RESTART|SVC_DISABLED_START)); svc->time_started = 0; /* running processes require no additional work -- if @@ -364,7 +364,7 @@ static void service_stop_or_reset(struct service *svc, int how) { /* The service is still SVC_RUNNING until its process exits, but if it has * already exited it shoudn't attempt a restart yet. */ - svc->flags &= (~SVC_RESTARTING); + svc->flags &= ~(SVC_RESTARTING | SVC_DISABLED_START); if ((how != SVC_DISABLED) && (how != SVC_RESET) && (how != SVC_RESTART)) { /* Hrm, an illegal flag. Default to SVC_DISABLED */ diff --git a/init/init.h b/init/init.h index 736b75b1a..c2419123a 100644 --- a/init/init.h +++ b/init/init.h @@ -74,6 +74,7 @@ struct svcenvinfo { so it can be restarted with its class */ #define SVC_RC_DISABLED 0x80 /* Remember if the disabled flag was set in the rc script */ #define SVC_RESTART 0x100 /* Use to safely restart (stop, wait, start) a service */ +#define SVC_DISABLED_START 0x200 /* a start was requested but it was disabled at the time */ #define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */ diff --git a/init/init_parser.c b/init/init_parser.c index f49e6981d..02e5bdcca 100644 --- a/init/init_parser.c +++ b/init/init_parser.c @@ -98,6 +98,7 @@ static int lookup_keyword(const char *s) if (!strcmp(s, "omainname")) return K_domainname; break; case 'e': + if (!strcmp(s, "nable")) return K_enable; if (!strcmp(s, "xec")) return K_exec; if (!strcmp(s, "xport")) return K_export; break; diff --git a/init/keywords.h b/init/keywords.h index 97fe50cc8..6625330c1 100644 --- a/init/keywords.h +++ b/init/keywords.h @@ -6,6 +6,7 @@ int do_class_start(int nargs, char **args); int do_class_stop(int nargs, char **args); int do_class_reset(int nargs, char **args); int do_domainname(int nargs, char **args); +int do_enable(int nargs, char **args); int do_exec(int nargs, char **args); int do_export(int nargs, char **args); int do_hostname(int nargs, char **args); @@ -55,6 +56,7 @@ enum { KEYWORD(critical, OPTION, 0, 0) KEYWORD(disabled, OPTION, 0, 0) KEYWORD(domainname, COMMAND, 1, do_domainname) + KEYWORD(enable, COMMAND, 1, do_enable) KEYWORD(exec, COMMAND, 1, do_exec) KEYWORD(export, COMMAND, 2, do_export) KEYWORD(group, OPTION, 0, 0) diff --git a/init/readme.txt b/init/readme.txt index 42a09cb82..613a9e957 100644 --- a/init/readme.txt +++ b/init/readme.txt @@ -178,6 +178,16 @@ class_stop domainname Set the domain name. +enable + Turns a disabled service into an enabled one as if the service did not + specify disabled. + If the service is supposed to be running, it will be started now. + Typically used when the bootloader sets a variable that indicates a specific + service should be started when needed. E.g. + on property:ro.boot.myfancyhardware=1 + enable my_fancy_service_for_my_fancy_hardware + + insmod Install the module at