]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/boot/bless-boot-generator.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
12 #include "string-util.h"
16 /* This generator pulls systemd-bless-boot.service into the initial transaction if the "LoaderBootCountPath" EFI
17 * variable is set, i.e. the system boots up with boot counting in effect, which means we should mark the boot as
18 * "good" if we manage to boot up far enough. */
20 static const char *arg_dest
= "/tmp";
22 int main(int argc
, char *argv
[]) {
25 log_setup_generator();
29 if (argc
> 1 && argc
!= 4) {
30 log_error("This program takes three or no arguments.");
37 if (in_initrd() > 0) {
38 log_debug("Skipping generator, running in the initrd.");
42 if (detect_container() > 0) {
43 log_debug("Skipping generator, running in a container.");
48 log_debug("Skipping generator, not an EFI boot.");
52 if (access("/sys/firmware/efi/efivars/LoaderBootCountPath-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f", F_OK
) < 0) {
54 if (errno
== ENOENT
) {
55 log_debug_errno(errno
, "Skipping generator, not booted with boot counting in effect.");
59 log_error_errno(errno
, "Failed to check if LoaderBootCountPath EFI variable exists: %m");
63 /* We pull this in from basic.target so that it ends up in all "regular" boot ups, but not in rescue.target or
64 * even emergency.target. */
65 p
= strjoina(arg_dest
, "/" SPECIAL_BASIC_TARGET
".wants/systemd-bless-boot.service");
66 (void) mkdir_parents(p
, 0755);
67 if (symlink(SYSTEM_DATA_UNIT_PATH
"/systemd-bless-boot.service", p
) < 0) {
68 log_error_errno(errno
, "Failed to create symlink '%s': %m", p
);