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