daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
1ff636
From 306dfc00aefbd35197ca30469f4b40bb120caf91 Mon Sep 17 00:00:00 2001
1ff636
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
1ff636
Date: Wed, 6 May 2015 01:09:53 -0400
1ff636
Subject: [PATCH] Generate systemd-fsck-root.service in the initramfs
1ff636
1ff636
In the initrafms, generate a systemd-fsck-root.service to replace
1ff636
systemd-fsck@<sysroot-device>.service. This way, after we transition
1ff636
to the real root, systemd-fsck-root.service is marked as already done.
1ff636
1ff636
This introduces an unnecessary synchronization point, because
1ff636
systemd-fsck@* is ordered after systemd-fsck-root also in the
1ff636
initramfs. In practice this shouldn't be a problem.
1ff636
1ff636
https://bugzilla.redhat.com/show_bug.cgi?id=1201979
1ff636
1ff636
C.f. 956eaf2b8d6c9999024705ddadc7393bc707de02.
1ff636
1ff636
(cherry picked from commit 4dda4e637e4c17a14db6cd265f36f5e8a5050367)
1ff636
1ff636
Cherry-picked from: 4dda4e6
1ff636
Resolves: #1222517
1ff636
---
23b3cf
 src/shared/generator.c | 63 +++++++++++++++++++++++++++++++++++++++---
1ff636
 1 file changed, 59 insertions(+), 4 deletions(-)
1ff636
1ff636
diff --git a/src/shared/generator.c b/src/shared/generator.c
c62b8e
index cd37812f86..148a0b077b 100644
1ff636
--- a/src/shared/generator.c
1ff636
+++ b/src/shared/generator.c
1ff636
@@ -29,8 +29,51 @@
1ff636
 #include "generator.h"
1ff636
 #include "path-util.h"
1ff636
 #include "fstab-util.h"
1ff636
+#include "fileio.h"
1ff636
 #include "dropin.h"
1ff636
 
1ff636
+static int write_fsck_sysroot_service(const char *dir, const char *what) {
1ff636
+        const char *unit;
1ff636
+        _cleanup_free_ char *device = NULL;
1ff636
+        _cleanup_fclose_ FILE *f = NULL;
1ff636
+
1ff636
+        unit = strjoina(dir, "/systemd-fsck-root.service");
1ff636
+        log_debug("Creating %s", unit);
1ff636
+
1ff636
+        device = unit_name_from_path(what, ".device");
1ff636
+        if (!device)
1ff636
+                return log_oom();
1ff636
+
1ff636
+        f = fopen(unit, "wxe");
1ff636
+        if (!f)
1ff636
+                return log_error_errno(errno, "Failed to create unit file %s: %m", unit);
1ff636
+
1ff636
+        fprintf(f,
1ff636
+                "# Automatically generated by %1$s\n\n"
1ff636
+                "[Unit]\n"
1ff636
+                "Documentation=man:systemd-fsck-root.service(8)\n"
1ff636
+                "Description=File System Check on %2$s\n"
1ff636
+                "DefaultDependencies=no\n"
1ff636
+                "BindsTo=%3$s\n"
1ff636
+                "After=%3$s\n"
1ff636
+                "Before=shutdown.target\n"
1ff636
+                "\n"
1ff636
+                "[Service]\n"
1ff636
+                "Type=oneshot\n"
1ff636
+                "RemainAfterExit=yes\n"
1ff636
+                "ExecStart=/usr/lib/systemd/systemd-fsck %2$s\n"
1ff636
+                "TimeoutSec=0\n",
1ff636
+                program_invocation_short_name,
1ff636
+                what,
1ff636
+                device);
1ff636
+
1ff636
+        fflush(f);
1ff636
+        if (ferror(f))
1ff636
+                return log_error_errno(errno, "Failed to write unit file %s: %m", unit);
1ff636
+
1ff636
+        return 0;
1ff636
+}
1ff636
+
1ff636
 int generator_write_fsck_deps(
1ff636
                 FILE *f,
1ff636
                 const char *dir,
1ff636
@@ -69,11 +112,23 @@ int generator_write_fsck_deps(
1ff636
                         return log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
1ff636
 
1ff636
         } else {
1ff636
-                _cleanup_free_ char *fsck = NULL;
1ff636
+                _cleanup_free_ char *_fsck = NULL;
1ff636
+                const char *fsck;
1ff636
+                int r;
1ff636
+
1ff636
+                if (in_initrd() && path_equal(where, "/sysroot")) {
1ff636
+                        r = write_fsck_sysroot_service(dir, what);
1ff636
+                        if (r < 0)
1ff636
+                                return r;
1ff636
+
1ff636
+                        fsck = "systemd-fsck-root.service";
1ff636
+                } else {
1ff636
+                        _fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
1ff636
+                        if (!_fsck)
1ff636
+                                return log_oom();
1ff636
 
1ff636
-                fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
1ff636
-                if (!fsck)
1ff636
-                        return log_oom();
1ff636
+                        fsck = _fsck;
1ff636
+                }
1ff636
 
1ff636
                 fprintf(f,
1ff636
                         "RequiresOverridable=%1$s\n"