1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-06 08:26:52 +03:00

bootctl: ferror must be called before FILE is closed

Otherwise it will not show any error stored
This commit is contained in:
Thomas Hindoe Paaboel Andersen 2015-05-22 23:40:19 +02:00
parent 0454229c10
commit 717442507b

View File

@ -884,7 +884,7 @@ static int install_loader_config(const char *esp_path) {
char *p; char *p;
char line[64]; char line[64];
char *machine = NULL; char *machine = NULL;
FILE *f; _cleanup_fclose_ FILE *f = NULL, *g = NULL;
f = fopen("/etc/machine-id", "re"); f = fopen("/etc/machine-id", "re");
if (!f) if (!f)
@ -899,18 +899,16 @@ static int install_loader_config(const char *esp_path) {
if (strlen(line) == 32) if (strlen(line) == 32)
machine = line; machine = line;
} }
fclose(f);
if (!machine) if (!machine)
return -ESRCH; return -ESRCH;
p = strjoina(esp_path, "/loader/loader.conf"); p = strjoina(esp_path, "/loader/loader.conf");
f = fopen(p, "wxe"); g = fopen(p, "wxe");
if (f) { if (g) {
fprintf(f, "#timeout 3\n"); fprintf(g, "#timeout 3\n");
fprintf(f, "default %s-*\n", machine); fprintf(g, "default %s-*\n", machine);
fclose(f); if (ferror(g))
if (ferror(f))
return log_error_errno(EIO, "Failed to write \"%s\": %m", p); return log_error_errno(EIO, "Failed to write \"%s\": %m", p);
} }
@ -926,7 +924,7 @@ static int help(void) {
" --path=PATH Path to the EFI System Partition (ESP)\n" " --path=PATH Path to the EFI System Partition (ESP)\n"
" --no-variables Don't touch EFI variables\n" " --no-variables Don't touch EFI variables\n"
"\n" "\n"
"Comands:\n" "Commands:\n"
" status Show status of installed systemd-boot and EFI variables\n" " status Show status of installed systemd-boot and EFI variables\n"
" install Install systemd-boot to the ESP and EFI variables\n" " install Install systemd-boot to the ESP and EFI variables\n"
" update Update systemd-boot in the ESP and EFI variables\n" " update Update systemd-boot in the ESP and EFI variables\n"