summaryrefslogtreecommitdiff
path: root/src/core/load-fragment.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/load-fragment.c')
-rw-r--r--src/core/load-fragment.c53
1 files changed, 18 insertions, 35 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index b7e848c08f..72c46371e4 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -2403,9 +2403,10 @@ static int merge_by_names(Unit **u, Set *names, const char *id) {
static int load_from_path(Unit *u, const char *path) {
int r;
- Set *symlink_names;
- FILE *f = NULL;
- char *filename = NULL, *id = NULL;
+ _cleanup_set_free_free_ Set *symlink_names = NULL;
+ _cleanup_fclose_ FILE *f = NULL;
+ _cleanup_free_ char *filename = NULL;
+ char *id = NULL;
Unit *merged;
struct stat st;
@@ -2419,10 +2420,8 @@ static int load_from_path(Unit *u, const char *path) {
if (path_is_absolute(path)) {
filename = strdup(path);
- if (!filename) {
- r = -ENOMEM;
- goto finish;
- }
+ if (!filename)
+ return -ENOMEM;
r = open_follow(&filename, &f, symlink_names, &id);
if (r < 0) {
@@ -2430,7 +2429,7 @@ static int load_from_path(Unit *u, const char *path) {
filename = NULL;
if (r != -ENOENT)
- goto finish;
+ return r;
}
} else {
@@ -2442,10 +2441,8 @@ static int load_from_path(Unit *u, const char *path) {
* follow all symlinks and add their name to our unit
* name set while doing so */
filename = path_make_absolute(path, *p);
- if (!filename) {
- r = -ENOMEM;
- goto finish;
- }
+ if (!filename)
+ return -ENOMEM;
if (u->manager->unit_path_cache &&
!set_get(u->manager->unit_path_cache, filename))
@@ -2458,7 +2455,7 @@ static int load_from_path(Unit *u, const char *path) {
filename = NULL;
if (r != -ENOENT)
- goto finish;
+ return r;
/* Empty the symlink names for the next run */
set_clear_free(symlink_names);
@@ -2469,27 +2466,22 @@ static int load_from_path(Unit *u, const char *path) {
}
}
- if (!filename) {
+ if (!filename)
/* Hmm, no suitable file found? */
- r = 0;
- goto finish;
- }
+ return 0;
merged = u;
r = merge_by_names(&merged, symlink_names, id);
if (r < 0)
- goto finish;
+ return r;
if (merged != u) {
u->load_state = UNIT_MERGED;
- r = 0;
- goto finish;
+ return 0;
}
- if (fstat(fileno(f), &st) < 0) {
- r = -errno;
- goto finish;
- }
+ if (fstat(fileno(f), &st) < 0)
+ return -errno;
if (null_or_empty(&st))
u->load_state = UNIT_MASKED;
@@ -2501,7 +2493,7 @@ static int load_from_path(Unit *u, const char *path) {
config_item_perf_lookup,
(void*) load_fragment_gperf_lookup, false, true, u);
if (r < 0)
- goto finish;
+ return r;
}
free(u->fragment_path);
@@ -2517,16 +2509,7 @@ static int load_from_path(Unit *u, const char *path) {
u->source_mtime = 0;
}
- r = 0;
-
-finish:
- set_free_free(symlink_names);
- free(filename);
-
- if (f)
- fclose(f);
-
- return r;
+ return 0;
}
int unit_load_fragment(Unit *u) {