aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2013-09-16 01:08:32 +0200
committerMichał Górny <mgorny@gentoo.org>2013-09-18 12:29:09 +0200
commit0a74184d5bc2cb50360ccc9bc0238a421816417a (patch)
tree4fff42f7a9c161d85f544af52c310d7e45c08d00
parentswap: fix reverse dependencies (diff)
downloadsystemd-gentoo-207.tar.gz
systemd-gentoo-207.tar.bz2
systemd-gentoo-207.zip
swap: create .wants symlink to 'auto' swap devicesgentoo-207
As we load unit files lazily, we need to make sure something pulls in swap units that should be started automatically, otherwise the default dependencies will never be applied. This partially reinstates code removed in commit 64347fc2b983f33e7efb0fd2bb44e133fb9f30f4. Also don't order swap devices after swap.target when they are 'nofail'.
-rw-r--r--src/core/swap.c8
-rw-r--r--src/fstab-generator/fstab-generator.c18
2 files changed, 22 insertions, 4 deletions
diff --git a/src/core/swap.c b/src/core/swap.c
index 395086075..76c7d4500 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -220,8 +220,12 @@ static int swap_add_default_dependencies(Swap *s) {
}
if (!noauto) {
- r = unit_add_two_dependencies_by_name_inverse(UNIT(s), UNIT_AFTER, (nofail ? UNIT_WANTS : UNIT_REQUIRES),
- SPECIAL_SWAP_TARGET, NULL, true);
+ if (nofail)
+ r = unit_add_dependency_by_name_inverse(UNIT(s),
+ UNIT_WANTS, SPECIAL_SWAP_TARGET, NULL, true);
+ else
+ r = unit_add_two_dependencies_by_name_inverse(UNIT(s),
+ UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SWAP_TARGET, NULL, true);
if (r < 0)
return r;
}
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 6ebe8aa67..b73dfa489 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -66,6 +66,7 @@ static int mount_find_pri(struct mntent *me, int *ret) {
static int add_swap(const char *what, struct mntent *me) {
_cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL;
_cleanup_fclose_ FILE *f = NULL;
+ bool noauto;
int r, pri = -1;
assert(what);
@@ -77,6 +78,8 @@ static int add_swap(const char *what, struct mntent *me) {
return pri;
}
+ noauto = !!hasmntopt(me, "noauto");
+
name = unit_name_from_path(what, ".swap");
if (!name)
return log_oom();
@@ -97,8 +100,7 @@ static int add_swap(const char *what, struct mntent *me) {
fprintf(f,
"# Automatically generated by systemd-fstab-generator\n\n"
"[Unit]\n"
- "SourcePath=/etc/fstab\n"
- "\n"
+ "SourcePath=/etc/fstab\n\n"
"[Swap]\n"
"What=%s\n",
what);
@@ -114,6 +116,18 @@ static int add_swap(const char *what, struct mntent *me) {
return -errno;
}
+ if (!noauto) {
+ lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
+ if (!lnk)
+ return log_oom();
+
+ mkdir_parents_label(lnk, 0755);
+ if (symlink(unit, lnk) < 0) {
+ log_error("Failed to create symlink %s: %m", lnk);
+ return -errno;
+ }
+ }
+
return 0;
}