X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsystemctl%2Fsystemctl.c;h=68cb71c585b455c9805a7931a0df4f97b7bdcd1b;hp=d16c673dcd4a772e2b460269b80db1421f3aa426;hb=8df1850740f2b78407b856e32ba649a7037227d4;hpb=33f6c497f3f2da15b94da9140f77aefac92e2866 diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index d16c673dc..68cb71c58 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();