Destroy vold socket interface completely.
Long live Binder.
Test: yes
Bug: 13758960
Change-Id: If6be379b5a873f1b0c66dd1522b87413ad10fc46
diff --git a/vdc.cpp b/vdc.cpp
index 3a38641..b249987 100644
--- a/vdc.cpp
+++ b/vdc.cpp
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <poll.h>
-#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -36,23 +35,13 @@
#include <android-base/stringprintf.h>
#include <binder/IServiceManager.h>
-#include <cutils/sockets.h>
#include <private/android_filesystem_config.h>
-#define ENABLE_BINDER 1
-
static void usage(char *progname);
-#if !ENABLE_BINDER
-static int do_monitor(int sock, int stop_after_cmd);
-static int do_cmd(int sock, int argc, char **argv);
-#endif
-
-static constexpr int kCommandTimeoutMs = 20 * 1000;
-
int main(int argc, char **argv) {
int sock;
- int wait_for_socket;
+ int wait;
char *progname;
progname = argv[0];
@@ -64,8 +53,8 @@
android::base::InitLogging(argv, &android::base::StderrLogger);
}
- wait_for_socket = argc > 1 && strcmp(argv[1], "--wait") == 0;
- if (wait_for_socket) {
+ wait = argc > 1 && strcmp(argv[1], "--wait") == 0;
+ if (wait) {
argv++;
argc--;
}
@@ -75,7 +64,6 @@
exit(5);
}
-#if ENABLE_BINDER
std::string arg1 = argv[1];
std::string arg2 = argv[2];
@@ -102,119 +90,8 @@
LOG(ERROR) << "Raw commands are no longer supported";
exit(EINVAL);
}
-#else
- const char* sockname = "vold";
- if (!strcmp(argv[1], "cryptfs")) {
- sockname = "cryptd";
- }
-
- while ((sock = socket_local_client(sockname,
- ANDROID_SOCKET_NAMESPACE_RESERVED,
- SOCK_STREAM)) < 0) {
- if (!wait_for_socket) {
- PLOG(ERROR) << "Error connecting to " << sockname;
- exit(4);
- } else {
- usleep(10000);
- }
- }
-
- if (!strcmp(argv[1], "monitor")) {
- exit(do_monitor(sock, 0));
- } else {
- exit(do_cmd(sock, argc, argv));
- }
-#endif
}
-#if !ENABLE_BINDER
-static int do_cmd(int sock, int argc, char **argv) {
- int seq = getpid();
-
- std::string cmd(android::base::StringPrintf("%d ", seq));
- for (int i = 1; i < argc; i++) {
- if (!strchr(argv[i], ' ')) {
- cmd.append(argv[i]);
- } else {
- cmd.push_back('\"');
- cmd.append(argv[i]);
- cmd.push_back('\"');
- }
-
- if (i < argc - 1) {
- cmd.push_back(' ');
- }
- }
-
- if (TEMP_FAILURE_RETRY(write(sock, cmd.c_str(), cmd.length() + 1)) < 0) {
- PLOG(ERROR) << "Failed to write command";
- return errno;
- }
-
- return do_monitor(sock, seq);
-}
-
-static int do_monitor(int sock, int stop_after_seq) {
- char buffer[4096];
- int timeout = kCommandTimeoutMs;
-
- if (stop_after_seq == 0) {
- LOG(INFO) << "Connected to vold";
- timeout = -1;
- }
-
- while (1) {
- struct pollfd poll_sock = { sock, POLLIN, 0 };
- int rc = TEMP_FAILURE_RETRY(poll(&poll_sock, 1, timeout));
- if (rc == 0) {
- LOG(ERROR) << "Timeout waiting for " << stop_after_seq;
- return ETIMEDOUT;
- } else if (rc < 0) {
- PLOG(ERROR) << "Failed during poll";
- return errno;
- }
-
- if (!(poll_sock.revents & POLLIN)) {
- LOG(INFO) << "No data; trying again";
- continue;
- }
-
- memset(buffer, 0, sizeof(buffer));
- rc = TEMP_FAILURE_RETRY(read(sock, buffer, sizeof(buffer)));
- if (rc == 0) {
- LOG(ERROR) << "Lost connection, did vold crash?";
- return ECONNRESET;
- } else if (rc < 0) {
- PLOG(ERROR) << "Error reading data";
- return errno;
- }
-
- int offset = 0;
- for (int i = 0; i < rc; i++) {
- if (buffer[i] == '\0') {
- char* res = buffer + offset;
- fprintf(stdout, "%s\n", res);
-
- int code = atoi(strtok(res, " "));
- if (code >= 200 && code < 600) {
- int seq = atoi(strtok(nullptr, " "));
- if (seq == stop_after_seq) {
- if (code == 200) {
- return 0;
- } else {
- return code;
- }
- }
- }
-
- offset = i + 1;
- }
- }
- }
- return EIO;
-}
-#endif
-
static void usage(char *progname) {
LOG(INFO) << "Usage: " << progname << " [--wait] <monitor>|<cmd> [arg1] [arg2...]";
}