From 6ac5322a33f46db7b1319eac706dbc04ff3e1e0f Mon Sep 17 00:00:00 2001 From: Ben Fennema Date: Thu, 22 Jun 2017 15:00:55 -0700 Subject: [PATCH] fs_mgr: properly propagate exec child errors Child status was being requested, but ignored, so if the exec failed with something like file not found or permissions denied the return value with be 0 (success). Passing in NULL instead of &status causes the failure to be properly returned from execvp instead of in status. Test: erase f2fs userdata on device without /system/bin/make_f2fs and verify device boots into recovery to format the partition instead of believing the format succeeded and going into infinite f2fs.fsck loop. Bug: 62901965 Signed-off-by: Ben Fennema Change-Id: Ia5bbf09d5a666402cba8437abcc56775583ba6d2 --- fs_mgr/fs_mgr_format.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs_mgr/fs_mgr_format.cpp b/fs_mgr/fs_mgr_format.cpp index 75feee798..fc88217ce 100644 --- a/fs_mgr/fs_mgr_format.cpp +++ b/fs_mgr/fs_mgr_format.cpp @@ -38,7 +38,6 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer) { uint64_t dev_sz; int fd, rc = 0; - int status; if ((fd = open(fs_blkdev, O_WRONLY)) < 0) { PERROR << "Cannot open block device"; @@ -62,7 +61,7 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer) const char* const mke2fs_args[] = { "/system/bin/mke2fs", "-t", "ext4", "-b", "4096", fs_blkdev, size_str.c_str(), nullptr}; - rc = android_fork_execvp_ext(arraysize(mke2fs_args), const_cast(mke2fs_args), &status, + rc = android_fork_execvp_ext(arraysize(mke2fs_args), const_cast(mke2fs_args), NULL, true, LOG_KLOG, true, nullptr, nullptr, 0); if (rc) { LERROR << "mke2fs returned " << rc; @@ -78,7 +77,7 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer) nullptr}; rc = android_fork_execvp_ext(arraysize(e2fsdroid_args), const_cast(e2fsdroid_args), - &status, true, LOG_KLOG, true, nullptr, nullptr, 0); + NULL, true, LOG_KLOG, true, nullptr, nullptr, 0); if (rc) { LERROR << "e2fsdroid returned " << rc; } @@ -88,10 +87,9 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer) static int format_f2fs(char *fs_blkdev) { - int status; const char* const args[] = {"/system/bin/make_f2fs", "-f", "-O encrypt", fs_blkdev, nullptr}; - return android_fork_execvp_ext(arraysize(args), const_cast(args), &status, true, + return android_fork_execvp_ext(arraysize(args), const_cast(args), NULL, true, LOG_KLOG, true, nullptr, nullptr, 0); }