summaryrefslogtreecommitdiff
path: root/src/systemctl
diff options
context:
space:
mode:
authorIvan Shapovalov <intelfx100@gmail.com>2015-02-05 01:57:00 +0300
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-02-04 20:10:28 -0500
commitdab2bce81ed3e97d059d56e66f560aa25d9c2d63 (patch)
tree5b5d195c24ba0d39fb91d5cc1164598f0e7df4a4 /src/systemctl
parent029009d4970b2871dafab5fcc9397abb335263c8 (diff)
systemctl: unit_find_paths(): unify error handling in two code pathes
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 384ae02e8b..2d70ff1de6 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2293,6 +2293,9 @@ static int unit_find_paths(sd_bus *bus,
LookupPaths *lp,
char **fragment_path,
char ***dropin_paths) {
+
+ _cleanup_free_ char *path = NULL;
+ _cleanup_strv_free_ char **dropins = NULL;
int r;
/**
@@ -2311,8 +2314,6 @@ static int unit_find_paths(sd_bus *bus,
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *unit_load_error = NULL;
_cleanup_free_ char *unit = NULL;
- _cleanup_free_ char *path = NULL;
- _cleanup_strv_free_ char **dropins = NULL;
_cleanup_strv_free_ char **load_error = NULL;
char *unit_load_error_name, *unit_load_error_message;
@@ -2359,28 +2360,17 @@ static int unit_find_paths(sd_bus *bus,
if (r < 0)
return log_error_errno(r, "Failed to get FragmentPath: %s", bus_error_message(&error, r));
- r = sd_bus_get_property_strv(
- bus,
- "org.freedesktop.systemd1",
- unit,
- "org.freedesktop.systemd1.Unit",
- "DropInPaths",
- &error,
- &dropins);
- if (r < 0)
- return log_error_errno(r, "Failed to get DropInPaths: %s", bus_error_message(&error, r));
-
- r = 0;
- if (!isempty(path)) {
- *fragment_path = path;
- path = NULL;
- r = 1;
- }
-
- if (dropin_paths && !strv_isempty(dropins)) {
- *dropin_paths = dropins;
- dropins = NULL;
- r = 1;
+ if (dropin_paths) {
+ r = sd_bus_get_property_strv(
+ bus,
+ "org.freedesktop.systemd1",
+ unit,
+ "org.freedesktop.systemd1.Unit",
+ "DropInPaths",
+ &error,
+ &dropins);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get DropInPaths: %s", bus_error_message(&error, r));
}
} else {
_cleanup_set_free_ Set *names;
@@ -2393,7 +2383,7 @@ static int unit_find_paths(sd_bus *bus,
if (r < 0)
return r;
- r = unit_file_find_path(lp, unit_name, fragment_path);
+ r = unit_file_find_path(lp, unit_name, &path);
if (r < 0)
return r;
@@ -2405,14 +2395,31 @@ static int unit_find_paths(sd_bus *bus,
return log_oom();
if (!streq(template, unit_name)) {
- r = unit_file_find_path(lp, template, fragment_path);
+ r = unit_file_find_path(lp, template, &path);
if (r < 0)
return r;
}
}
- if (dropin_paths)
- r = unit_file_find_dropin_paths(lp->unit_path, NULL, names, dropin_paths);
+ if (dropin_paths) {
+ r = unit_file_find_dropin_paths(lp->unit_path, NULL, names, &dropins);
+ if (r < 0)
+ return r;
+ }
+ }
+
+ r = 0;
+
+ if (!isempty(path)) {
+ *fragment_path = path;
+ path = NULL;
+ r = 1;
+ }
+
+ if (dropin_paths && !strv_isempty(dropins)) {
+ *dropin_paths = dropins;
+ dropins = NULL;
+ r = 1;
}
if (r == 0)