ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
a4b143
From c1f9c15f319f7dfb96bcbf2c3cf879f2b4457350 Mon Sep 17 00:00:00 2001
a4b143
From: Tom Gundersen <teg@jklm.no>
a4b143
Date: Mon, 16 Sep 2013 01:08:32 +0200
a4b143
Subject: [PATCH] swap: create .wants symlink to 'auto' swap devices
a4b143
a4b143
As we load unit files lazily, we need to make sure something pulls in swap
a4b143
units that should be started automatically, otherwise the default dependencies
a4b143
will never be applied.
a4b143
a4b143
This partially reinstates code removed in
a4b143
commit 64347fc2b983f33e7efb0fd2bb44e133fb9f30f4.
a4b143
a4b143
Also don't order swap devices after swap.target when they are 'nofail'.
a4b143
---
a4b143
 src/core/swap.c                       |  8 ++++++--
a4b143
 src/fstab-generator/fstab-generator.c | 18 ++++++++++++++++--
a4b143
 2 files changed, 22 insertions(+), 4 deletions(-)
a4b143
a4b143
diff --git a/src/core/swap.c b/src/core/swap.c
a4b143
index 3950860..76c7d45 100644
a4b143
--- a/src/core/swap.c
a4b143
+++ b/src/core/swap.c
a4b143
@@ -220,8 +220,12 @@ static int swap_add_default_dependencies(Swap *s) {
a4b143
         }
a4b143
 
a4b143
         if (!noauto) {
a4b143
-                r = unit_add_two_dependencies_by_name_inverse(UNIT(s), UNIT_AFTER, (nofail ? UNIT_WANTS : UNIT_REQUIRES),
a4b143
-                                                      SPECIAL_SWAP_TARGET, NULL, true);
a4b143
+                if (nofail)
a4b143
+                        r = unit_add_dependency_by_name_inverse(UNIT(s),
a4b143
+                                UNIT_WANTS, SPECIAL_SWAP_TARGET, NULL, true);
a4b143
+                else
a4b143
+                        r = unit_add_two_dependencies_by_name_inverse(UNIT(s),
a4b143
+                                UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SWAP_TARGET, NULL, true);
a4b143
                 if (r < 0)
a4b143
                         return r;
a4b143
         }
a4b143
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
a4b143
index 6ebe8aa..b73dfa4 100644
a4b143
--- a/src/fstab-generator/fstab-generator.c
a4b143
+++ b/src/fstab-generator/fstab-generator.c
a4b143
@@ -66,6 +66,7 @@ static int mount_find_pri(struct mntent *me, int *ret) {
a4b143
 static int add_swap(const char *what, struct mntent *me) {
a4b143
         _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL;
a4b143
         _cleanup_fclose_ FILE *f = NULL;
a4b143
+        bool noauto;
a4b143
         int r, pri = -1;
a4b143
 
a4b143
         assert(what);
a4b143
@@ -77,6 +78,8 @@ static int add_swap(const char *what, struct mntent *me) {
a4b143
                 return pri;
a4b143
         }
a4b143
 
a4b143
+        noauto = !!hasmntopt(me, "noauto");
a4b143
+
a4b143
         name = unit_name_from_path(what, ".swap");
a4b143
         if (!name)
a4b143
                 return log_oom();
a4b143
@@ -97,8 +100,7 @@ static int add_swap(const char *what, struct mntent *me) {
a4b143
         fprintf(f,
a4b143
                 "# Automatically generated by systemd-fstab-generator\n\n"
a4b143
                 "[Unit]\n"
a4b143
-                "SourcePath=/etc/fstab\n"
a4b143
-                "\n"
a4b143
+                "SourcePath=/etc/fstab\n\n"
a4b143
                 "[Swap]\n"
a4b143
                 "What=%s\n",
a4b143
                 what);
a4b143
@@ -114,6 +116,18 @@ static int add_swap(const char *what, struct mntent *me) {
a4b143
                 return -errno;
a4b143
         }
a4b143
 
a4b143
+        if (!noauto) {
a4b143
+                lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
a4b143
+                if (!lnk)
a4b143
+                        return log_oom();
a4b143
+
a4b143
+                mkdir_parents_label(lnk, 0755);
a4b143
+                if (symlink(unit, lnk) < 0) {
a4b143
+                        log_error("Failed to create symlink %s: %m", lnk);
a4b143
+                        return -errno;
a4b143
+                }
a4b143
+        }
a4b143
+
a4b143
         return 0;
a4b143
 }
a4b143