config.pl get: don't rewrite config.h; detect write errors
scripts/config.pl would always rewrite config.h if it was reading it.
This commit changes it to not modify the file when only reading is
required, i.e. for the get command.
Also, die if writing config.h fails (e.g. disk full).
diff --git a/scripts/config.pl b/scripts/config.pl
index 4cf4ac8..9fc6062 100755
--- a/scripts/config.pl
+++ b/scripts/config.pl
@@ -175,7 +175,10 @@
$no_exclude_re = join '|', @non_excluded;
}
-open my $config_write, '>', $config_file or die "write $config_file: $!\n";
+my $config_write = undef;
+if ($action ne "get") {
+ open $config_write, '>', $config_file or die "write $config_file: $!\n";
+}
my $done;
for my $line (@config_lines) {
@@ -211,7 +214,9 @@
}
}
- print $config_write $line;
+ if (defined $config_write) {
+ print $config_write $line or die "write $config_file: $!\n";;
+ }
}
# Did the set command work?
@@ -223,10 +228,12 @@
$line .= "\n";
$done = 1;
- print $config_write $line;
+ print $config_write $line or die "write $config_file: $!\n";
}
-close $config_write;
+if (defined $config_write) {
+ close $config_write or die "close $config_file: $!\n";
+}
if ($action eq "get") {
if($done) {