bless-boot-generator: use generator_add_symlink
authorMike Yuan <me@yhndnzj.com>
Wed, 10 Apr 2024 14:51:31 +0000 (22:51 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 10 Apr 2024 15:40:53 +0000 (23:40 +0800)
src/boot/bless-boot-generator.c

index 38b2c3ad7cd87ec3375b37270c29c78b393a0581..cf645e2416cecaa7226dcd4a064147dcd88be614 100644 (file)
@@ -7,7 +7,6 @@
 #include "generator.h"
 #include "initrd-util.h"
 #include "log.h"
-#include "mkdir.h"
 #include "special.h"
 #include "string-util.h"
 #include "virt.h"
@@ -17,6 +16,7 @@
  * boot as "good" if we manage to boot up far enough. */
 
 static int run(const char *dest, const char *dest_early, const char *dest_late) {
+        assert(dest_early);
 
         if (in_initrd()) {
                 log_debug("Skipping generator, running in the initrd.");
@@ -34,7 +34,6 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
         }
 
         if (access(EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderBootCountPath)), F_OK) < 0) {
-
                 if (errno == ENOENT) {
                         log_debug_errno(errno, "Skipping generator, not booted with boot counting in effect.");
                         return 0;
@@ -45,12 +44,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
 
         /* We pull this in from basic.target so that it ends up in all "regular" boot ups, but not in
          * rescue.target or even emergency.target. */
-        const char *p = strjoina(dest_early, "/" SPECIAL_BASIC_TARGET ".wants/systemd-bless-boot.service");
-        (void) mkdir_parents(p, 0755);
-        if (symlink(SYSTEM_DATA_UNIT_DIR "/systemd-bless-boot.service", p) < 0)
-                return log_error_errno(errno, "Failed to create symlink '%s': %m", p);
-
-        return 0;
+        return generator_add_symlink(dest_early, SPECIAL_BASIC_TARGET, "wants", "systemd-bless-boot.service");
 }
 
 DEFINE_MAIN_GENERATOR_FUNCTION(run);