summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNam T. Nguyen <namnguyen@chromium.org>2015-01-21 14:37:10 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-22 21:14:35 +0000
commit616153ad1c15e0112afe664f6f5f50f06fa7e073 (patch)
tree5db53c7a072ac8b479c56e0f76aa812b446bf6d0
parent9fa6afce26879f605b13f481e7abd097e563970f (diff)
downloadvboot-616153ad1c15e0112afe664f6f5f50f06fa7e073.tar.gz
cgpt: Close stdout on exec'ing flashrom
flashrom spills out "Reading flash... SUCCESS" and so on to stdout. This affects scripts calling to "cgpt". So this CL sets stdout to CLOEXEC before exec'ing flashrom. It still leaves stderr and stdin unclosed. BUG=None BRANCH=None TEST=cgpt show /dev/mtd0 2>/dev/null will not show any unnecessary text Change-Id: Ide1414c56f63ffe8bc2385a797f166476dacd732 Reviewed-on: https://chromium-review.googlesource.com/242295 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@google.com>
-rw-r--r--cgpt/cgpt_nor.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/cgpt/cgpt_nor.c b/cgpt/cgpt_nor.c
index 95c2f495..bf0a1764 100644
--- a/cgpt/cgpt_nor.c
+++ b/cgpt/cgpt_nor.c
@@ -209,14 +209,18 @@ int ReadNorFlash(char *temp_dir_template) {
// Read RW_GPT section from NOR flash to "rw_gpt".
ret++;
+ int fd_flags = fcntl(1, F_GETFD);
+ // Close stdout on exec so that flashrom does not muck up cgpt's output.
+ fcntl(1, F_SETFD, FD_CLOEXEC);
if (ForkExecL(temp_dir_template, FLASHROM_PATH, "-i", "RW_GPT:rw_gpt", "-r",
NULL) != 0) {
Error("Cannot exec flashrom to read from RW_GPT section.\n");
RemoveDir(temp_dir_template);
- return ret;
+ } else {
+ ret = 0;
}
- ret = 0;
+ fcntl(1, F_SETFD, fd_flags);
return ret;
}
@@ -230,6 +234,9 @@ int WriteNorFlash(const char *dir) {
}
ret++;
int nr_fails = 0;
+ int fd_flags = fcntl(1, F_GETFD);
+ // Close stdout on exec so that flashrom does not muck up cgpt's output.
+ fcntl(1, F_SETFD, FD_CLOEXEC);
if (ForkExecL(dir, FLASHROM_PATH, "-i", "RW_GPT_PRIMARY:rw_gpt_1",
"-w", "--fast-verify", NULL) != 0) {
Warning("Cannot write the 1st half of rw_gpt back with flashrom.\n");
@@ -240,6 +247,7 @@ int WriteNorFlash(const char *dir) {
Warning("Cannot write the 2nd half of rw_gpt back with flashrom.\n");
nr_fails++;
}
+ fcntl(1, F_SETFD, fd_flags);
switch (nr_fails) {
case 0: ret = 0; break;
case 1: Warning("It might still be okay.\n"); break;