diff options
Diffstat (limited to 'vold/vold.c')
-rw-r--r-- | vold/vold.c | 76 |
1 files changed, 30 insertions, 46 deletions
diff --git a/vold/vold.c b/vold/vold.c index b2c8eb2..7d50a2f 100644 --- a/vold/vold.c +++ b/vold/vold.c @@ -27,7 +27,6 @@ #include <sys/select.h> #include <sys/time.h> #include <sys/types.h> -#include <sys/inotify.h> #include <sys/un.h> #include <cutils/config_utils.h> @@ -57,12 +56,11 @@ static int fw_sock = -1; int main(int argc, char **argv) { int door_sock = -1; - int inotify_sock = -1; int uevent_sock = -1; struct sockaddr_nl nladdr; int uevent_sz = 64 * 1024; - LOG_VOL("Android Volume Daemon version %d.%d\n", ver_major, ver_minor); + LOGI("Android Volume Daemon version %d.%d", ver_major, ver_minor); /* * Create all the various sockets we'll need @@ -70,29 +68,18 @@ int main(int argc, char **argv) // Socket to listen on for incomming framework connections if ((door_sock = android_get_control_socket(VOLD_SOCKET)) < 0) { - LOGE("Obtaining file descriptor socket '%s' failed: %s\n", + LOGE("Obtaining file descriptor socket '%s' failed: %s", VOLD_SOCKET, strerror(errno)); exit(1); } if (listen(door_sock, 4) < 0) { - LOGE("Unable to listen on fd '%d' for socket '%s': %s\n", + LOGE("Unable to listen on fd '%d' for socket '%s': %s", door_sock, VOLD_SOCKET, strerror(errno)); exit(1); } - // Socket to listen on for changes to /dev/block - if ((inotify_sock = inotify_init()) < 0) { - LOGE("Unable to initialize inotify interface (%s)\n", strerror(errno)); - exit(1); - } - - fcntl(inotify_sock, F_SETFL, O_NONBLOCK | fcntl(inotify_sock, F_GETFL)); - - if (inotify_add_watch(inotify_sock, DEVPATH, IN_CREATE | IN_DELETE) < 0) { - LOGE("Unable to add inotify watch (%s)\n", strerror(errno)); - exit(1); - } + mkdir("/dev/block/vold", 0755); // Socket to listen on for uevent changes memset(&nladdr, 0, sizeof(nladdr)); @@ -102,18 +89,18 @@ int main(int argc, char **argv) if ((uevent_sock = socket(PF_NETLINK, SOCK_DGRAM,NETLINK_KOBJECT_UEVENT)) < 0) { - LOGE("Unable to create uevent socket: %s\n", strerror(errno)); + LOGE("Unable to create uevent socket: %s", strerror(errno)); exit(1); } if (setsockopt(uevent_sock, SOL_SOCKET, SO_RCVBUFFORCE, &uevent_sz, sizeof(uevent_sz)) < 0) { - LOGE("Unable to set uevent socket options: %s\n", strerror(errno)); + LOGE("Unable to set uevent socket options: %s", strerror(errno)); exit(1); } if (bind(uevent_sock, (struct sockaddr *) &nladdr, sizeof(nladdr)) < 0) { - LOGE("Unable to bind uevent socket: %s\n", strerror(errno)); + LOGE("Unable to bind uevent socket: %s", strerror(errno)); exit(1); } @@ -121,22 +108,22 @@ int main(int argc, char **argv) * Bootstrap */ + // Volume Manager + volmgr_bootstrap(); + // SD Card system mmc_bootstrap(); // USB Mass Storage ums_bootstrap(); - // Volume Manager - volmgr_bootstrap(); - - // Block device system - inotify_bootstrap(); + // Switch + switch_bootstrap(); /* * Main loop */ - + LOG_VOL("Bootstrapping complete"); while(1) { fd_set read_fds; struct timeval to; @@ -146,12 +133,10 @@ int main(int argc, char **argv) to.tv_sec = (60 * 60); to.tv_usec = 0; + FD_ZERO(&read_fds); FD_SET(door_sock, &read_fds); if (door_sock > max) max = door_sock; - FD_SET(inotify_sock, &read_fds); - if (inotify_sock > max) - max = inotify_sock; FD_SET(uevent_sock, &read_fds); if (uevent_sock > max) max = uevent_sock; @@ -163,7 +148,7 @@ int main(int argc, char **argv) } if ((rc = select(max + 1, &read_fds, NULL, NULL, &to)) < 0) { - LOGE("select() failed (%s)\n", strerror(errno)); + LOGE("select() failed (%s)", strerror(errno)); sleep(1); continue; } @@ -178,42 +163,41 @@ int main(int argc, char **argv) alen = sizeof(addr); + if (fw_sock != -1) { + LOGE("Dropping duplicate framework connection"); + int tmp = accept(door_sock, &addr, &alen); + close(tmp); + continue; + } + if ((fw_sock = accept(door_sock, &addr, &alen)) < 0) { - LOGE("Unable to accept framework connection (%s)\n", + LOGE("Unable to accept framework connection (%s)", strerror(errno)); } - LOG_VOL("Accepted connection from framework\n"); + LOG_VOL("Accepted connection from framework"); if ((rc = volmgr_send_states()) < 0) { - LOGE("Unable to send volmgr status to framework (%d)\n", rc); + LOGE("Unable to send volmgr status to framework (%d)", rc); } } if (FD_ISSET(fw_sock, &read_fds)) { if ((rc = process_framework_command(fw_sock)) < 0) { if (rc == -ECONNRESET) { - LOGE("Framework disconnected\n"); + LOGE("Framework disconnected"); close(fw_sock); fw_sock = -1; } else { - LOGE("Error processing framework command (%s)\n", + LOGE("Error processing framework command (%s)", strerror(errno)); } } } - if (FD_ISSET(inotify_sock, &read_fds)) { - if ((rc = process_inotify_event(inotify_sock)) < 0) { - LOGE("Error processing inotify msg (%s)\n", strerror(errno)); - } - } - if (FD_ISSET(uevent_sock, &read_fds)) { if ((rc = process_uevent_message(uevent_sock)) < 0) { - LOGE("Error processing uevent msg (%s)\n", strerror(errno)); + LOGE("Error processing uevent msg (%s)", strerror(errno)); } } - - } // while } @@ -224,7 +208,7 @@ int send_msg(char* message) pthread_mutex_lock(&write_mutex); - LOG_VOL("send_msg(%s):\n", message); +// LOG_VOL("send_msg(%s):", message); if (fw_sock >= 0) result = write(fw_sock, message, strlen(message) + 1); @@ -240,7 +224,7 @@ int send_msg_with_data(char *message, char *data) char* buffer = (char *)alloca(strlen(message) + strlen(data) + 1); if (!buffer) { - LOGE("alloca failed in send_msg_with_data\n"); + LOGE("alloca failed in send_msg_with_data"); return -1; } |