summaryrefslogtreecommitdiff
path: root/src/fstab-generator
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-07-17 10:02:54 +0200
committerGitHub <noreply@github.com>2017-07-17 10:02:54 +0200
commit981778e2126e8c8e6c918948d60dcbb64a8f24ec (patch)
treea09a394db3916ef2d8459de49d640d78a5d90420 /src/fstab-generator
parent7398320f9a6751bdce4334fbe27c050bfec7c6ac (diff)
parent1256c4814f9ff0a1d31fcdf1463bcb25a77adf9e (diff)
downloadsystemd-981778e2126e8c8e6c918948d60dcbb64a8f24ec.tar.gz
Merge pull request #6324 from keszybz/generator-add-symlink
Add helper function for creation of unit symlinks in generators
Diffstat (limited to 'src/fstab-generator')
-rw-r--r--src/fstab-generator/fstab-generator.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 7f23b9fd74..ea5ceb39ca 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -92,7 +92,7 @@ static int add_swap(
bool noauto,
bool nofail) {
- _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL;
+ _cleanup_free_ char *name = NULL, *unit = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
@@ -149,14 +149,10 @@ static int add_swap(
return r;
if (!noauto) {
- lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET,
- nofail ? ".wants/" : ".requires/", name, NULL);
- if (!lnk)
- return log_oom();
-
- mkdir_parents_label(lnk, 0755);
- if (symlink(unit, lnk) < 0)
- return log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
+ r = generator_add_symlink(arg_dest, SPECIAL_SWAP_TARGET,
+ nofail ? "wants" : "requires", name);
+ if (r < 0)
+ return r;
}
return 0;
@@ -302,7 +298,7 @@ static int add_mount(
const char *source) {
_cleanup_free_ char
- *name = NULL, *unit = NULL, *lnk = NULL,
+ *name = NULL, *unit = NULL,
*automount_name = NULL, *automount_unit = NULL,
*filtered = NULL;
_cleanup_fclose_ FILE *f = NULL;
@@ -431,13 +427,10 @@ static int add_mount(
return log_error_errno(r, "Failed to write unit file %s: %m", unit);
if (!noauto && !automount) {
- lnk = strjoin(dest, "/", post, nofail ? ".wants/" : ".requires/", name);
- if (!lnk)
- return log_oom();
-
- mkdir_parents_label(lnk, 0755);
- if (symlink(unit, lnk) < 0)
- return log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
+ r = generator_add_symlink(dest, post,
+ nofail ? "wants" : "requires", name);
+ if (r < 0)
+ return r;
}
if (automount) {
@@ -492,14 +485,10 @@ static int add_mount(
if (r < 0)
return log_error_errno(r, "Failed to write unit file %s: %m", automount_unit);
- free(lnk);
- lnk = strjoin(dest, "/", post, nofail ? ".wants/" : ".requires/", automount_name);
- if (!lnk)
- return log_oom();
-
- mkdir_parents_label(lnk, 0755);
- if (symlink(automount_unit, lnk) < 0)
- return log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
+ r = generator_add_symlink(dest, post,
+ nofail ? "wants" : "requires", automount_name);
+ if (r < 0)
+ return r;
}
return 0;