summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao2018-08-01 18:00:05 -0500
committerJosh Gao2018-08-02 14:52:26 -0500
commit6fb946110312a47ea2b0f639d8b3e135a7481dca (patch)
tree26e4c251f27881ba4369b5cf22e97af26179f487
parentddcee93c0138fc68dbc6320962a53cd4761ab94b (diff)
downloadplatform-system-core-6fb946110312a47ea2b0f639d8b3e135a7481dca.tar.gz
platform-system-core-6fb946110312a47ea2b0f639d8b3e135a7481dca.tar.xz
platform-system-core-6fb946110312a47ea2b0f639d8b3e135a7481dca.zip
adbd: when rebooting, don't close socket before pausing.
An accidental side-effect of the change to unique_fd was that we started closing the reboot service socket before pausing and waiting for our death. This results in the client immediately returning, which means they might get a chance to run other commands before we actually manage to reboot. Bug: http://b/112104037 Test: adb reboot; adb devices Change-Id: Id61321da0c08ebd1ab57f1ce926bafd9109dd9c2
-rw-r--r--adb/daemon/services.cpp15
1 files changed, 4 insertions, 11 deletions
diff --git a/adb/daemon/services.cpp b/adb/daemon/services.cpp
index 1f59d6446..dfcc52d95 100644
--- a/adb/daemon/services.cpp
+++ b/adb/daemon/services.cpp
@@ -94,7 +94,7 @@ void restart_usb_service(unique_fd fd) {
94 WriteFdExactly(fd.get(), "restarting in USB mode\n"); 94 WriteFdExactly(fd.get(), "restarting in USB mode\n");
95} 95}
96 96
97bool reboot_service_impl(unique_fd fd, const std::string& arg) { 97void reboot_service(unique_fd fd, const std::string& arg) {
98 std::string reboot_arg = arg; 98 std::string reboot_arg = arg;
99 bool auto_reboot = false; 99 bool auto_reboot = false;
100 100
@@ -108,7 +108,7 @@ bool reboot_service_impl(unique_fd fd, const std::string& arg) {
108 if (reboot_arg == "sideload") { 108 if (reboot_arg == "sideload") {
109 if (getuid() != 0) { 109 if (getuid() != 0) {
110 WriteFdExactly(fd.get(), "'adb root' is required for 'adb reboot sideload'.\n"); 110 WriteFdExactly(fd.get(), "'adb root' is required for 'adb reboot sideload'.\n");
111 return false; 111 return;
112 } 112 }
113 113
114 const std::vector<std::string> options = {auto_reboot ? "--sideload_auto_reboot" 114 const std::vector<std::string> options = {auto_reboot ? "--sideload_auto_reboot"
@@ -116,7 +116,7 @@ bool reboot_service_impl(unique_fd fd, const std::string& arg) {
116 std::string err; 116 std::string err;
117 if (!write_bootloader_message(options, &err)) { 117 if (!write_bootloader_message(options, &err)) {
118 D("Failed to set bootloader message: %s", err.c_str()); 118 D("Failed to set bootloader message: %s", err.c_str());
119 return false; 119 return;
120 } 120 }
121 121
122 reboot_arg = "recovery"; 122 reboot_arg = "recovery";
@@ -128,16 +128,9 @@ bool reboot_service_impl(unique_fd fd, const std::string& arg) {
128 std::string reboot_string = android::base::StringPrintf("reboot,%s", reboot_arg.c_str()); 128 std::string reboot_string = android::base::StringPrintf("reboot,%s", reboot_arg.c_str());
129 if (!android::base::SetProperty(ANDROID_RB_PROPERTY, reboot_string)) { 129 if (!android::base::SetProperty(ANDROID_RB_PROPERTY, reboot_string)) {
130 WriteFdFmt(fd.get(), "reboot (%s) failed\n", reboot_string.c_str()); 130 WriteFdFmt(fd.get(), "reboot (%s) failed\n", reboot_string.c_str());
131 return false;
132 }
133
134 return true;
135}
136
137void reboot_service(unique_fd fd, const std::string& arg) {
138 if (!reboot_service_impl(std::move(fd), arg)) {
139 return; 131 return;
140 } 132 }
133
141 // Don't return early. Give the reboot command time to take effect 134 // Don't return early. Give the reboot command time to take effect
142 // to avoid messing up scripts which do "adb reboot && adb wait-for-device" 135 // to avoid messing up scripts which do "adb reboot && adb wait-for-device"
143 while (true) { 136 while (true) {