summaryrefslogtreecommitdiff
path: root/src/core/load-fragment.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-21 19:54:10 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-11-15 22:53:14 -0500
commite48614c4b268d9e7ecbd478d1d2410f9e92095e0 (patch)
treeda8b1d7fd759db5aa86d3f28f9b7ba065bdc5ce0 /src/core/load-fragment.c
parent94192cdaf652c9717f15274504ed315126c07a93 (diff)
core: some more _cleanup_free_
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) {