summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
Diffstat (limited to 'init')
-rw-r--r--init/builtins.c38
-rw-r--r--init/init_parser.c2
-rw-r--r--init/keywords.h2
-rw-r--r--[-rwxr-xr-x]init/property_service.c1
4 files changed, 43 insertions, 0 deletions
diff --git a/init/builtins.c b/init/builtins.c
index 275a1af..06180a1 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -32,6 +32,7 @@
#include <sys/wait.h>
#include <linux/loop.h>
#include <cutils/partition_utils.h>
+#include <cutils/android_reboot.h>
#include <sys/system_properties.h>
#include <fs_mgr.h>
@@ -605,6 +606,43 @@ int do_restart(int nargs, char **args)
return 0;
}
+int do_powerctl(int nargs, char **args)
+{
+ char command[PROP_VALUE_MAX];
+ int res;
+ int len = 0;
+ int cmd = 0;
+ char *reboot_target;
+
+ res = expand_props(command, args[1], sizeof(command));
+ if (res) {
+ ERROR("powerctl: cannot expand '%s'\n", args[1]);
+ return -EINVAL;
+ }
+
+ if (strncmp(command, "shutdown", 8) == 0) {
+ cmd = ANDROID_RB_POWEROFF;
+ len = 8;
+ } else if (strncmp(command, "reboot", 6) == 0) {
+ cmd = ANDROID_RB_RESTART2;
+ len = 6;
+ } else {
+ ERROR("powerctl: unrecognized command '%s'\n", command);
+ return -EINVAL;
+ }
+
+ if (command[len] == ',') {
+ reboot_target = &command[len + 1];
+ } else if (command[len] == '\0') {
+ reboot_target = "";
+ } else {
+ ERROR("powerctl: unrecognized reboot target '%s'\n", &command[len]);
+ return -EINVAL;
+ }
+
+ return android_reboot(cmd, 0, reboot_target);
+}
+
int do_trigger(int nargs, char **args)
{
action_for_each_trigger(args[1], action_add_queue_tail);
diff --git a/init/init_parser.c b/init/init_parser.c
index 5182a29..a79d3a1 100644
--- a/init/init_parser.c
+++ b/init/init_parser.c
@@ -130,6 +130,8 @@ int lookup_keyword(const char *s)
if (!strcmp(s, "neshot")) return K_oneshot;
if (!strcmp(s, "nrestart")) return K_onrestart;
break;
+ case 'p':
+ if (!strcmp(s, "owerctl")) return K_powerctl;
case 'r':
if (!strcmp(s, "estart")) return K_restart;
if (!strcmp(s, "estorecon")) return K_restorecon;
diff --git a/init/keywords.h b/init/keywords.h
index 55d6af3..275c64d 100644
--- a/init/keywords.h
+++ b/init/keywords.h
@@ -14,6 +14,7 @@ int do_insmod(int nargs, char **args);
int do_mkdir(int nargs, char **args);
int do_mount_all(int nargs, char **args);
int do_mount(int nargs, char **args);
+int do_powerctl(int nargs, char **args);
int do_restart(int nargs, char **args);
int do_restorecon(int nargs, char **args);
int do_rm(int nargs, char **args);
@@ -67,6 +68,7 @@ enum {
KEYWORD(on, SECTION, 0, 0)
KEYWORD(oneshot, OPTION, 0, 0)
KEYWORD(onrestart, OPTION, 0, 0)
+ KEYWORD(powerctl, COMMAND, 1, do_powerctl)
KEYWORD(restart, COMMAND, 1, do_restart)
KEYWORD(restorecon, COMMAND, 1, do_restorecon)
KEYWORD(rm, COMMAND, 1, do_rm)
diff --git a/init/property_service.c b/init/property_service.c
index e8c8869..5387422 100755..100644
--- a/init/property_service.c
+++ b/init/property_service.c
@@ -77,6 +77,7 @@ struct {
{ "runtime.", AID_SYSTEM, 0 },
{ "hw.", AID_SYSTEM, 0 },
{ "sys.", AID_SYSTEM, 0 },
+ { "sys.powerctl", AID_SHELL, 0 },
{ "service.", AID_SYSTEM, 0 },
{ "wlan.", AID_SYSTEM, 0 },
{ "bluetooth.", AID_BLUETOOTH, 0 },