]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootctl: also split out 'systemd-efi-options' verb
authorLennart Poettering <lennart@poettering.net>
Fri, 16 Dec 2022 17:45:55 +0000 (18:45 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 19 Dec 2022 10:52:09 +0000 (11:52 +0100)
meson.build
src/boot/bootctl-systemd-efi-options.c [new file with mode: 0644]
src/boot/bootctl-systemd-efi-options.h [new file with mode: 0644]
src/boot/bootctl.c

index d4d19dc0a84d1b2e3bace7aa005dc36716af8079..d30331e72a98895ffe9d7f8e0ebdd5c19461bfeb 100644 (file)
@@ -2611,6 +2611,8 @@ if conf.get('HAVE_BLKID') == 1 and conf.get('HAVE_GNU_EFI') == 1
                  'src/boot/bootctl-random-seed.h',
                  'src/boot/bootctl-reboot-to-firmware.c',
                  'src/boot/bootctl-reboot-to-firmware.h',
+                 'src/boot/bootctl-systemd-efi-options.c',
+                 'src/boot/bootctl-systemd-efi-options.h',
                  'src/boot/bootctl-util.c',
                  'src/boot/bootctl-util.h'],
                 include_directories : includes,
diff --git a/src/boot/bootctl-systemd-efi-options.c b/src/boot/bootctl-systemd-efi-options.c
new file mode 100644 (file)
index 0000000..d0de9ef
--- /dev/null
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "alloc-util.h"
+#include "bootctl-systemd-efi-options.h"
+#include "efi-loader.h"
+
+int verb_systemd_efi_options(int argc, char *argv[], void *userdata) {
+        int r;
+
+        if (argc == 1) {
+                _cleanup_free_ char *line = NULL, *new = NULL;
+
+                r = systemd_efi_options_variable(&line);
+                if (r == -ENODATA)
+                        log_debug("No SystemdOptions EFI variable present in cache.");
+                else if (r < 0)
+                        return log_error_errno(r, "Failed to read SystemdOptions EFI variable from cache: %m");
+                else
+                        puts(line);
+
+                r = systemd_efi_options_efivarfs_if_newer(&new);
+                if (r == -ENODATA) {
+                        if (line)
+                                log_notice("Note: SystemdOptions EFI variable has been removed since boot.");
+                } else if (r < 0)
+                        log_warning_errno(r, "Failed to check SystemdOptions EFI variable in efivarfs, ignoring: %m");
+                else if (new && !streq_ptr(line, new))
+                        log_notice("Note: SystemdOptions EFI variable has been modified since boot. New value: %s",
+                                   new);
+        } else {
+                r = efi_set_variable_string(EFI_SYSTEMD_VARIABLE(SystemdOptions), argv[1]);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to set SystemdOptions EFI variable: %m");
+        }
+
+        return 0;
+}
diff --git a/src/boot/bootctl-systemd-efi-options.h b/src/boot/bootctl-systemd-efi-options.h
new file mode 100644 (file)
index 0000000..d0243eb
--- /dev/null
@@ -0,0 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+int verb_systemd_efi_options(int argc, char *argv[], void *userdata);
index 808c1f0c444568bfcfba3c4e7188c0bba439560f..52f4200e3878f24458f40da044774c44e5eacb3a 100644 (file)
@@ -17,6 +17,7 @@
 #include "bootctl.h"
 #include "bootctl-random-seed.h"
 #include "bootctl-reboot-to-firmware.h"
+#include "bootctl-systemd-efi-options.h"
 #include "bootctl-util.h"
 #include "bootspec.h"
 #include "build.h"
@@ -2318,38 +2319,6 @@ static int verb_set_efivar(int argc, char *argv[], void *userdata) {
         return 0;
 }
 
-static int verb_systemd_efi_options(int argc, char *argv[], void *userdata) {
-        int r;
-
-        if (argc == 1) {
-                _cleanup_free_ char *line = NULL, *new = NULL;
-
-                r = systemd_efi_options_variable(&line);
-                if (r == -ENODATA)
-                        log_debug("No SystemdOptions EFI variable present in cache.");
-                else if (r < 0)
-                        return log_error_errno(r, "Failed to read SystemdOptions EFI variable from cache: %m");
-                else
-                        puts(line);
-
-                r = systemd_efi_options_efivarfs_if_newer(&new);
-                if (r == -ENODATA) {
-                        if (line)
-                                log_notice("Note: SystemdOptions EFI variable has been removed since boot.");
-                } else if (r < 0)
-                        log_warning_errno(r, "Failed to check SystemdOptions EFI variable in efivarfs, ignoring: %m");
-                else if (new && !streq_ptr(line, new))
-                        log_notice("Note: SystemdOptions EFI variable has been modified since boot. New value: %s",
-                                   new);
-        } else {
-                r = efi_set_variable_string(EFI_SYSTEMD_VARIABLE(SystemdOptions), argv[1]);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to set SystemdOptions EFI variable: %m");
-        }
-
-        return 0;
-}
-
 static int bootctl_main(int argc, char *argv[]) {
         static const Verb verbs[] = {
                 { "help",                VERB_ANY, VERB_ANY, 0,            help                     },