diff options
| author | Ken Sumrall <ksumrall@android.com> | 2013-03-19 19:38:44 -0700 |
|---|---|---|
| committer | Ken Sumrall <ksumrall@android.com> | 2013-04-14 17:11:00 -0700 |
| commit | bf021b4cd760a48b38c58347a35157180593c4b8 (patch) | |
| tree | 68d68ec09e5679e07c925a44d1a2fd2939a7de57 /fs_mgr | |
| parent | 96e11b5bc473918d61b088f1840e4d1ec48fd3ab (diff) | |
| download | system_core-bf021b4cd760a48b38c58347a35157180593c4b8.tar.gz system_core-bf021b4cd760a48b38c58347a35157180593c4b8.tar.bz2 system_core-bf021b4cd760a48b38c58347a35157180593c4b8.zip | |
fs_mgr: Capture the output of e2fsck and add to the kernel log
Currently, the output of e2fsck is not saved, and we have no insight
into how many errors e2fsck is finding and fixing. Using the new
abbreviated logging feature in liblogwrap, up to the first 100 lines,
and last 4K bytes of the output of e2fsck is captured by fs_mgr, and
added to the kernel log.
Usually, the filesystem will be clean, and this will only add a few
lines to the kernel log on boot, but when things go wrong, it should
save enough to indicate what the problem is, without potentially
filling the kernel log with only e2fsck output if the filesystem is
really corrupted.
Change-Id: I9c264798e6fe721c8f818b5ce15d0975027ddbdd
Diffstat (limited to 'fs_mgr')
| -rw-r--r-- | fs_mgr/Android.mk | 3 | ||||
| -rw-r--r-- | fs_mgr/fs_mgr.c | 32 |
2 files changed, 16 insertions, 19 deletions
diff --git a/fs_mgr/Android.mk b/fs_mgr/Android.mk index 7c66f6ab0..0ce07c12b 100644 --- a/fs_mgr/Android.mk +++ b/fs_mgr/Android.mk @@ -8,6 +8,7 @@ LOCAL_SRC_FILES:= fs_mgr.c LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_MODULE:= libfs_mgr +LOCAL_STATIC_LIBRARIES := liblogwrap LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include include $(BUILD_STATIC_LIBRARY) @@ -27,7 +28,7 @@ LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED) -LOCAL_STATIC_LIBRARIES := libfs_mgr libcutils libc +LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils libc include $(BUILD_EXECUTABLE) diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index 8f647578b..fecc556a3 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -14,11 +14,6 @@ * limitations under the License. */ -/* TO DO: - * 1. Re-direct fsck output to the kernel log? - * - */ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -36,6 +31,7 @@ #include <private/android_filesystem_config.h> #include <cutils/partition_utils.h> #include <cutils/properties.h> +#include <logwrap/logwrap.h> #include "fs_mgr_priv.h" @@ -44,6 +40,8 @@ #define E2FSCK_BIN "/system/bin/e2fsck" +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) + struct flag_list { const char *name; unsigned flag; @@ -434,11 +432,15 @@ void fs_mgr_free_fstab(struct fstab *fstab) static void check_fs(char *blk_device, char *fs_type, char *target) { - pid_t pid; int status; int ret; long tmpmnt_flags = MS_NOATIME | MS_NOEXEC | MS_NOSUID; char *tmpmnt_opts = "nomblk_io_submit,errors=remount-ro"; + char *e2fsck_argv[] = { + E2FSCK_BIN, + "-y", + blk_device + }; /* Check for the types of filesystems we know how to check */ if (!strcmp(fs_type, "ext2") || !strcmp(fs_type, "ext3") || !strcmp(fs_type, "ext4")) { @@ -461,19 +463,13 @@ static void check_fs(char *blk_device, char *fs_type, char *target) } INFO("Running %s on %s\n", E2FSCK_BIN, blk_device); - pid = fork(); - if (pid > 0) { - /* Parent, wait for the child to return */ - waitpid(pid, &status, 0); - } else if (pid == 0) { - /* child, run checker */ - execlp(E2FSCK_BIN, E2FSCK_BIN, "-y", blk_device, (char *)NULL); - - /* Only gets here on error */ - ERROR("Cannot run fs_mgr binary %s\n", E2FSCK_BIN); - } else { + + ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv), e2fsck_argv, + &status, true, LOG_KLOG, true); + + if (ret < 0) { /* No need to check for error in fork, we can't really handle it now */ - ERROR("Fork failed trying to run %s\n", E2FSCK_BIN); + ERROR("Failed trying to run %s\n", E2FSCK_BIN); } } |
