summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_nor.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgpt/cgpt_nor.c')
-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;