]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootctl: let's start splitting up bootctl like we did for systemctl and others
authorLennart Poettering <lennart@poettering.net>
Fri, 16 Dec 2022 17:27:06 +0000 (18:27 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 19 Dec 2022 10:43:19 +0000 (11:43 +0100)
meson.build
src/boot/bootctl-reboot-to-firmware.c [new file with mode: 0644]
src/boot/bootctl-reboot-to-firmware.h [new file with mode: 0644]
src/boot/bootctl.c

index 3c6734b578f837ce7a033014564410270c67f61c..f0b7b8958ee0edd2d02656b9b6a5bc96297a2bee 100644 (file)
@@ -2605,7 +2605,9 @@ if conf.get('HAVE_BLKID') == 1 and conf.get('HAVE_GNU_EFI') == 1
 
         exe = executable(
                 'bootctl',
-                'src/boot/bootctl.c',
+                ['src/boot/bootctl.c',
+                 'src/boot/bootctl-reboot-to-firmware.c',
+                 'src/boot/bootctl-reboot-to-firmware.h'],
                 include_directories : includes,
                 link_with : [boot_link_with],
                 dependencies : [libblkid,
diff --git a/src/boot/bootctl-reboot-to-firmware.c b/src/boot/bootctl-reboot-to-firmware.c
new file mode 100644 (file)
index 0000000..77e3ff1
--- /dev/null
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "bootctl-reboot-to-firmware.h"
+#include "efi-api.h"
+#include "parse-util.h"
+
+int verb_reboot_to_firmware(int argc, char *argv[], void *userdata) {
+        int r;
+
+        if (argc < 2) {
+                r = efi_get_reboot_to_firmware();
+                if (r > 0) {
+                        puts("active");
+                        return EXIT_SUCCESS; /* success */
+                }
+                if (r == 0) {
+                        puts("supported");
+                        return 1; /* recognizable error #1 */
+                }
+                if (r == -EOPNOTSUPP) {
+                        puts("not supported");
+                        return 2; /* recognizable error #2 */
+                }
+
+                log_error_errno(r, "Failed to query reboot-to-firmware state: %m");
+                return 3; /* other kind of error */
+        } else {
+                r = parse_boolean(argv[1]);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse argument: %s", argv[1]);
+
+                r = efi_set_reboot_to_firmware(r);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to set reboot-to-firmware option: %m");
+
+                return 0;
+        }
+}
diff --git a/src/boot/bootctl-reboot-to-firmware.h b/src/boot/bootctl-reboot-to-firmware.h
new file mode 100644 (file)
index 0000000..0ca4b2c
--- /dev/null
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+int verb_reboot_to_firmware(int argc, char *argv[], void *userdata);
index 7721c3d2e38ed16c2baf96a263ecc9e2409be9e1..9b82102d0e724471bf57c7483ffe381be0c1ed3f 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "alloc-util.h"
 #include "blkid-util.h"
+#include "bootctl-reboot-to-firmware.h"
 #include "bootspec.h"
 #include "build.h"
 #include "chase-symlinks.h"
@@ -2499,39 +2500,6 @@ static int verb_systemd_efi_options(int argc, char *argv[], void *userdata) {
         return 0;
 }
 
-static int verb_reboot_to_firmware(int argc, char *argv[], void *userdata) {
-        int r;
-
-        if (argc < 2) {
-                r = efi_get_reboot_to_firmware();
-                if (r > 0) {
-                        puts("active");
-                        return EXIT_SUCCESS; /* success */
-                }
-                if (r == 0) {
-                        puts("supported");
-                        return 1; /* recognizable error #1 */
-                }
-                if (r == -EOPNOTSUPP) {
-                        puts("not supported");
-                        return 2; /* recognizable error #2 */
-                }
-
-                log_error_errno(r, "Failed to query reboot-to-firmware state: %m");
-                return 3; /* other kind of error */
-        } else {
-                r = parse_boolean(argv[1]);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to parse argument: %s", argv[1]);
-
-                r = efi_set_reboot_to_firmware(r);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to set reboot-to-firmware option: %m");
-
-                return 0;
-        }
-}
-
 static int bootctl_main(int argc, char *argv[]) {
         static const Verb verbs[] = {
                 { "help",                VERB_ANY, VERB_ANY, 0,            help                     },