From 7b0f41c3933ab506552c22c4acffdbedca7d5663 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 26 Sep 2017 10:19:41 -0700 Subject: [PATCH] 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 --- reboot/reboot.c | 20 ++++++++++++-------- 1 file 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 @@ #include #include -int main(int argc, char *argv[]) -{ +int main(int argc, char* argv[]) { int ret; size_t prop_len; char property_val[PROPERTY_VALUE_MAX]; - const char *cmd = "reboot"; - char *optarg = ""; + static const char reboot[] = "reboot"; + const char* cmd = reboot; + char* optarg = ""; opterr = 0; do { @@ -60,19 +60,23 @@ int main(int argc, char *argv[]) prop_len = snprintf(property_val, sizeof(property_val), "%s,%s", cmd, optarg); if (prop_len >= sizeof(property_val)) { - fprintf(stderr, "reboot command too long: %s\n", optarg); + fprintf(stderr, "%s command too long: %s\n", cmd, optarg); exit(EXIT_FAILURE); } ret = property_set(ANDROID_RB_PROPERTY, property_val); - if(ret < 0) { - perror("reboot"); + if (ret < 0) { + perror(cmd); exit(EXIT_FAILURE); } // Don't return early. Give the reboot command time to take effect // to avoid messing up scripts which do "adb shell reboot && adb wait-for-device" - while(1) { pause(); } + if (cmd == reboot) { + while (1) { + pause(); + } + } fprintf(stderr, "Done\n"); return 0;