summaryrefslogtreecommitdiff
path: root/src/systemctl/systemctl.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-12-16 00:28:43 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-12-16 00:30:34 -0500
commit8df1850740f2b78407b856e32ba649a7037227d4 (patch)
tree4561282231e2da4bf01ff643655048059e3da850 /src/systemctl/systemctl.c
parent33f6c497f3f2da15b94da9140f77aefac92e2866 (diff)
systemctl: split out LookupPaths initialization
Diffstat (limited to 'src/systemctl/systemctl.c')
-rw-r--r--src/systemctl/systemctl.c54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index d16c673dcd..68cb71c585 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4668,6 +4668,38 @@ static int show(sd_bus *bus, char **args) {
return ret;
}
+static int init_home_and_lookup_paths(char **user_home, char **user_runtime, LookupPaths *lp) {
+ int r;
+
+ assert(user_home);
+ assert(user_runtime);
+ assert(lp);
+
+ if (arg_scope == UNIT_FILE_USER) {
+ r = user_config_home(user_home);
+ if (r < 0)
+ return log_error_errno(r, "Failed to query XDG_CONFIG_HOME: %m");
+ else if (r == 0)
+ return log_error_errno(ENOTDIR, "Cannot find units: $XDG_CONFIG_HOME and $HOME are not set.");
+
+ r = user_runtime_dir(user_runtime);
+ if (r < 0)
+ return log_error_errno(r, "Failed to query XDG_CONFIG_HOME: %m");
+ else if (r == 0)
+ return log_error_errno(ENOTDIR, "Cannot find units: $XDG_RUNTIME_DIR is not set.");
+ }
+
+ r = lookup_paths_init(lp,
+ arg_scope == UNIT_FILE_SYSTEM ? SYSTEMD_SYSTEM : SYSTEMD_USER,
+ arg_scope == UNIT_FILE_USER,
+ arg_root,
+ NULL, NULL, NULL);
+ if (r < 0)
+ return log_error_errno(r, "Failed to lookup unit lookup paths: %m");
+
+ return 0;
+}
+
static int cat(sd_bus *bus, char **args) {
_cleanup_strv_free_ char **names = NULL;
char **name;
@@ -6105,27 +6137,9 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) {
assert(names);
assert(paths);
- if (arg_scope == UNIT_FILE_USER) {
- r = user_config_home(&user_home);
- if (r < 0)
- return log_error_errno(r, "Failed to query XDG_CONFIG_HOME: %m");
- else if (r == 0)
- return log_error_errno(ENOTDIR, "Cannot edit units: $XDG_CONFIG_HOME and $HOME are not set.");
-
- r = user_runtime_dir(&user_runtime);
- if (r < 0)
- return log_error_errno(r, "Failed to query XDG_CONFIG_HOME: %m");
- else if (r == 0)
- return log_error_errno(ENOTDIR, "Cannot edit units: $XDG_RUNTIME_DIR is not set.");
- }
-
- r = lookup_paths_init(&lp,
- arg_scope == UNIT_FILE_SYSTEM ? SYSTEMD_SYSTEM : SYSTEMD_USER,
- arg_scope == UNIT_FILE_USER,
- arg_root,
- NULL, NULL, NULL);
+ r = init_home_and_lookup_paths(&user_home, &user_runtime, &lp);
if (r < 0)
- return log_error_errno(r, "Failed get lookup paths: %m");
+ return r;
avoid_bus_cache = !bus || avoid_bus();