Move crypt commands to a different listener in vold

In order to prevent this bug from happening, we must allow vold cryptfs
commands to complete while a long running mount is underway.

While waiting for vold to be changed to a binder interface, we will simply
create two listeners, one for cryptfs and one for everything else.

Bug: 19197175
Change-Id: If74142aa81abd58f718a9de6c9e387f6ea442754
diff --git a/main.cpp b/main.cpp
index fb8ffc4..290093f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -17,6 +17,7 @@
 #include "Disk.h"
 #include "VolumeManager.h"
 #include "CommandListener.h"
+#include "CryptCommandListener.h"
 #include "NetlinkManager.h"
 #include "cryptfs.h"
 #include "sehandle.h"
@@ -56,6 +57,7 @@
 
     VolumeManager *vm;
     CommandListener *cl;
+    CryptCommandListener *ccl;
     NetlinkManager *nm;
 
     parse_args(argc, argv);
@@ -67,6 +69,7 @@
 
     // Quickly throw a CLOEXEC on the socket we just inherited from init
     fcntl(android_get_control_socket("vold"), F_SETFD, FD_CLOEXEC);
+    fcntl(android_get_control_socket("cryptd"), F_SETFD, FD_CLOEXEC);
 
     mkdir("/dev/block/vold", 0755);
 
@@ -89,6 +92,7 @@
     }
 
     cl = new CommandListener();
+    ccl = new CryptCommandListener();
     vm->setBroadcaster((SocketListener *) cl);
     nm->setBroadcaster((SocketListener *) cl);
 
@@ -117,6 +121,11 @@
         exit(1);
     }
 
+    if (ccl->startListener()) {
+        PLOG(ERROR) << "Unable to start CryptCommandListener";
+        exit(1);
+    }
+
     // Eventually we'll become the monitoring thread
     while(1) {
         sleep(1000);