Merge "minadbd: avoid overrriding services_to_fd."
am: 6f1f2c811a
Change-Id: Idd6afe20fe9341ee5ff79e6aaf2277490a027e21
This commit is contained in:
@@ -21,15 +21,18 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "adb.h"
|
#include "adb.h"
|
||||||
|
#include "adb_unique_fd.h"
|
||||||
#include "fdevent.h"
|
#include "fdevent.h"
|
||||||
#include "fuse_adb_provider.h"
|
#include "fuse_adb_provider.h"
|
||||||
|
#include "services.h"
|
||||||
#include "sysdeps.h"
|
#include "sysdeps.h"
|
||||||
|
|
||||||
static void sideload_host_service(int sfd, const std::string& args) {
|
static void sideload_host_service(unique_fd sfd, const std::string& args) {
|
||||||
int file_size;
|
int file_size;
|
||||||
int block_size;
|
int block_size;
|
||||||
if (sscanf(args.c_str(), "%d:%d", &file_size, &block_size) != 2) {
|
if (sscanf(args.c_str(), "%d:%d", &file_size, &block_size) != 2) {
|
||||||
@@ -45,22 +48,7 @@ static void sideload_host_service(int sfd, const std::string& args) {
|
|||||||
exit(result == 0 ? 0 : 1);
|
exit(result == 0 ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create_service_thread(void (*func)(int, const std::string&), const std::string& args) {
|
unique_fd daemon_service_to_fd(const char* name, atransport* /* transport */) {
|
||||||
int s[2];
|
|
||||||
if (adb_socketpair(s)) {
|
|
||||||
printf("cannot create service socket pair\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::thread([s, func, args]() { func(s[1], args); }).detach();
|
|
||||||
|
|
||||||
VLOG(SERVICES) << "service thread started, " << s[0] << ":" << s[1];
|
|
||||||
return s[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
int service_to_fd(const char* name, atransport* /* transport */) {
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!strncmp(name, "sideload:", 9)) {
|
if (!strncmp(name, "sideload:", 9)) {
|
||||||
// this exit status causes recovery to print a special error
|
// this exit status causes recovery to print a special error
|
||||||
// message saying to use a newer adb (that supports
|
// message saying to use a newer adb (that supports
|
||||||
@@ -68,10 +56,8 @@ int service_to_fd(const char* name, atransport* /* transport */) {
|
|||||||
exit(3);
|
exit(3);
|
||||||
} else if (!strncmp(name, "sideload-host:", 14)) {
|
} else if (!strncmp(name, "sideload-host:", 14)) {
|
||||||
std::string arg(name + 14);
|
std::string arg(name + 14);
|
||||||
ret = create_service_thread(sideload_host_service, arg);
|
return create_service_thread("sideload-host",
|
||||||
|
std::bind(sideload_host_service, std::placeholders::_1, arg));
|
||||||
}
|
}
|
||||||
if (ret >= 0) {
|
return unique_fd{};
|
||||||
close_on_exec(ret);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user