summaryrefslogtreecommitdiffstats
path: root/reboot
diff options
context:
space:
mode:
authorMark Salyzyn2017-09-26 12:19:41 -0500
committerMark Salyzyn2017-09-29 11:29:52 -0500
commit7b0f41c3933ab506552c22c4acffdbedca7d5663 (patch)
treee0818f665e5e3e42a628150b57a31ab00c250b71 /reboot
parent61578ab50be06745dfac57aa106aeb996e5326df (diff)
downloadplatform-system-core-7b0f41c3933ab506552c22c4acffdbedca7d5663.tar.gz
platform-system-core-7b0f41c3933ab506552c22c4acffdbedca7d5663.tar.xz
platform-system-core-7b0f41c3933ab506552c22c4acffdbedca7d5663.zip
reboot: only pause indefinitely for non-shutdown operations
If -p flag specified, return immediately so that scripting code can progress. Shutdown is unique in that if it does happen, the device will never come back, but if it fails one can continue diagnosis (without the need for a script to send a SIGINT to break out of the indefinite pause on the reboot -p command). Yes, this will break adb shell reboot -p ; adb wait-for-device as noted in the comment, but no one should ever expect the device to come back if a shutdown is requested. We do not break adb reboot ; adb wait-for-device sequence though as we retain the pause forever. Test: manual Bug: 63736262 Bug: 38446744 Bug: 66912053 Change-Id: I028cd873a7193a78c6b3c342eca1e08b6b296fd2
Diffstat (limited to 'reboot')
-rw-r--r--reboot/reboot.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/reboot/reboot.c b/reboot/reboot.c
index f0cf40c89..fe763a882 100644
--- a/reboot/reboot.c
+++ b/reboot/reboot.c
@@ -21,13 +21,13 @@
21#include <cutils/android_reboot.h> 21#include <cutils/android_reboot.h>
22#include <unistd.h> 22#include <unistd.h>
23 23
24int main(int argc, char *argv[]) 24int main(int argc, char* argv[]) {
25{
26 int ret; 25 int ret;
27 size_t prop_len; 26 size_t prop_len;
28 char property_val[PROPERTY_VALUE_MAX]; 27 char property_val[PROPERTY_VALUE_MAX];
29 const char *cmd = "reboot"; 28 static const char reboot[] = "reboot";
30 char *optarg = ""; 29 const char* cmd = reboot;
30 char* optarg = "";
31 31
32 opterr = 0; 32 opterr = 0;
33 do { 33 do {
@@ -60,19 +60,23 @@ int main(int argc, char *argv[])
60 60
61 prop_len = snprintf(property_val, sizeof(property_val), "%s,%s", cmd, optarg); 61 prop_len = snprintf(property_val, sizeof(property_val), "%s,%s", cmd, optarg);
62 if (prop_len >= sizeof(property_val)) { 62 if (prop_len >= sizeof(property_val)) {
63 fprintf(stderr, "reboot command too long: %s\n", optarg); 63 fprintf(stderr, "%s command too long: %s\n", cmd, optarg);
64 exit(EXIT_FAILURE); 64 exit(EXIT_FAILURE);
65 } 65 }
66 66
67 ret = property_set(ANDROID_RB_PROPERTY, property_val); 67 ret = property_set(ANDROID_RB_PROPERTY, property_val);
68 if(ret < 0) { 68 if (ret < 0) {
69 perror("reboot"); 69 perror(cmd);
70 exit(EXIT_FAILURE); 70 exit(EXIT_FAILURE);
71 } 71 }
72 72
73 // Don't return early. Give the reboot command time to take effect 73 // Don't return early. Give the reboot command time to take effect
74 // to avoid messing up scripts which do "adb shell reboot && adb wait-for-device" 74 // to avoid messing up scripts which do "adb shell reboot && adb wait-for-device"
75 while(1) { pause(); } 75 if (cmd == reboot) {
76 while (1) {
77 pause();
78 }
79 }
76 80
77 fprintf(stderr, "Done\n"); 81 fprintf(stderr, "Done\n");
78 return 0; 82 return 0;