summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2013-08-21 22:48:56 +0800
committerTom Gundersen <teg@jklm.no>2013-09-11 14:43:24 +0200
commit64347fc2b983f33e7efb0fd2bb44e133fb9f30f4 (patch)
tree4dbaaccf37c9bf4904e7ccf15cfd94134c17bbe8 /src
parent88ac30a1979365a926bc85a9cd7150da85823077 (diff)
swap: handle nofail/noauto in core
Diffstat (limited to 'src')
-rw-r--r--src/core/swap.c15
-rw-r--r--src/fstab-generator/fstab-generator.c59
2 files changed, 18 insertions, 56 deletions
diff --git a/src/core/swap.c b/src/core/swap.c
index f0e19ad8c4..57d15eb34b 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -197,6 +197,7 @@ static int swap_add_device_links(Swap *s) {
}
static int swap_add_default_dependencies(Swap *s) {
+ bool nofail = false, noauto = false;
int r;
assert(s);
@@ -211,6 +212,20 @@ static int swap_add_default_dependencies(Swap *s) {
if (r < 0)
return r;
+ if (s->from_fragment) {
+ SwapParameters *p = &s->parameters_fragment;
+
+ nofail = p->nofail;
+ noauto = p->noauto;
+ }
+
+ if (!noauto) {
+ r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, (nofail ? UNIT_WANTED_BY : UNIT_REQUIRED_BY),
+ SPECIAL_SWAP_TARGET, NULL, true);
+ if (r < 0)
+ return r;
+ }
+
return 0;
}
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index e78001829b..6ebe8aa673 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -38,22 +38,6 @@
static const char *arg_dest = "/tmp";
static bool arg_enabled = true;
-static int device_name(const char *path, char **unit) {
- char *p;
-
- assert(path);
-
- if (!is_device_path(path))
- return 0;
-
- p = unit_name_from_path(path, ".device");
- if (!p)
- return log_oom();
-
- *unit = p;
- return 1;
-}
-
static int mount_find_pri(struct mntent *me, int *ret) {
char *end, *pri;
unsigned long r;
@@ -82,7 +66,6 @@ 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, nofail;
int r, pri = -1;
assert(what);
@@ -94,9 +77,6 @@ static int add_swap(const char *what, struct mntent *me) {
return pri;
}
- noauto = !!hasmntopt(me, "noauto");
- nofail = !!hasmntopt(me, "nofail");
-
name = unit_name_from_path(what, ".swap");
if (!name)
return log_oom();
@@ -114,14 +94,10 @@ static int add_swap(const char *what, struct mntent *me) {
return -errno;
}
- fputs("# Automatically generated by systemd-fstab-generator\n\n"
- "[Unit]\n"
- "SourcePath=/etc/fstab\n", f);
-
- if (!noauto && !nofail)
- fputs("Before=" SPECIAL_SWAP_TARGET "\n", f);
-
fprintf(f,
+ "# Automatically generated by systemd-fstab-generator\n\n"
+ "[Unit]\n"
+ "SourcePath=/etc/fstab\n"
"\n"
"[Swap]\n"
"What=%s\n",
@@ -138,35 +114,6 @@ 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;
- }
-
- r = device_name(what, &device);
- if (r < 0)
- return r;
-
- if (r > 0) {
- free(lnk);
- lnk = strjoin(arg_dest, "/", device, ".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;
}