summaryrefslogtreecommitdiffstats
path: root/reboot
diff options
context:
space:
mode:
authorNick Kralevich2013-04-18 14:20:02 -0500
committerNick Kralevich2013-04-23 15:21:40 -0500
commitca8e66a8b0f843812014a28d49208f9f6f64ecbc (patch)
tree677652e5cbeb630b3fe66c1c41aa94160b6a13dd /reboot
parentba4ac0cc3aa69075d6cbcee4eddb314ef753aa8d (diff)
downloadplatform-system-core-ca8e66a8b0f843812014a28d49208f9f6f64ecbc.tar.gz
platform-system-core-ca8e66a8b0f843812014a28d49208f9f6f64ecbc.tar.xz
platform-system-core-ca8e66a8b0f843812014a28d49208f9f6f64ecbc.zip
Make init handle reboots
Move the responsibility for rebooting the system from the reboot command to init. Init is in a better position to take actions to bring the system down cleanly, including making sure filesystems are mounted read-only. The only UIDs which can perform an init triggered reboot are root, system, and shell. Modify the reboot command so that it calls into init to perform the reboot. The reboot command no longer requires CAP_SYS_BOOT. Remove the -n reboot option and code which supports it. Anyone needing to do an unclean shutdown can just do a 'echo c > /proc/sysrq-trigger'. Modify adb so that it calls into init to perform a shutdown. Bug: 8646621 Change-Id: I84c0513acb549720cb0e8c9fcbda0050f5c396f5
Diffstat (limited to 'reboot')
-rw-r--r--reboot/reboot.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/reboot/reboot.c b/reboot/reboot.c
index 45d8a8ef5..0e5170d42 100644
--- a/reboot/reboot.c
+++ b/reboot/reboot.c
@@ -17,35 +17,34 @@
17#include <errno.h> 17#include <errno.h>
18#include <stdio.h> 18#include <stdio.h>
19#include <stdlib.h> 19#include <stdlib.h>
20#include <cutils/properties.h>
20#include <cutils/android_reboot.h> 21#include <cutils/android_reboot.h>
21#include <unistd.h> 22#include <unistd.h>
22 23
23int main(int argc, char *argv[]) 24int main(int argc, char *argv[])
24{ 25{
25 int ret; 26 int ret;
26 int nosync = 0; 27 size_t prop_len;
27 int poweroff = 0; 28 char property_val[PROPERTY_VALUE_MAX];
28 int flags = 0; 29 const char *cmd = "reboot";
30 char *optarg = "";
29 31
30 opterr = 0; 32 opterr = 0;
31 do { 33 do {
32 int c; 34 int c;
33 35
34 c = getopt(argc, argv, "np"); 36 c = getopt(argc, argv, "p");
35 37
36 if (c == EOF) { 38 if (c == EOF) {
37 break; 39 break;
38 } 40 }
39 41
40 switch (c) { 42 switch (c) {
41 case 'n':
42 nosync = 1;
43 break;
44 case 'p': 43 case 'p':
45 poweroff = 1; 44 cmd = "shutdown";
46 break; 45 break;
47 case '?': 46 case '?':
48 fprintf(stderr, "usage: %s [-n] [-p] [rebootcommand]\n", argv[0]); 47 fprintf(stderr, "usage: %s [-p] [rebootcommand]\n", argv[0]);
49 exit(EXIT_FAILURE); 48 exit(EXIT_FAILURE);
50 } 49 }
51 } while (1); 50 } while (1);
@@ -55,20 +54,20 @@ int main(int argc, char *argv[])
55 exit(EXIT_FAILURE); 54 exit(EXIT_FAILURE);
56 } 55 }
57 56
58 if(nosync) 57 if (argc > optind)
59 /* also set NO_REMOUNT_RO as remount ro includes an implicit sync */ 58 optarg = argv[optind];
60 flags = ANDROID_RB_FLAG_NO_SYNC | ANDROID_RB_FLAG_NO_REMOUNT_RO; 59
60 prop_len = snprintf(property_val, sizeof(property_val), "%s,%s", cmd, optarg);
61 if (prop_len >= sizeof(property_val)) {
62 fprintf(stderr, "reboot command too long: %s\n", optarg);
63 exit(EXIT_FAILURE);
64 }
61 65
62 if(poweroff) 66 ret = property_set(ANDROID_RB_PROPERTY, property_val);
63 ret = android_reboot(ANDROID_RB_POWEROFF, flags, 0);
64 else if(argc > optind)
65 ret = android_reboot(ANDROID_RB_RESTART2, flags, argv[optind]);
66 else
67 ret = android_reboot(ANDROID_RB_RESTART, flags, 0);
68 if(ret < 0) { 67 if(ret < 0) {
69 perror("reboot"); 68 perror("reboot");
70 exit(EXIT_FAILURE); 69 exit(EXIT_FAILURE);
71 } 70 }
72 fprintf(stderr, "reboot returned\n"); 71 fprintf(stderr, "Done\n");
73 return 0; 72 return 0;
74} 73}