summaryrefslogtreecommitdiff
path: root/adb/services.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-10-30 18:37:26 -0700
committerYabin Cui <yabinc@google.com>2015-11-02 10:39:09 -0800
commitfbfa84045d30a8288c3feab9d7ce7c0c20d7728b (patch)
treed7b61e8c3b85071a1b22558dcad88a89595d2373 /adb/services.cpp
parent1e2382a0277eb36fb57a3a54202945556dfd234b (diff)
adb: run reverse_service() in main thread.
reverse_service() calls handle_forward_request(), which calls functions in fdevent.cpp. fdevent functions is only supposed to be called in the main thread. Add check in fdevent.cpp to make sure all operations come from main thread. Bug: 25355808 Change-Id: Iceb9273f3056acc0713eaafe086ac950ca80ff4f
Diffstat (limited to 'adb/services.cpp')
-rw-r--r--adb/services.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/adb/services.cpp b/adb/services.cpp
index e24b4705e9..19a6726f8c 100644
--- a/adb/services.cpp
+++ b/adb/services.cpp
@@ -184,15 +184,18 @@ void reboot_service(int fd, void* arg)
adb_close(fd);
}
-void reverse_service(int fd, void* arg)
-{
- const char* command = reinterpret_cast<const char*>(arg);
-
- if (handle_forward_request(command, kTransportAny, NULL, fd) < 0) {
- SendFail(fd, "not a reverse forwarding command");
+int reverse_service(const char* command) {
+ int s[2];
+ if (adb_socketpair(s)) {
+ PLOG(ERROR) << "cannot create service socket pair.";
+ return -1;
}
- free(arg);
- adb_close(fd);
+ VLOG(SERVICES) << "service socketpair: " << s[0] << ", " << s[1];
+ if (handle_forward_request(command, kTransportAny, nullptr, s[1]) < 0) {
+ SendFail(s[1], "not a reverse forwarding command");
+ }
+ adb_close(s[1]);
+ return s[0];
}
// Shell service string can look like:
@@ -335,15 +338,7 @@ int service_to_fd(const char* name, const atransport* transport) {
} else if(!strncmp(name, "usb:", 4)) {
ret = create_service_thread(restart_usb_service, NULL);
} else if (!strncmp(name, "reverse:", 8)) {
- char* cookie = strdup(name + 8);
- if (cookie == NULL) {
- ret = -1;
- } else {
- ret = create_service_thread(reverse_service, cookie);
- if (ret < 0) {
- free(cookie);
- }
- }
+ ret = reverse_service(name + 8);
} else if(!strncmp(name, "disable-verity:", 15)) {
ret = create_service_thread(set_verity_enabled_state_service, (void*)0);
} else if(!strncmp(name, "enable-verity:", 15)) {