diff options
author | Ken Sumrall <ksumrall@android.com> | 2011-06-06 13:24:13 -0700 |
---|---|---|
committer | Ken Sumrall <ksumrall@android.com> | 2011-06-06 13:24:13 -0700 |
commit | a0b154fab1f1dd3fd11c63de18d375412cdfd1c7 (patch) | |
tree | 0a5e2b670b27f8639641f644b4bcddcf3c54f7c0 | |
parent | 337847a149d956ed6d5990f84006f7340475f715 (diff) | |
download | extras-a0b154fab1f1dd3fd11c63de18d375412cdfd1c7.tar.gz |
A few small cleanups to setup_fs.c
Based on code review comments when the code was moved from
crespo specific code to ext4 generic code.
Change-Id: Ia09261563863f6db1d5eadb5a3677b0b38382b93
-rw-r--r-- | ext4_utils/setup_fs.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/ext4_utils/setup_fs.c b/ext4_utils/setup_fs.c index 380c0df8..56c563fa 100644 --- a/ext4_utils/setup_fs.c +++ b/ext4_utils/setup_fs.c @@ -14,6 +14,7 @@ int setup_fs(const char *blockdev) char buf[256], path[128]; pid_t child; int status, n; + pid_t pid; /* we might be looking at an indirect reference */ n = readlink(blockdev, path, sizeof(path) - 1); @@ -27,13 +28,13 @@ int setup_fs(const char *blockdev) fprintf(stderr,"not a block device name: %s\n", blockdev); return 0; } - - sprintf(buf,"/sys/fs/ext4/%s", blockdev); + + snprintf(buf, sizeof(buf), "/sys/fs/ext4/%s", blockdev); if (access(buf, F_OK) == 0) { fprintf(stderr,"device %s already has a filesystem\n", blockdev); return 0; } - sprintf(buf,"/dev/block/%s", blockdev); + snprintf(buf, sizeof(buf), "/dev/block/%s", blockdev); if (!partition_wiped(buf)) { fprintf(stderr,"device %s not wiped, probably encrypted, not wiping\n", blockdev); @@ -44,7 +45,7 @@ int setup_fs(const char *blockdev) child = fork(); if (child < 0) { - fprintf(stderr,"error: fork failed\n"); + fprintf(stderr,"error: setup_fs: fork failed\n"); return 0; } if (child == 0) { @@ -52,7 +53,12 @@ int setup_fs(const char *blockdev) exit(-1); } - while (waitpid(-1, &status, 0) != child) ; + while ((pid=waitpid(-1, &status, 0)) != child) { + if (pid == -1) { + fprintf(stderr, "error: setup_fs: waitpid failed!\n"); + return 1; + } + } fprintf(stderr,"---\n"); return 1; |