summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-04-04 09:36:44 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-04-04 10:46:13 +0200
commit957b2423191f56f134c45f348f8de5f90115f6fb (patch)
treedb4918b71ea5be5fffb311244c71591f5ec0b000
parentb2e7ded16b16181767822d471d214cd8eba3c2d5 (diff)
downloadsystemd-957b2423191f56f134c45f348f8de5f90115f6fb.tar.gz
bootctl: do not call acquire_esp() twice
That function is nasty because it modifies global state. We should call it just once in each call path. Also drop 'return 1' which doesn't seem to have any use.
-rw-r--r--src/boot/bootctl.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c
index 759b3ca86a..c4cb33c705 100644
--- a/src/boot/bootctl.c
+++ b/src/boot/bootctl.c
@@ -115,7 +115,7 @@ static int acquire_esp(
free_and_replace(arg_esp_path, np);
log_debug("Using EFI System Partition at %s.", arg_esp_path);
- return 1;
+ return 0;
}
static int acquire_xbootldr(
@@ -1593,13 +1593,9 @@ static void print_yes_no_line(bool first, bool good, const char *name) {
name);
}
-static int are_we_installed(void) {
+static int are_we_installed(const char *esp_path) {
int r;
- r = acquire_esp(/* privileged_mode= */ false, /* graceful= */ false, NULL, NULL, NULL, NULL, NULL);
- if (r < 0)
- return r;
-
/* Tests whether systemd-boot is installed. It's not obvious what to use as check here: we could
* check EFI variables, we could check what binary /EFI/BOOT/BOOT*.EFI points to, or whether the
* loader entries directory exists. Here we opted to check whether /EFI/systemd/ is non-empty, which
@@ -1614,7 +1610,7 @@ static int are_we_installed(void) {
* → It specifically checks for systemd-boot, not for other boot loaders (which a check for
* /boot/loader/entries would do). */
- _cleanup_free_ char *p = path_join(arg_esp_path, "/EFI/systemd/");
+ _cleanup_free_ char *p = path_join(esp_path, "/EFI/systemd/");
if (!p)
return log_oom();
@@ -1659,8 +1655,8 @@ static int verb_status(int argc, char *argv[], void *userdata) {
if (arg_print_esp_path || arg_print_dollar_boot_path)
return 0;
- r = 0; /* If we couldn't determine the path, then don't consider that a problem from here on, just show what we
- * can show */
+ r = 0; /* If we couldn't determine the path, then don't consider that a problem from here on, just
+ * show what we can show */
pager_open(arg_pager_flags);
@@ -2063,7 +2059,7 @@ static int verb_install(int argc, char *argv[], void *userdata) {
if (!install) {
/* If we are updating, don't do anything if sd-boot wasn't actually installed. */
- r = are_we_installed();
+ r = are_we_installed(arg_esp_path);
if (r < 0)
return r;
if (r == 0) {
@@ -2209,7 +2205,11 @@ static int verb_remove(int argc, char *argv[], void *userdata) {
static int verb_is_installed(int argc, char *argv[], void *userdata) {
int r;
- r = are_we_installed();
+ r = acquire_esp(/* privileged_mode= */ false, /* graceful= */ false, NULL, NULL, NULL, NULL, NULL);
+ if (r < 0)
+ return r;
+
+ r = are_we_installed(arg_esp_path);
if (r < 0)
return r;