Replace custom logwrapper implementation with liblogwrap

Use liblogwrap to provide logwrapper functionality instead of
using vold's own implementation.

Change-Id: I76aac5aa72a1fdca043a63b86c6a9b54e7abec16
diff --git a/Ext4.cpp b/Ext4.cpp
index c99d801..1466922 100644
--- a/Ext4.cpp
+++ b/Ext4.cpp
@@ -29,6 +29,7 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/mount.h>
+#include <sys/wait.h>
 
 #include <linux/kdev_t.h>
 #include <linux/fs.h>
@@ -38,14 +39,13 @@
 #include <cutils/log.h>
 #include <cutils/properties.h>
 
+#include <logwrap/logwrap.h>
+
 #include "Ext4.h"
 #include "VoldUtil.h"
 
 #define MKEXT4FS_PATH "/system/bin/make_ext4fs";
 
-extern "C" int logwrap(int argc, const char **argv, int background);
-
-
 int Ext4::doMount(const char *fsPath, const char *mountPoint, bool ro, bool remount,
         bool executable) {
     int rc;
@@ -72,19 +72,34 @@
     int fd;
     const char *args[5];
     int rc;
+    int status;
 
     args[0] = MKEXT4FS_PATH;
     args[1] = "-J";
     args[2] = "-a";
     args[3] = mountpoint;
     args[4] = fsPath;
-    rc = logwrap(ARRAY_SIZE(args), args, 1);
+    rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status, false,
+            true);
+    if (rc != 0) {
+        SLOGE("Filesystem (ext4) format failed due to logwrap error");
+        errno = EIO;
+        return -1;
+    }
 
-    if (rc == 0) {
+    if (!WIFEXITED(status)) {
+        SLOGE("Filesystem (ext4) format did not exit properly");
+        errno = EIO;
+        return -1;
+    }
+
+    status = WEXITSTATUS(status);
+
+    if (status == 0) {
         SLOGI("Filesystem (ext4) formatted OK");
         return 0;
     } else {
-        SLOGE("Format (ext4) failed (unknown exit code %d)", rc);
+        SLOGE("Format (ext4) failed (unknown exit code %d)", status);
         errno = EIO;
         return -1;
     }