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/Fat.cpp b/Fat.cpp
index b43f089..ac473da 100644
--- a/Fat.cpp
+++ b/Fat.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,12 +39,13 @@
#include <cutils/log.h>
#include <cutils/properties.h>
+#include <logwrap/logwrap.h>
+
#include "Fat.h"
#include "VoldUtil.h"
static char FSCK_MSDOS_PATH[] = "/system/bin/fsck_msdos";
static char MKDOSFS_PATH[] = "/system/bin/newfs_msdos";
-extern "C" int logwrap(int argc, const char **argv, int background);
extern "C" int mount(const char *, const char *, const char *, unsigned long, const void *);
int Fat::check(const char *fsPath) {
@@ -57,14 +59,29 @@
int rc = 0;
do {
const char *args[4];
+ int status;
args[0] = FSCK_MSDOS_PATH;
args[1] = "-p";
args[2] = "-f";
args[3] = 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 check failed due to logwrap error");
+ errno = EIO;
+ return -1;
+ }
- switch(rc) {
+ if (!WIFEXITED(status)) {
+ SLOGE("Filesystem check did not exit properly");
+ errno = EIO;
+ return -1;
+ }
+
+ status = WEXITSTATUS(status);
+
+ switch(status) {
case 0:
SLOGI("Filesystem check completed OK");
return 0;
@@ -85,7 +102,7 @@
return -1;
default:
- SLOGE("Filesystem check failed (unknown exit code %d)", rc);
+ SLOGE("Filesystem check failed (unknown exit code %d)", status);
errno = EIO;
return -1;
}
@@ -155,6 +172,7 @@
int fd;
const char *args[10];
int rc;
+ int status;
args[0] = MKDOSFS_PATH;
args[1] = "-F";
@@ -171,17 +189,33 @@
args[7] = "-s";
args[8] = size;
args[9] = fsPath;
- rc = logwrap(ARRAY_SIZE(args), args, 1);
+ rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status,
+ false, true);
} else {
args[7] = fsPath;
- rc = logwrap(8, args, 1);
+ rc = android_fork_execvp(8, (char **)args, &status, false,
+ true);
}
- if (rc == 0) {
+ if (rc != 0) {
+ SLOGE("Filesystem format failed due to logwrap error");
+ errno = EIO;
+ return -1;
+ }
+
+ if (!WIFEXITED(status)) {
+ SLOGE("Filesystem format did not exit properly");
+ errno = EIO;
+ return -1;
+ }
+
+ status = WEXITSTATUS(status);
+
+ if (status == 0) {
SLOGI("Filesystem formatted OK");
return 0;
} else {
- SLOGE("Format failed (unknown exit code %d)", rc);
+ SLOGE("Format failed (unknown exit code %d)", status);
errno = EIO;
return -1;
}