• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 23273450309

18 Mar 2026 11:04PM UTC coverage: 72.618% (+0.04%) from 72.575%
23273450309

push

github

web-flow
userdb: add birthDate field to JSON user records (#40954)

Add an optional field that can be used to store a user's birth date.
userdb already stores personal metadata (`emailAddress`, `realName`,
`location`) so `birthDate` is a natural fit.

80 of 96 new or added lines in 8 files covered. (83.33%)

5187 existing lines in 82 files now uncovered.

316431 of 435750 relevant lines covered (72.62%)

1196544.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/bootctl/bootctl.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <getopt.h>
4
#include <sys/stat.h>
5

6
#include "sd-varlink.h"
7

8
#include "blockdev-util.h"
9
#include "boot-entry.h"
10
#include "bootctl.h"
11
#include "bootctl-cleanup.h"
12
#include "bootctl-install.h"
13
#include "bootctl-random-seed.h"
14
#include "bootctl-reboot-to-firmware.h"
15
#include "bootctl-set-efivar.h"
16
#include "bootctl-status.h"
17
#include "bootctl-uki.h"
18
#include "bootctl-unlink.h"
19
#include "build.h"
20
#include "devnum-util.h"
21
#include "dissect-image.h"
22
#include "efi-loader.h"
23
#include "efivars.h"
24
#include "escape.h"
25
#include "find-esp.h"
26
#include "image-policy.h"
27
#include "log.h"
28
#include "loop-util.h"
29
#include "main-func.h"
30
#include "mount-util.h"
31
#include "openssl-util.h"
32
#include "pager.h"
33
#include "parse-argument.h"
34
#include "path-util.h"
35
#include "pretty-print.h"
36
#include "string-table.h"
37
#include "string-util.h"
38
#include "strv.h"
39
#include "utf8.h"
40
#include "varlink-io.systemd.BootControl.h"
41
#include "varlink-util.h"
42
#include "verbs.h"
43
#include "virt.h"
44

45
static GracefulMode _arg_graceful = ARG_GRACEFUL_NO;
46

47
char *arg_esp_path = NULL;
48
char *arg_xbootldr_path = NULL;
49
bool arg_print_esp_path = false;
50
bool arg_print_dollar_boot_path = false;
51
bool arg_print_loader_path = false;
52
bool arg_print_stub_path = false;
53
unsigned arg_print_root_device = 0;
54
int arg_touch_variables = -1;
55
bool arg_install_random_seed = true;
56
PagerFlags arg_pager_flags = 0;
57
bool arg_quiet = false;
58
int arg_make_entry_directory = false; /* tri-state: < 0 for automatic logic */
59
sd_id128_t arg_machine_id = SD_ID128_NULL;
60
char *arg_install_layout = NULL;
61
BootEntryTokenType arg_entry_token_type = BOOT_ENTRY_TOKEN_AUTO;
62
char *arg_entry_token = NULL;
63
sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
64
bool arg_arch_all = false;
65
char *arg_root = NULL;
66
char *arg_image = NULL;
67
InstallSource arg_install_source = INSTALL_SOURCE_AUTO;
68
char *arg_efi_boot_option_description = NULL;
69
bool arg_efi_boot_option_description_with_device = false;
70
bool arg_dry_run = false;
71
ImagePolicy *arg_image_policy = NULL;
72
bool arg_varlink = false;
73
bool arg_secure_boot_auto_enroll = false;
74
char *arg_certificate = NULL;
75
CertificateSourceType arg_certificate_source_type = OPENSSL_CERTIFICATE_SOURCE_FILE;
76
char *arg_certificate_source = NULL;
77
char *arg_private_key = NULL;
78
KeySourceType arg_private_key_source_type = OPENSSL_KEY_SOURCE_FILE;
79
char *arg_private_key_source = NULL;
80

81
STATIC_DESTRUCTOR_REGISTER(arg_esp_path, freep);
297✔
82
STATIC_DESTRUCTOR_REGISTER(arg_xbootldr_path, freep);
297✔
83
STATIC_DESTRUCTOR_REGISTER(arg_install_layout, freep);
297✔
84
STATIC_DESTRUCTOR_REGISTER(arg_entry_token, freep);
297✔
85
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
297✔
86
STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
297✔
87
STATIC_DESTRUCTOR_REGISTER(arg_efi_boot_option_description, freep);
297✔
88
STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
297✔
89
STATIC_DESTRUCTOR_REGISTER(arg_certificate, freep);
297✔
90
STATIC_DESTRUCTOR_REGISTER(arg_certificate_source, freep);
297✔
91
STATIC_DESTRUCTOR_REGISTER(arg_private_key, freep);
297✔
92
STATIC_DESTRUCTOR_REGISTER(arg_private_key_source, freep);
297✔
93

94
static const char* const install_source_table[_INSTALL_SOURCE_MAX] = {
95
        [INSTALL_SOURCE_IMAGE] = "image",
96
        [INSTALL_SOURCE_HOST]  = "host",
97
        [INSTALL_SOURCE_AUTO]  = "auto",
98
};
99

100
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(install_source, InstallSource);
×
101

102
int acquire_esp(
256✔
103
                int unprivileged_mode,
104
                bool graceful,
105
                uint32_t *ret_part,
106
                uint64_t *ret_pstart,
107
                uint64_t *ret_psize,
108
                sd_id128_t *ret_uuid,
109
                dev_t *ret_devid) {
110

111
        char *np;
256✔
112
        int r;
256✔
113

114
        /* Find the ESP, and log about errors. Note that find_esp_and_warn() will log in all error cases on
115
         * its own, except for ENOKEY (which is good, we want to show our own message in that case,
116
         * suggesting use of --esp-path=) and EACCESS (only when we request unprivileged mode; in this case
117
         * we simply eat up the error here, so that --list and --status work too, without noise about
118
         * this). */
119

120
        r = find_esp_and_warn_full(arg_root, arg_esp_path, unprivileged_mode, &np, ret_part, ret_pstart, ret_psize, ret_uuid, ret_devid);
256✔
121
        if (r == -ENOKEY) {
256✔
122
                if (graceful)
5✔
123
                        return log_full_errno(arg_quiet ? LOG_DEBUG : LOG_INFO, r,
×
124
                                              "Couldn't find EFI system partition, skipping.");
125

126
                return log_error_errno(r,
5✔
127
                                       "Couldn't find EFI system partition. It is recommended to mount it to /boot/ or /efi/.\n"
128
                                       "Alternatively, use --esp-path= to specify path to mount point.");
129
        }
130
        if (r < 0)
251✔
131
                return r;
132

133
        free_and_replace(arg_esp_path, np);
250✔
134
        log_debug("Using EFI System Partition at %s.", arg_esp_path);
250✔
135

136
        return 0;
137
}
138

139
int acquire_xbootldr(
203✔
140
                int unprivileged_mode,
141
                sd_id128_t *ret_uuid,
142
                dev_t *ret_devid) {
143

144
        char *np;
203✔
145
        int r;
203✔
146

147
        r = find_xbootldr_and_warn_full(arg_root, arg_xbootldr_path, unprivileged_mode, &np, ret_uuid, ret_devid);
203✔
148
        if (r == -ENOKEY || path_equal(np, arg_esp_path)) {
203✔
149
                log_debug("Didn't find an XBOOTLDR partition, using the ESP as $BOOT.");
156✔
150
                arg_xbootldr_path = mfree(arg_xbootldr_path);
156✔
151

152
                if (ret_uuid)
156✔
153
                        *ret_uuid = SD_ID128_NULL;
15✔
154
                if (ret_devid)
156✔
155
                        *ret_devid = 0;
20✔
156
                return 0;
156✔
157
        }
158
        if (r < 0)
47✔
159
                return r;
160

161
        free_and_replace(arg_xbootldr_path, np);
46✔
162
        log_debug("Using XBOOTLDR partition at %s as $BOOT.", arg_xbootldr_path);
46✔
163

164
        return 1;
165
}
166

167
static int print_loader_or_stub_path(void) {
6✔
168
        _cleanup_free_ char *p = NULL;
6✔
169
        sd_id128_t uuid;
6✔
170
        int r;
6✔
171

172
        if (arg_print_loader_path) {
6✔
173
                r = efi_loader_get_device_part_uuid(&uuid);
×
174
                if (r == -ENOENT)
×
175
                        return log_error_errno(r, "No loader partition UUID passed.");
×
176
                if (r < 0)
×
177
                        return log_error_errno(r, "Unable to determine loader partition UUID: %m");
×
178

179
                r = efi_get_variable_path(EFI_LOADER_VARIABLE_STR("LoaderImageIdentifier"), &p);
×
180
                if (r == -ENOENT)
×
181
                        return log_error_errno(r, "No loader EFI binary path passed.");
×
182
                if (r < 0)
×
183
                        return log_error_errno(r, "Unable to determine loader EFI binary path: %m");
×
184
        } else {
185
                assert(arg_print_stub_path);
6✔
186

187
                r = efi_stub_get_device_part_uuid(&uuid);
6✔
188
                if (r == -ENOENT)
6✔
189
                        return log_error_errno(r, "No stub partition UUID passed.");
×
190
                if (r < 0)
6✔
191
                        return log_error_errno(r, "Unable to determine stub partition UUID: %m");
×
192

193
                r = efi_get_variable_path(EFI_LOADER_VARIABLE_STR("StubImageIdentifier"), &p);
6✔
194
                if (r == -ENOENT)
6✔
195
                        return log_error_errno(r, "No stub EFI binary path passed.");
×
196
                if (r < 0)
6✔
197
                        return log_error_errno(r, "Unable to determine stub EFI binary path: %m");
×
198
        }
199

200
        sd_id128_t esp_uuid;
6✔
201
        r = acquire_esp(/* unprivileged_mode= */ false, /* graceful= */ false,
6✔
202
                        /* ret_part= */ NULL, /* ret_pstart= */ NULL, /* ret_psize= */ NULL,
203
                        &esp_uuid, /* ret_devid= */ NULL);
204
        if (r < 0)
6✔
205
                return r;
206

207
        const char *found_path = NULL;
6✔
208
        if (sd_id128_equal(esp_uuid, uuid))
6✔
209
                found_path = arg_esp_path;
6✔
210
        else if (arg_print_stub_path) { /* In case of the stub, also look for things in the xbootldr partition */
×
211
                sd_id128_t xbootldr_uuid;
×
212

213
                r = acquire_xbootldr(/* unprivileged_mode= */ false, &xbootldr_uuid, /* ret_devid= */ NULL);
×
214
                if (r < 0)
×
215
                        return r;
×
216

217
                if (sd_id128_equal(xbootldr_uuid, uuid))
×
218
                        found_path = arg_xbootldr_path;
×
219
        }
220

221
        if (!found_path)
6✔
222
                return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Failed to discover partition " SD_ID128_FORMAT_STR " among mounted boot partitions.", SD_ID128_FORMAT_VAL(uuid));
×
223

224
        _cleanup_free_ char *j = path_join(found_path, p);
12✔
225
        if (!j)
6✔
226
                return log_oom();
×
227

228
        puts(j);
6✔
229
        return 0;
230
}
231

232
GracefulMode arg_graceful(void) {
288✔
233
        static bool chroot_checked = false;
288✔
234

235
        if (!chroot_checked && running_in_chroot() > 0) {
288✔
236
                if (_arg_graceful == ARG_GRACEFUL_NO)
×
237
                        log_full(arg_quiet ? LOG_DEBUG : LOG_INFO, "Running in a chroot, enabling --graceful.");
×
238

239
                _arg_graceful = ARG_GRACEFUL_FORCE;
×
240
        }
241

242
        chroot_checked = true;
288✔
243

244
        return _arg_graceful;
288✔
245
}
246

247
static int help(void) {
3✔
248
        _cleanup_free_ char *link = NULL;
3✔
249
        int r;
3✔
250

251
        pager_open(arg_pager_flags);
3✔
252

253
        r = terminal_urlify_man("bootctl", "1", &link);
3✔
254
        if (r < 0)
3✔
255
                return log_oom();
×
256

257
        printf("%1$s [OPTIONS...] COMMAND ...\n"
6✔
258
               "\n%5$sControl EFI firmware boot settings and manage boot loader.%6$s\n"
259
               "\n%3$sGeneric EFI Firmware/Boot Loader Commands:%4$s\n"
260
               "  status               Show status of installed boot loader and EFI variables\n"
261
               "  reboot-to-firmware [BOOL]\n"
262
               "                       Query or set reboot-to-firmware EFI flag\n"
263
               "\n%3$sBoot Loader Specification Commands:%4$s\n"
264
               "  list                 List boot loader entries\n"
265
               "  unlink ID            Remove boot loader entry\n"
266
               "  cleanup              Remove files in ESP not referenced in any boot entry\n"
267
               "\n%3$sBoot Loader Interface Commands:%4$s\n"
268
               "  set-default ID       Set default boot loader entry\n"
269
               "  set-oneshot ID       Set default boot loader entry, for next boot only\n"
270
               "  set-sysfail ID       Set boot loader entry used in case of a system failure\n"
271
               "  set-timeout SECONDS  Set the menu timeout\n"
272
               "  set-timeout-oneshot SECONDS\n"
273
               "                       Set the menu timeout for the next boot only\n"
274
               "\n%3$ssystemd-boot Commands:%4$s\n"
275
               "  install              Install systemd-boot to the ESP and EFI variables\n"
276
               "  update               Update systemd-boot in the ESP and EFI variables\n"
277
               "  remove               Remove systemd-boot from the ESP and EFI variables\n"
278
               "  is-installed         Test whether systemd-boot is installed in the ESP\n"
279
               "  random-seed          Initialize or refresh random seed in ESP and EFI\n"
280
               "                       variables\n"
281
               "\n%3$sKernel Image Commands:%4$s\n"
282
               "  kernel-identify KERNEL-IMAGE\n"
283
               "                       Identify kernel image type\n"
284
               "  kernel-inspect KERNEL-IMAGE\n"
285
               "                       Prints details about the kernel image\n"
286
               "\n%3$sBlock Device Discovery Commands:%4$s\n"
287
               "  -p --print-esp-path  Print path to the EFI System Partition mount point\n"
288
               "  -x --print-boot-path Print path to the $BOOT partition mount point\n"
289
               "     --print-loader-path\n"
290
               "                       Print path to currently booted boot loader binary\n"
291
               "     --print-stub-path Print path to currently booted unified kernel binary\n"
292
               "  -R --print-root-device\n"
293
               "                       Print path to the block device node backing the\n"
294
               "                       root file system (returns e.g. /dev/nvme0n1p5)\n"
295
               "  -RR                  Print path to the whole disk block device node\n"
296
               "                       backing the root FS (returns e.g. /dev/nvme0n1)\n"
297
               "\n%3$sOptions:%4$s\n"
298
               "  -h --help            Show this help\n"
299
               "     --version         Print version\n"
300
               "     --esp-path=PATH   Path to the EFI System Partition (ESP)\n"
301
               "     --boot-path=PATH  Path to the $BOOT partition\n"
302
               "     --root=PATH       Operate on an alternate filesystem root\n"
303
               "     --image=PATH      Operate on disk image as filesystem root\n"
304
               "     --image-policy=POLICY\n"
305
               "                       Specify disk image dissection policy\n"
306
               "     --install-source=auto|image|host\n"
307
               "                       Where to pick files when using --root=/--image=\n"
308
               "     --variables=yes|no\n"
309
               "                       Whether to modify EFI variables\n"
310
               "     --random-seed=yes|no\n"
311
               "                       Whether to create random-seed file during install\n"
312
               "     --no-pager        Do not pipe output into a pager\n"
313
               "     --graceful        Don't fail when the ESP cannot be found or EFI\n"
314
               "                       variables cannot be written\n"
315
               "  -q --quiet           Suppress output\n"
316
               "     --make-entry-directory=yes|no|auto\n"
317
               "                       Create $BOOT/ENTRY-TOKEN/ directory\n"
318
               "     --entry-token=machine-id|os-id|os-image-id|auto|literal:…\n"
319
               "                       Entry token to use for this installation\n"
320
               "     --json=pretty|short|off\n"
321
               "                       Generate JSON output\n"
322
               "     --all-architectures\n"
323
               "                       Install all supported EFI architectures\n"
324
               "     --efi-boot-option-description=DESCRIPTION\n"
325
               "                       Description of the entry in the boot option list\n"
326
               "     --efi-boot-option-description-with-device=yes\n"
327
               "                       Suffix description with disk vendor/model/serial\n"
328
               "     --dry-run         Dry run (unlink and cleanup)\n"
329
               "     --secure-boot-auto-enroll=yes|no\n"
330
               "                       Set up secure boot auto-enrollment\n"
331
               "     --private-key=PATH|URI\n"
332
               "                       Private key to use when setting up secure boot\n"
333
               "                       auto-enrollment or an engine or provider specific\n"
334
               "                       designation if --private-key-source= is used\n"
335
               "     --private-key-source=file|provider:PROVIDER|engine:ENGINE\n"
336
               "                       Specify how to use KEY for --private-key=. Allows\n"
337
               "                       an OpenSSL engine/provider to be used when setting\n"
338
               "                       up secure boot auto-enrollment\n"
339
               "     --certificate=PATH|URI\n"
340
               "                       PEM certificate to use when setting up Secure Boot\n"
341
               "                       auto-enrollment, or a provider specific designation\n"
342
               "                       if --certificate-source= is used\n"
343
               "     --certificate-source=file|provider:PROVIDER\n"
344
               "                       Specify how to interpret the certificate from\n"
345
               "                       --certificate=. Allows the certificate to be loaded\n"
346
               "                       from an OpenSSL provider\n"
347
               "\nSee the %2$s for details.\n",
348
               program_invocation_short_name,
349
               link,
350
               ansi_underline(),
351
               ansi_normal(),
352
               ansi_highlight(),
353
               ansi_normal());
354

355
        return 0;
356
}
357

UNCOV
358
static int verb_help(int argc, char *argv[], uintptr_t _data, void *userdata) {
×
UNCOV
359
        return help();
×
360
}
361

362
static int parse_argv(int argc, char *argv[]) {
297✔
363
        enum {
297✔
364
                ARG_ESP_PATH = 0x100,
365
                ARG_BOOT_PATH,
366
                ARG_ROOT,
367
                ARG_IMAGE,
368
                ARG_IMAGE_POLICY,
369
                ARG_INSTALL_SOURCE,
370
                ARG_VERSION,
371
                ARG_VARIABLES,
372
                ARG_NO_VARIABLES,
373
                ARG_RANDOM_SEED,
374
                ARG_NO_PAGER,
375
                ARG_GRACEFUL,
376
                ARG_MAKE_ENTRY_DIRECTORY,
377
                ARG_ENTRY_TOKEN,
378
                ARG_JSON,
379
                ARG_ARCH_ALL,
380
                ARG_EFI_BOOT_OPTION_DESCRIPTION,
381
                ARG_EFI_BOOT_OPTION_DESCRIPTION_WITH_DEVICE,
382
                ARG_DRY_RUN,
383
                ARG_PRINT_LOADER_PATH,
384
                ARG_PRINT_STUB_PATH,
385
                ARG_SECURE_BOOT_AUTO_ENROLL,
386
                ARG_CERTIFICATE,
387
                ARG_CERTIFICATE_SOURCE,
388
                ARG_PRIVATE_KEY,
389
                ARG_PRIVATE_KEY_SOURCE,
390
        };
391

392
        static const struct option options[] = {
297✔
393
                { "help",                                    no_argument,       NULL, 'h'                                         },
394
                { "version",                                 no_argument,       NULL, ARG_VERSION                                 },
395
                { "esp-path",                                required_argument, NULL, ARG_ESP_PATH                                },
396
                { "path",                                    required_argument, NULL, ARG_ESP_PATH                                }, /* Compatibility alias */
397
                { "boot-path",                               required_argument, NULL, ARG_BOOT_PATH                               },
398
                { "root",                                    required_argument, NULL, ARG_ROOT                                    },
399
                { "image",                                   required_argument, NULL, ARG_IMAGE                                   },
400
                { "image-policy",                            required_argument, NULL, ARG_IMAGE_POLICY                            },
401
                { "install-source",                          required_argument, NULL, ARG_INSTALL_SOURCE                          },
402
                { "print-esp-path",                          no_argument,       NULL, 'p'                                         },
403
                { "print-path",                              no_argument,       NULL, 'p'                                         }, /* Compatibility alias */
404
                { "print-boot-path",                         no_argument,       NULL, 'x'                                         },
405
                { "print-loader-path",                       no_argument,       NULL, ARG_PRINT_LOADER_PATH                       },
406
                { "print-stub-path",                         no_argument,       NULL, ARG_PRINT_STUB_PATH                         },
407
                { "print-root-device",                       no_argument,       NULL, 'R'                                         },
408
                { "variables",                               required_argument, NULL, ARG_VARIABLES                               },
409
                { "no-variables",                            no_argument,       NULL, ARG_NO_VARIABLES                            }, /* Compatibility alias */
410
                { "random-seed",                             required_argument, NULL, ARG_RANDOM_SEED                             },
411
                { "no-pager",                                no_argument,       NULL, ARG_NO_PAGER                                },
412
                { "graceful",                                no_argument,       NULL, ARG_GRACEFUL                                },
413
                { "quiet",                                   no_argument,       NULL, 'q'                                         },
414
                { "make-entry-directory",                    required_argument, NULL, ARG_MAKE_ENTRY_DIRECTORY                    },
415
                { "make-machine-id-directory",               required_argument, NULL, ARG_MAKE_ENTRY_DIRECTORY                    }, /* Compatibility alias */
416
                { "entry-token",                             required_argument, NULL, ARG_ENTRY_TOKEN                             },
417
                { "json",                                    required_argument, NULL, ARG_JSON                                    },
418
                { "all-architectures",                       no_argument,       NULL, ARG_ARCH_ALL                                },
419
                { "efi-boot-option-description",             required_argument, NULL, ARG_EFI_BOOT_OPTION_DESCRIPTION             },
420
                { "efi-boot-option-description-with-device", required_argument, NULL, ARG_EFI_BOOT_OPTION_DESCRIPTION_WITH_DEVICE },
421
                { "dry-run",                                 no_argument,       NULL, ARG_DRY_RUN                                 },
422
                { "secure-boot-auto-enroll",                 required_argument, NULL, ARG_SECURE_BOOT_AUTO_ENROLL                 },
423
                { "certificate",                             required_argument, NULL, ARG_CERTIFICATE                             },
424
                { "certificate-source",                      required_argument, NULL, ARG_CERTIFICATE_SOURCE                      },
425
                { "private-key",                             required_argument, NULL, ARG_PRIVATE_KEY                             },
426
                { "private-key-source",                      required_argument, NULL, ARG_PRIVATE_KEY_SOURCE                      },
427
                {}
428
        };
429

430
        int c, r;
297✔
431

432
        assert(argc >= 0);
297✔
433
        assert(argv);
297✔
434

435
        while ((c = getopt_long(argc, argv, "hpxRq", options, NULL)) >= 0)
728✔
436
                switch (c) {
437✔
437

438
                case 'h':
3✔
439
                        return help();
3✔
440

441
                case ARG_VERSION:
3✔
442
                        return version();
3✔
443

444
                case ARG_ESP_PATH:
3✔
445
                        r = free_and_strdup(&arg_esp_path, optarg);
3✔
446
                        if (r < 0)
3✔
UNCOV
447
                                return log_oom();
×
448
                        break;
449

450
                case ARG_BOOT_PATH:
3✔
451
                        r = free_and_strdup(&arg_xbootldr_path, optarg);
3✔
452
                        if (r < 0)
3✔
UNCOV
453
                                return log_oom();
×
454
                        break;
455

456
                case ARG_ROOT:
34✔
457
                        r = parse_path_argument(optarg, /* suppress_root= */ true, &arg_root);
34✔
458
                        if (r < 0)
34✔
459
                                return r;
460
                        break;
461

462
                case ARG_IMAGE:
29✔
463
                        r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image);
29✔
464
                        if (r < 0)
29✔
465
                                return r;
466
                        break;
467

UNCOV
468
                case ARG_IMAGE_POLICY:
×
UNCOV
469
                        r = parse_image_policy_argument(optarg, &arg_image_policy);
×
UNCOV
470
                        if (r < 0)
×
471
                                return r;
472
                        break;
473

474
                case ARG_INSTALL_SOURCE: {
×
UNCOV
475
                        InstallSource is = install_source_from_string(optarg);
×
476
                        if (is < 0)
×
477
                                return log_error_errno(is, "Unexpected parameter for --install-source=: %s", optarg);
×
478

UNCOV
479
                        arg_install_source = is;
×
UNCOV
480
                        break;
×
481
                }
482

483
                case 'p':
47✔
484
                        arg_print_esp_path = true;
47✔
485
                        break;
47✔
486

487
                case 'x':
8✔
488
                        arg_print_dollar_boot_path = true;
8✔
489
                        break;
8✔
490

UNCOV
491
                case ARG_PRINT_LOADER_PATH:
×
UNCOV
492
                        arg_print_loader_path = true;
×
UNCOV
493
                        break;
×
494

495
                case ARG_PRINT_STUB_PATH:
6✔
496
                        arg_print_stub_path = true;
6✔
497
                        break;
6✔
498

499
                case 'R':
7✔
500
                        arg_print_root_device++;
7✔
501
                        break;
7✔
502

503
                case ARG_VARIABLES:
118✔
504
                        r = parse_tristate_argument_with_auto("--variables=", optarg, &arg_touch_variables);
118✔
505
                        if (r < 0)
118✔
506
                                return r;
507
#if !ENABLE_EFI
508
                        if (arg_touch_variables > 0)
509
                                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
510
                                                       "Compiled without support for EFI, --variables=%s cannot be specified.", optarg);
511
#endif
512
                        break;
513

UNCOV
514
                case ARG_NO_VARIABLES:
×
515
                        arg_touch_variables = false;
×
516
                        break;
×
517

UNCOV
518
                case ARG_RANDOM_SEED:
×
UNCOV
519
                        r = parse_boolean_argument("--random-seed=", optarg, &arg_install_random_seed);
×
UNCOV
520
                        if (r < 0)
×
521
                                return r;
522
                        break;
523

UNCOV
524
                case ARG_NO_PAGER:
×
UNCOV
525
                        arg_pager_flags |= PAGER_DISABLE;
×
UNCOV
526
                        break;
×
527

528
                case ARG_GRACEFUL:
136✔
529
                        _arg_graceful = ARG_GRACEFUL_YES;
136✔
530
                        break;
136✔
531

532
                case 'q':
6✔
533
                        arg_quiet = true;
6✔
534
                        break;
6✔
535

UNCOV
536
                case ARG_ENTRY_TOKEN:
×
UNCOV
537
                        r = parse_boot_entry_token_type(optarg, &arg_entry_token_type, &arg_entry_token);
×
UNCOV
538
                        if (r < 0)
×
539
                                return r;
540
                        break;
541

542
                case ARG_MAKE_ENTRY_DIRECTORY:
13✔
543
                        if (streq(optarg, "auto"))  /* retained for backwards compatibility */
13✔
UNCOV
544
                                arg_make_entry_directory = -1; /* yes if machine-id is permanent */
×
545
                        else {
546
                                r = parse_boolean_argument("--make-entry-directory=", optarg, NULL);
13✔
547
                                if (r < 0)
13✔
548
                                        return r;
549

550
                                arg_make_entry_directory = r;
13✔
551
                        }
552
                        break;
553

554
                case ARG_JSON:
6✔
555
                        r = parse_json_argument(optarg, &arg_json_format_flags);
6✔
556
                        if (r <= 0)
6✔
557
                                return r;
558
                        break;
559

560
                case ARG_ARCH_ALL:
12✔
561
                        arg_arch_all = true;
12✔
562
                        break;
12✔
563

564
                case ARG_EFI_BOOT_OPTION_DESCRIPTION:
×
UNCOV
565
                        if (isempty(optarg) || !(string_is_safe(optarg) && utf8_is_valid(optarg))) {
×
UNCOV
566
                                _cleanup_free_ char *escaped = cescape(optarg);
×
567
                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
568
                                                       "Invalid --efi-boot-option-description=: %s", strna(escaped));
569
                        }
UNCOV
570
                        if (strlen(optarg) > EFI_BOOT_OPTION_DESCRIPTION_MAX)
×
571
                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
572
                                                       "--efi-boot-option-description= too long: %zu > %zu",
573
                                                       strlen(optarg), EFI_BOOT_OPTION_DESCRIPTION_MAX);
UNCOV
574
                        r = free_and_strdup_warn(&arg_efi_boot_option_description, optarg);
×
UNCOV
575
                        if (r < 0)
×
576
                                return r;
577
                        break;
578

UNCOV
579
                case ARG_EFI_BOOT_OPTION_DESCRIPTION_WITH_DEVICE:
×
UNCOV
580
                        r = parse_boolean_argument("--efi-boot-option-description-with-device=", optarg, &arg_efi_boot_option_description_with_device);
×
UNCOV
581
                        if (r < 0)
×
582
                                return r;
583

584
                        break;
585

UNCOV
586
                case ARG_DRY_RUN:
×
UNCOV
587
                        arg_dry_run = true;
×
UNCOV
588
                        break;
×
589

590
                case ARG_SECURE_BOOT_AUTO_ENROLL:
1✔
591
                        r = parse_boolean_argument("--secure-boot-auto-enroll=", optarg, &arg_secure_boot_auto_enroll);
1✔
592
                        if (r < 0)
1✔
593
                                return r;
594
                        break;
595

596
                case ARG_CERTIFICATE:
1✔
597
                        r = free_and_strdup_warn(&arg_certificate, optarg);
1✔
598
                        if (r < 0)
1✔
599
                                return r;
600
                        break;
601

UNCOV
602
                case ARG_CERTIFICATE_SOURCE:
×
UNCOV
603
                        r = parse_openssl_certificate_source_argument(
×
604
                                        optarg,
605
                                        &arg_certificate_source,
606
                                        &arg_certificate_source_type);
UNCOV
607
                        if (r < 0)
×
608
                                return r;
609
                        break;
610

611
                case ARG_PRIVATE_KEY: {
1✔
612
                        r = free_and_strdup_warn(&arg_private_key, optarg);
1✔
613
                        if (r < 0)
1✔
614
                                return r;
615
                        break;
616
                }
617

UNCOV
618
                case ARG_PRIVATE_KEY_SOURCE:
×
UNCOV
619
                        r = parse_openssl_key_source_argument(
×
620
                                        optarg,
621
                                        &arg_private_key_source,
622
                                        &arg_private_key_source_type);
UNCOV
623
                        if (r < 0)
×
624
                                return r;
625
                        break;
626

627
                case '?':
628
                        return -EINVAL;
629

UNCOV
630
                default:
×
UNCOV
631
                        assert_not_reached();
×
632
                }
633

634
        if (!!arg_print_esp_path + !!arg_print_dollar_boot_path + (arg_print_root_device > 0) + arg_print_loader_path + arg_print_stub_path > 1)
291✔
UNCOV
635
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
636
                                                       "--print-esp-path/-p, --print-boot-path/-x, --print-root-device=/-R, --print-loader-path, --print-stub-path cannot be combined.");
637

638
        if ((arg_root || arg_image) && argv[optind] && !STR_IN_SET(argv[optind], "status", "list",
291✔
639
                        "install", "update", "remove", "is-installed", "random-seed", "unlink", "cleanup"))
UNCOV
640
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
641
                                       "Options --root= and --image= are not supported with verb %s.",
642
                                       argv[optind]);
643

644
        if (arg_root && arg_image)
291✔
645
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Please specify either --root= or --image=, the combination of both is not supported.");
×
646

647
        if (arg_install_source != INSTALL_SOURCE_AUTO && !arg_root && !arg_image)
291✔
648
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--install-from-host is only supported with --root= or --image=.");
×
649

650
        if (arg_dry_run && argv[optind] && !STR_IN_SET(argv[optind], "unlink", "cleanup"))
291✔
UNCOV
651
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--dry-run is only supported with --unlink or --cleanup");
×
652

653
        if (arg_secure_boot_auto_enroll) {
291✔
654
#if HAVE_OPENSSL
655
                if (!arg_certificate)
1✔
656
                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Secure boot auto-enrollment requested but no certificate provided.");
×
657

658
                if (!arg_private_key)
1✔
UNCOV
659
                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Secure boot auto-enrollment requested but no private key provided.");
×
660
#else
661
                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Secure boot auto-enrollment requested but OpenSSL support is disabled.");
662
#endif
663
        }
664

665
        r = sd_varlink_invocation(SD_VARLINK_ALLOW_ACCEPT);
291✔
666
        if (r < 0)
291✔
UNCOV
667
                return log_error_errno(r, "Failed to check if invoked in Varlink mode: %m");
×
668
        if (r > 0) {
291✔
669
                arg_varlink = true;
14✔
670
                arg_pager_flags |= PAGER_DISABLE;
14✔
671
        }
672

673
        return 1;
674
}
675

676
static int bootctl_main(int argc, char *argv[]) {
266✔
677
        static const Verb verbs[] = {
266✔
678
                { "help",                VERB_ANY, VERB_ANY, 0,            verb_help                },
679
                { "status",              VERB_ANY, 1,        VERB_DEFAULT, verb_status              },
680
                { "install",             VERB_ANY, 1,        0,            verb_install             },
681
                { "update",              VERB_ANY, 1,        0,            verb_install             },
682
                { "remove",              VERB_ANY, 1,        0,            verb_remove              },
683
                { "is-installed",        VERB_ANY, 1,        0,            verb_is_installed        },
684
                { "kernel-identify",     2,        2,        0,            verb_kernel_identify     },
685
                { "kernel-inspect",      2,        2,        0,            verb_kernel_inspect      },
686
                { "list",                VERB_ANY, 1,        0,            verb_list                },
687
                { "unlink",              2,        2,        0,            verb_unlink              },
688
                { "cleanup",             VERB_ANY, 1,        0,            verb_cleanup             },
689
                { "set-default",         2,        2,        0,            verb_set_efivar          },
690
                { "set-preferred",       2,        2,        0,            verb_set_efivar          },
691
                { "set-oneshot",         2,        2,        0,            verb_set_efivar          },
692
                { "set-timeout",         2,        2,        0,            verb_set_efivar          },
693
                { "set-timeout-oneshot", 2,        2,        0,            verb_set_efivar          },
694
                { "set-sysfail",         2,        2,        0,            verb_set_efivar          },
695
                { "random-seed",         VERB_ANY, 1,        0,            verb_random_seed         },
696
                { "reboot-to-firmware",  VERB_ANY, 2,        0,            verb_reboot_to_firmware  },
697
                {}
698
        };
699

700
        return dispatch_verb(argc, argv, verbs, NULL);
266✔
701
}
702

703
static int vl_server(void) {
14✔
704
        _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_server = NULL;
14✔
705
        int r;
14✔
706

707
        /* Invocation as Varlink service */
708

709
        r = varlink_server_new(
14✔
710
                        &varlink_server,
711
                        SD_VARLINK_SERVER_ROOT_ONLY|SD_VARLINK_SERVER_ALLOW_FD_PASSING_INPUT,
712
                        /* userdata= */ NULL);
713
        if (r < 0)
14✔
UNCOV
714
                return log_error_errno(r, "Failed to allocate Varlink server: %m");
×
715

716
        r = sd_varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_BootControl);
14✔
717
        if (r < 0)
14✔
UNCOV
718
                return log_error_errno(r, "Failed to add Varlink interface: %m");
×
719

720
        r = sd_varlink_server_bind_method_many(
14✔
721
                        varlink_server,
722
                        "io.systemd.BootControl.ListBootEntries",     vl_method_list_boot_entries,
723
                        "io.systemd.BootControl.SetRebootToFirmware", vl_method_set_reboot_to_firmware,
724
                        "io.systemd.BootControl.GetRebootToFirmware", vl_method_get_reboot_to_firmware,
725
                        "io.systemd.BootControl.Install",             vl_method_install);
726
        if (r < 0)
14✔
UNCOV
727
                return log_error_errno(r, "Failed to bind Varlink methods: %m");
×
728

729
        r = sd_varlink_server_loop_auto(varlink_server);
14✔
730
        if (r < 0)
14✔
UNCOV
731
                return log_error_errno(r, "Failed to run Varlink event loop: %m");
×
732

733
        return 0;
734
}
735

736
static int run(int argc, char *argv[]) {
297✔
737
        _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
297✔
738
        _cleanup_(umount_and_freep) char *mounted_dir = NULL;
297✔
739
        int r;
297✔
740

741
        log_setup();
297✔
742

743
        r = parse_argv(argc, argv);
297✔
744
        if (r <= 0)
297✔
745
                return r;
746

747
        if (arg_varlink)
291✔
748
                return vl_server();
14✔
749

750
        if (arg_print_root_device > 0) {
277✔
751
                _cleanup_free_ char *path = NULL;
5✔
752
                dev_t devno;
5✔
753

754
                r = blockdev_get_root(LOG_ERR, &devno);
5✔
755
                if (r < 0)
5✔
756
                        return r;
757
                if (r == 0) {
5✔
UNCOV
758
                        log_error("Root file system not backed by a (single) whole block device.");
×
UNCOV
759
                        return 80; /* some recognizable error code */
×
760
                }
761

762
                if (arg_print_root_device > 1) {
5✔
763
                        r = block_get_whole_disk(devno, &devno);
2✔
764
                        if (r < 0)
2✔
UNCOV
765
                                log_debug_errno(r, "Unable to find whole block device for root block device, ignoring: %m");
×
766
                }
767

768
                r = device_path_make_canonical(S_IFBLK, devno, &path);
5✔
769
                if (r < 0)
5✔
UNCOV
770
                        return log_error_errno(r,
×
771
                                               "Failed to format canonical device path for devno '" DEVNUM_FORMAT_STR "': %m",
772
                                               DEVNUM_FORMAT_VAL(devno));
773

774
                puts(path);
5✔
775
                return 0;
776
        }
777

778
        if (arg_print_loader_path || arg_print_stub_path)
272✔
779
                return print_loader_or_stub_path();
6✔
780

781
        /* Open up and mount the image */
782
        if (arg_image) {
266✔
783
                assert(!arg_root);
26✔
784

785
                r = mount_image_privately_interactively(
26✔
786
                                arg_image,
787
                                arg_image_policy,
788
                                DISSECT_IMAGE_GENERIC_ROOT |
789
                                DISSECT_IMAGE_USR_NO_ROOT |
790
                                DISSECT_IMAGE_RELAX_VAR_CHECK |
791
                                DISSECT_IMAGE_ALLOW_USERSPACE_VERITY,
792
                                &mounted_dir,
793
                                /* ret_dir_fd= */ NULL,
794
                                &loop_device);
795
                if (r < 0)
26✔
796
                        return r;
797

798
                arg_root = strdup(mounted_dir);
26✔
799
                if (!arg_root)
26✔
UNCOV
800
                        return log_oom();
×
801
        }
802

803
        return bootctl_main(argc, argv);
266✔
804
}
805

806
DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);
297✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc