DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(unit_file_type, UnitFileType);
-static int in_search_path(const LookupPaths *p, const char *path) {
+static int in_search_path(const LookupPaths *lp, const char *path) {
_cleanup_free_ char *parent = NULL;
assert(path);
if (!parent)
return -ENOMEM;
- return path_strv_contains(p->search_path, parent);
+ return path_strv_contains(lp->search_path, parent);
}
-static const char* skip_root(const LookupPaths *p, const char *path) {
- char *e;
-
- assert(p);
+static const char* skip_root(const char *root_dir, const char *path) {
assert(path);
- if (!p->root_dir)
+ if (!root_dir)
return path;
- e = path_startswith(path, p->root_dir);
+ const char *e = path_startswith(path, root_dir);
if (!e)
return NULL;
return e;
}
-static int path_is_generator(const LookupPaths *p, const char *path) {
+static int path_is_generator(const LookupPaths *lp, const char *path) {
_cleanup_free_ char *parent = NULL;
- assert(p);
+ assert(lp);
assert(path);
parent = dirname_malloc(path);
if (!parent)
return -ENOMEM;
- return path_equal_ptr(parent, p->generator) ||
- path_equal_ptr(parent, p->generator_early) ||
- path_equal_ptr(parent, p->generator_late);
+ return path_equal_ptr(parent, lp->generator) ||
+ path_equal_ptr(parent, lp->generator_early) ||
+ path_equal_ptr(parent, lp->generator_late);
}
-static int path_is_transient(const LookupPaths *p, const char *path) {
+static int path_is_transient(const LookupPaths *lp, const char *path) {
_cleanup_free_ char *parent = NULL;
- assert(p);
+ assert(lp);
assert(path);
parent = dirname_malloc(path);
if (!parent)
return -ENOMEM;
- return path_equal_ptr(parent, p->transient);
+ return path_equal_ptr(parent, lp->transient);
}
-static int path_is_control(const LookupPaths *p, const char *path) {
+static int path_is_control(const LookupPaths *lp, const char *path) {
_cleanup_free_ char *parent = NULL;
- assert(p);
+ assert(lp);
assert(path);
parent = dirname_malloc(path);
if (!parent)
return -ENOMEM;
- return path_equal_ptr(parent, p->persistent_control) ||
- path_equal_ptr(parent, p->runtime_control);
+ return path_equal_ptr(parent, lp->persistent_control) ||
+ path_equal_ptr(parent, lp->runtime_control);
}
-static int path_is_config(const LookupPaths *p, const char *path, bool check_parent) {
+static int path_is_config(const LookupPaths *lp, const char *path, bool check_parent) {
_cleanup_free_ char *parent = NULL;
- assert(p);
+ assert(lp);
assert(path);
/* Note that we do *not* have generic checks for /etc or /run in place, since with
path = parent;
}
- return path_equal_ptr(path, p->persistent_config) ||
- path_equal_ptr(path, p->runtime_config);
+ return path_equal_ptr(path, lp->persistent_config) ||
+ path_equal_ptr(path, lp->runtime_config);
}
-static int path_is_runtime(const LookupPaths *p, const char *path, bool check_parent) {
+static int path_is_runtime(const LookupPaths *lp, const char *path, bool check_parent) {
_cleanup_free_ char *parent = NULL;
const char *rpath;
- assert(p);
+ assert(lp);
assert(path);
/* Everything in /run is considered runtime. On top of that we also add
* explicit checks for the various runtime directories, as safety net. */
- rpath = skip_root(p, path);
+ rpath = skip_root(lp->root_dir, path);
if (rpath && path_startswith(rpath, "/run"))
return true;
path = parent;
}
- return path_equal_ptr(path, p->runtime_config) ||
- path_equal_ptr(path, p->generator) ||
- path_equal_ptr(path, p->generator_early) ||
- path_equal_ptr(path, p->generator_late) ||
- path_equal_ptr(path, p->transient) ||
- path_equal_ptr(path, p->runtime_control);
+ return path_equal_ptr(path, lp->runtime_config) ||
+ path_equal_ptr(path, lp->generator) ||
+ path_equal_ptr(path, lp->generator_early) ||
+ path_equal_ptr(path, lp->generator_late) ||
+ path_equal_ptr(path, lp->transient) ||
+ path_equal_ptr(path, lp->runtime_control);
}
-static int path_is_vendor_or_generator(const LookupPaths *p, const char *path) {
+static int path_is_vendor_or_generator(const LookupPaths *lp, const char *path) {
const char *rpath;
- assert(p);
+ assert(lp);
assert(path);
- rpath = skip_root(p, path);
+ rpath = skip_root(lp->root_dir, path);
if (!rpath)
return 0;
return true;
#endif
- if (path_is_generator(p, rpath))
+ if (path_is_generator(lp, rpath))
return true;
return path_equal(rpath, SYSTEM_DATA_UNIT_DIR);
}
-static const char* config_path_from_flags(const LookupPaths *paths, UnitFileFlags flags) {
- assert(paths);
+static const char* config_path_from_flags(const LookupPaths *lp, UnitFileFlags flags) {
+ assert(lp);
if (FLAGS_SET(flags, UNIT_FILE_PORTABLE))
- return FLAGS_SET(flags, UNIT_FILE_RUNTIME) ? paths->runtime_attached : paths->persistent_attached;
+ return FLAGS_SET(flags, UNIT_FILE_RUNTIME) ? lp->runtime_attached : lp->persistent_attached;
else
- return FLAGS_SET(flags, UNIT_FILE_RUNTIME) ? paths->runtime_config : paths->persistent_config;
+ return FLAGS_SET(flags, UNIT_FILE_RUNTIME) ? lp->runtime_config : lp->persistent_config;
}
int unit_file_changes_add(
}
static int create_symlink(
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *old_path,
const char *new_path,
bool force,
assert(old_path);
assert(new_path);
- rp = skip_root(paths, old_path);
+ rp = skip_root(lp->root_dir, old_path);
if (rp)
old_path = rp;
if (!dirname)
return -ENOMEM;
- if (chroot_symlinks_same(paths->root_dir, dirname, dest, old_path)) {
+ if (chroot_symlinks_same(lp->root_dir, dirname, dest, old_path)) {
log_debug("Symlink %s → %s already exists", new_path, dest);
return 1;
}
/* Now, remember the full path (but with the root prefix removed) of
* the symlink we just removed, and remove any symlinks to it, too. */
- rp = skip_root(lp, p);
+ rp = skip_root(lp->root_dir, p);
q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: p);
if (q < 0)
return q;
static int find_symlinks_in_scope(
UnitFileScope scope,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const UnitFileInstallInfo *i,
bool match_name,
UnitFileState *state) {
char **p;
int r;
- assert(paths);
+ assert(lp);
assert(i);
- /* As we iterate over the list of search paths in paths->search_path, we may encounter "same name"
+ /* As we iterate over the list of search paths in lp->search_path, we may encounter "same name"
* symlinks. The ones which are "below" (i.e. have lower priority) than the unit file itself are
* effectively masked, so we should ignore them. */
- STRV_FOREACH(p, paths->search_path) {
+ STRV_FOREACH(p, lp->search_path) {
bool same_name_link = false;
- r = find_symlinks(paths->root_dir, i, match_name, ignore_same_name, *p, &same_name_link);
+ r = find_symlinks(lp->root_dir, i, match_name, ignore_same_name, *p, &same_name_link);
if (r < 0)
return r;
if (r > 0) {
/* We found symlinks in this dir? Yay! Let's see where precisely it is enabled. */
- if (path_equal_ptr(*p, paths->persistent_config)) {
+ if (path_equal_ptr(*p, lp->persistent_config)) {
/* This is the best outcome, let's return it immediately. */
*state = UNIT_FILE_ENABLED;
return 1;
return 1;
}
- r = path_is_runtime(paths, *p, false);
+ r = path_is_runtime(lp, *p, false);
if (r < 0)
return r;
if (r > 0)
enabled_at_all = true;
} else if (same_name_link) {
- if (path_equal_ptr(*p, paths->persistent_config))
+ if (path_equal_ptr(*p, lp->persistent_config))
same_name_link_config = true;
else {
- r = path_is_runtime(paths, *p, false);
+ r = path_is_runtime(lp, *p, false);
if (r < 0)
return r;
if (r > 0)
static int install_info_may_process(
const UnitFileInstallInfo *i,
- const LookupPaths *paths,
+ const LookupPaths *lp,
UnitFileChange **changes,
size_t *n_changes) {
assert(i);
- assert(paths);
+ assert(lp);
/* Checks whether the loaded unit file is one we should process, or is masked,
* transient or generated and thus not subject to enable/disable operations. */
unit_file_changes_add(changes, n_changes, -ERFKILL, i->path, NULL);
return -ERFKILL;
}
- if (path_is_generator(paths, i->path) ||
- path_is_transient(paths, i->path)) {
+ if (path_is_generator(lp, i->path) ||
+ path_is_transient(lp, i->path)) {
unit_file_changes_add(changes, n_changes, -EADDRNOTAVAIL, i->path, NULL);
return -EADDRNOTAVAIL;
}
InstallContext *c,
UnitFileInstallInfo *info,
const char *path,
- const char *root_dir,
+ const LookupPaths *lp,
SearchFlags flags) {
_cleanup_free_ char *resolved = NULL;
int r;
- r = unit_file_load(c, info, path, root_dir, flags);
+ r = unit_file_load(c, info, path, lp->root_dir, flags);
if (r != -ELOOP || (flags & SEARCH_DROPIN))
return r;
- r = chase_symlinks(path, root_dir, CHASE_WARN | CHASE_NONEXISTENT, &resolved, NULL);
+ r = chase_symlinks(path, lp->root_dir, CHASE_WARN | CHASE_NONEXISTENT, &resolved, NULL);
if (r >= 0 &&
- root_dir &&
- path_equal_ptr(path_startswith(resolved, root_dir), "dev/null"))
+ lp->root_dir &&
+ path_equal_ptr(path_startswith(resolved, lp->root_dir), "dev/null"))
/* When looking under root_dir, we can't expect /dev/ to be mounted,
* so let's see if the path is a (possibly dangling) symlink to /dev/null. */
info->type = UNIT_FILE_TYPE_MASKED;
if (path_is_absolute(target))
/* This is an absolute path, prefix the root so that we always deal with fully qualified paths */
- info->symlink_target = path_join(root_dir, target);
+ info->symlink_target = path_join(lp->root_dir, target);
else
/* This is a relative path, take it relative to the dir the symlink is located in. */
info->symlink_target = file_in_same_dir(path, target);
static int unit_file_search(
InstallContext *c,
UnitFileInstallInfo *info,
- const LookupPaths *paths,
+ const LookupPaths *lp,
SearchFlags flags) {
const char *dropin_dir_name = NULL, *dropin_template_dir_name = NULL;
char **p;
assert(info);
- assert(paths);
+ assert(lp);
/* Was this unit already loaded? */
if (info->type != _UNIT_FILE_TYPE_INVALID)
return 0;
if (info->path)
- return unit_file_load_or_readlink(c, info, info->path, paths->root_dir, flags);
+ return unit_file_load_or_readlink(c, info, info->path, lp, flags);
assert(info->name);
return r;
}
- STRV_FOREACH(p, paths->search_path) {
+ STRV_FOREACH(p, lp->search_path) {
_cleanup_free_ char *path = NULL;
path = path_join(*p, info->name);
if (!path)
return -ENOMEM;
- r = unit_file_load_or_readlink(c, info, path, paths->root_dir, flags);
+ r = unit_file_load_or_readlink(c, info, path, lp, flags);
if (r >= 0) {
info->path = TAKE_PTR(path);
result = r;
* enablement was requested. We will check if it is
* possible to load template unit file. */
- STRV_FOREACH(p, paths->search_path) {
+ STRV_FOREACH(p, lp->search_path) {
_cleanup_free_ char *path = NULL;
path = path_join(*p, template);
if (!path)
return -ENOMEM;
- r = unit_file_load_or_readlink(c, info, path, paths->root_dir, flags);
+ r = unit_file_load_or_readlink(c, info, path, lp, flags);
if (r >= 0) {
info->path = TAKE_PTR(path);
result = r;
/* Search for drop-in directories */
dropin_dir_name = strjoina(info->name, ".d");
- STRV_FOREACH(p, paths->search_path) {
+ STRV_FOREACH(p, lp->search_path) {
char *path;
path = path_join(*p, dropin_dir_name);
if (template) {
dropin_template_dir_name = strjoina(template, ".d");
- STRV_FOREACH(p, paths->search_path) {
+ STRV_FOREACH(p, lp->search_path) {
char *path;
path = path_join(*p, dropin_template_dir_name);
return log_debug_errno(r, "Failed to get list of conf files: %m");
STRV_FOREACH(p, files) {
- r = unit_file_load_or_readlink(c, info, *p, paths->root_dir, flags | SEARCH_DROPIN);
+ r = unit_file_load_or_readlink(c, info, *p, lp, flags | SEARCH_DROPIN);
if (r < 0)
return log_debug_errno(r, "Failed to load conf file %s: %m", *p);
}
static int install_info_follow(
InstallContext *c,
UnitFileInstallInfo *i,
- const char *root_dir,
+ const LookupPaths *lp,
SearchFlags flags,
bool ignore_different_name) {
free_and_replace(i->path, i->symlink_target);
i->type = _UNIT_FILE_TYPE_INVALID;
- return unit_file_load_or_readlink(c, i, i->path, root_dir, flags);
+ return unit_file_load_or_readlink(c, i, i->path, lp, flags);
}
/**
static int install_info_traverse(
UnitFileScope scope,
InstallContext *c,
- const LookupPaths *paths,
+ const LookupPaths *lp,
UnitFileInstallInfo *start,
SearchFlags flags,
UnitFileInstallInfo **ret) {
unsigned k = 0;
int r;
- assert(paths);
+ assert(lp);
assert(start);
assert(c);
- r = unit_file_search(c, start, paths, flags);
+ r = unit_file_search(c, start, lp, flags);
if (r < 0)
return r;
return -ELOOP;
if (!(flags & SEARCH_FOLLOW_CONFIG_SYMLINKS)) {
- r = path_is_config(paths, i->path, true);
+ r = path_is_config(lp, i->path, true);
if (r < 0)
return r;
if (r > 0)
return -ELOOP;
}
- r = install_info_follow(c, i, paths->root_dir, flags, false);
+ r = install_info_follow(c, i, lp, flags, false);
if (r == -EXDEV) {
_cleanup_free_ char *buffer = NULL;
const char *bn;
/* We filled in the instance, and the target stayed the same? If so, then let's
* honour the link as it is. */
- r = install_info_follow(c, i, paths->root_dir, flags, true);
+ r = install_info_follow(c, i, lp, flags, true);
if (r < 0)
return r;
bn = buffer;
}
- r = install_info_add(c, bn, NULL, paths->root_dir, /* auxiliary= */ false, &i);
+ r = install_info_add(c, bn, NULL, lp->root_dir, /* auxiliary= */ false, &i);
if (r < 0)
return r;
/* Try again, with the new target we found. */
- r = unit_file_search(c, i, paths, flags);
+ r = unit_file_search(c, i, lp, flags);
if (r == -ENOENT)
/* Translate error code to highlight this specific case */
return -ENOLINK;
*/
static int install_info_add_auto(
InstallContext *c,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *name_or_path,
UnitFileInstallInfo **ret) {
if (path_is_absolute(name_or_path)) {
const char *pp;
- pp = prefix_roota(paths->root_dir, name_or_path);
+ pp = prefix_roota(lp->root_dir, name_or_path);
- return install_info_add(c, NULL, pp, paths->root_dir, /* auxiliary= */ false, ret);
+ return install_info_add(c, NULL, pp, lp->root_dir, /* auxiliary= */ false, ret);
} else
- return install_info_add(c, name_or_path, NULL, paths->root_dir, /* auxiliary= */ false, ret);
+ return install_info_add(c, name_or_path, NULL, lp->root_dir, /* auxiliary= */ false, ret);
}
static int install_info_discover(
UnitFileScope scope,
InstallContext *c,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *name,
SearchFlags flags,
UnitFileInstallInfo **ret,
int r;
assert(c);
- assert(paths);
+ assert(lp);
assert(name);
- r = install_info_add_auto(c, paths, name, &i);
+ r = install_info_add_auto(c, lp, name, &i);
if (r >= 0)
- r = install_info_traverse(scope, c, paths, i, flags, ret);
+ r = install_info_traverse(scope, c, lp, i, flags, ret);
if (r < 0)
unit_file_changes_add(changes, n_changes, r, name, NULL);
static int install_info_discover_and_check(
UnitFileScope scope,
InstallContext *c,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *name,
SearchFlags flags,
UnitFileInstallInfo **ret,
int r;
- r = install_info_discover(scope, c, paths, name, flags, ret, changes, n_changes);
+ r = install_info_discover(scope, c, lp, name, flags, ret, changes, n_changes);
if (r < 0)
return r;
- return install_info_may_process(ret ? *ret : NULL, paths, changes, n_changes);
+ return install_info_may_process(ret ? *ret : NULL, lp, changes, n_changes);
}
int unit_file_verify_alias(const UnitFileInstallInfo *i, const char *dst, char **ret_dst) {
static int install_info_symlink_alias(
UnitFileInstallInfo *i,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *config_path,
bool force,
UnitFileChange **changes,
int r = 0, q;
assert(i);
- assert(paths);
+ assert(lp);
assert(config_path);
STRV_FOREACH(s, i->aliases) {
if (!alias_path)
return -ENOMEM;
- q = create_symlink(paths, i->path, alias_path, force, changes, n_changes);
+ q = create_symlink(lp, i->path, alias_path, force, changes, n_changes);
if (r == 0)
r = q;
}
UnitFileScope scope,
UnitFileFlags file_flags,
UnitFileInstallInfo *i,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *config_path,
char **list,
const char *suffix,
int r = 0, q;
assert(i);
- assert(paths);
+ assert(lp);
assert(config_path);
if (strv_isempty(list))
return r;
instance.name = buf;
- r = unit_file_search(NULL, &instance, paths, SEARCH_FOLLOW_CONFIG_SYMLINKS);
+ r = unit_file_search(NULL, &instance, lp, SEARCH_FOLLOW_CONFIG_SYMLINKS);
if (r < 0)
return r;
if (!path)
return -ENOMEM;
- q = create_symlink(paths, i->path, path, true, changes, n_changes);
+ q = create_symlink(lp, i->path, path, true, changes, n_changes);
if (r == 0)
r = q;
- if (unit_file_exists(scope, paths, dst) == 0)
+ if (unit_file_exists(scope, lp, dst) == 0)
unit_file_changes_add(changes, n_changes, UNIT_FILE_DESTINATION_NOT_PRESENT, dst, i->path);
}
static int install_info_symlink_link(
UnitFileInstallInfo *i,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *config_path,
bool force,
UnitFileChange **changes,
int r;
assert(i);
- assert(paths);
+ assert(lp);
assert(config_path);
assert(i->path);
- r = in_search_path(paths, i->path);
+ r = in_search_path(lp, i->path);
if (r < 0)
return r;
if (r > 0)
if (!path)
return -ENOMEM;
- return create_symlink(paths, i->path, path, force, changes, n_changes);
+ return create_symlink(lp, i->path, path, force, changes, n_changes);
}
static int install_info_apply(
UnitFileScope scope,
UnitFileFlags file_flags,
UnitFileInstallInfo *i,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *config_path,
UnitFileChange **changes,
size_t *n_changes) {
int r, q;
assert(i);
- assert(paths);
+ assert(lp);
assert(config_path);
if (i->type != UNIT_FILE_TYPE_REGULAR)
bool force = file_flags & UNIT_FILE_FORCE;
- r = install_info_symlink_alias(i, paths, config_path, force, changes, n_changes);
+ r = install_info_symlink_alias(i, lp, config_path, force, changes, n_changes);
- q = install_info_symlink_wants(scope, file_flags, i, paths, config_path, i->wanted_by, ".wants/", changes, n_changes);
+ q = install_info_symlink_wants(scope, file_flags, i, lp, config_path, i->wanted_by, ".wants/", changes, n_changes);
if (r == 0)
r = q;
- q = install_info_symlink_wants(scope, file_flags, i, paths, config_path, i->required_by, ".requires/", changes, n_changes);
+ q = install_info_symlink_wants(scope, file_flags, i, lp, config_path, i->required_by, ".requires/", changes, n_changes);
if (r == 0)
r = q;
- q = install_info_symlink_link(i, paths, config_path, force, changes, n_changes);
+ q = install_info_symlink_link(i, lp, config_path, force, changes, n_changes);
/* Do not count links to the unit file towards the "carries_install_info" count */
if (r == 0 && q < 0)
r = q;
UnitFileScope scope,
UnitFileFlags file_flags,
InstallContext *c,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *config_path,
SearchFlags flags,
UnitFileChange **changes,
int r;
assert(c);
- assert(paths);
+ assert(lp);
assert(config_path);
if (ordered_hashmap_isempty(c->will_process))
if (q < 0)
return q;
- q = install_info_traverse(scope, c, paths, i, flags, NULL);
+ q = install_info_traverse(scope, c, lp, i, flags, NULL);
if (q < 0) {
if (i->auxiliary) {
q = unit_file_changes_add(changes, n_changes, UNIT_FILE_AUXILIARY_FAILED, NULL, i->name);
if (i->type != UNIT_FILE_TYPE_REGULAR)
continue;
- q = install_info_apply(scope, file_flags, i, paths, config_path, changes, n_changes);
+ q = install_info_apply(scope, file_flags, i, lp, config_path, changes, n_changes);
if (r >= 0) {
if (q < 0)
r = q;
static int install_context_mark_for_removal(
UnitFileScope scope,
InstallContext *c,
- const LookupPaths *paths,
+ const LookupPaths *lp,
Set **remove_symlinks_to,
const char *config_path,
UnitFileChange **changes,
int r;
assert(c);
- assert(paths);
+ assert(lp);
assert(config_path);
/* Marks all items for removal */
if (r < 0)
return r;
- r = install_info_traverse(scope, c, paths, i, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS, NULL);
+ r = install_info_traverse(scope, c, lp, i, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS, NULL);
if (r == -ENOLINK) {
log_debug_errno(r, "Name %s leads to a dangling symlink, removing name.", i->name);
unit_file_changes_add(changes, n_changes, UNIT_FILE_IS_DANGLING, i->path ?: i->name, NULL);
UnitFileChange **changes,
size_t *n_changes) {
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
const char *config_path;
char **i;
int r;
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- config_path = (flags & UNIT_FILE_RUNTIME) ? paths.runtime_config : paths.persistent_config;
+ config_path = (flags & UNIT_FILE_RUNTIME) ? lp.runtime_config : lp.persistent_config;
if (!config_path)
return -ENXIO;
if (!path)
return -ENOMEM;
- q = create_symlink(&paths, "/dev/null", path, !!(flags & UNIT_FILE_FORCE), changes, n_changes);
+ q = create_symlink(&lp, "/dev/null", path, !!(flags & UNIT_FILE_FORCE), changes, n_changes);
if (q < 0 && r >= 0)
r = q;
}
UnitFileChange **changes,
size_t *n_changes) {
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
_cleanup_strv_free_ char **todo = NULL;
const char *config_path;
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- config_path = (flags & UNIT_FILE_RUNTIME) ? paths.runtime_config : paths.persistent_config;
+ config_path = (flags & UNIT_FILE_RUNTIME) ? lp.runtime_config : lp.persistent_config;
if (!config_path)
return -ENXIO;
unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, path, NULL);
- rp = skip_root(&paths, path);
+ rp = skip_root(lp.root_dir, path);
q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: path);
if (q < 0)
return q;
}
- q = remove_marked_symlinks(remove_symlinks_to, config_path, &paths, dry_run, changes, n_changes);
+ q = remove_marked_symlinks(remove_symlinks_to, config_path, &lp, dry_run, changes, n_changes);
if (r >= 0)
r = q;
UnitFileChange **changes,
size_t *n_changes) {
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_strv_free_ char **todo = NULL;
const char *config_path;
size_t n_todo = 0;
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- config_path = (flags & UNIT_FILE_RUNTIME) ? paths.runtime_config : paths.persistent_config;
+ config_path = (flags & UNIT_FILE_RUNTIME) ? lp.runtime_config : lp.persistent_config;
if (!config_path)
return -ENXIO;
if (!unit_name_is_valid(fn, UNIT_NAME_ANY))
return -EINVAL;
- full = path_join(paths.root_dir, *i);
+ full = path_join(lp.root_dir, *i);
if (!full)
return -ENOMEM;
if (r < 0)
return r;
- q = in_search_path(&paths, *i);
+ q = in_search_path(&lp, *i);
if (q < 0)
return q;
if (q > 0)
if (!new_path)
return -ENOMEM;
- q = create_symlink(&paths, *i, new_path, !!(flags & UNIT_FILE_FORCE), changes, n_changes);
+ q = create_symlink(&lp, *i, new_path, !!(flags & UNIT_FILE_FORCE), changes, n_changes);
if (q < 0 && r >= 0)
r = q;
}
return r;
}
-static int path_shall_revert(const LookupPaths *paths, const char *path) {
+static int path_shall_revert(const LookupPaths *lp, const char *path) {
int r;
- assert(paths);
+ assert(lp);
assert(path);
/* Checks whether the path is one where the drop-in directories shall be removed. */
- r = path_is_config(paths, path, true);
+ r = path_is_config(lp, path, true);
if (r != 0)
return r;
- r = path_is_control(paths, path);
+ r = path_is_control(lp, path);
if (r != 0)
return r;
- return path_is_transient(paths, path);
+ return path_is_transient(lp, path);
}
int unit_file_revert(
size_t *n_changes) {
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_strv_free_ char **todo = NULL;
size_t n_todo = 0;
char **i;
* We remove all that in both the runtime and the persistent directories, if that applies.
*/
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
if (!unit_name_is_valid(*i, UNIT_NAME_ANY))
return -EINVAL;
- STRV_FOREACH(p, paths.search_path) {
+ STRV_FOREACH(p, lp.search_path) {
_cleanup_free_ char *path = NULL, *dropin = NULL;
struct stat st;
return -errno;
} else if (S_ISREG(st.st_mode)) {
/* Check if there's a vendor version */
- r = path_is_vendor_or_generator(&paths, path);
+ r = path_is_vendor_or_generator(&lp, path);
if (r < 0)
return r;
if (r > 0)
return -errno;
} else if (S_ISDIR(st.st_mode)) {
/* Remove the drop-ins */
- r = path_shall_revert(&paths, dropin);
+ r = path_shall_revert(&lp, dropin);
if (r < 0)
return r;
if (r > 0) {
continue;
/* OK, there's a vendor version, hence drop all configuration versions */
- STRV_FOREACH(p, paths.search_path) {
+ STRV_FOREACH(p, lp.search_path) {
_cleanup_free_ char *path = NULL;
struct stat st;
if (errno != ENOENT)
return -errno;
} else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
- r = path_is_config(&paths, path, true);
+ r = path_is_config(&lp, path, true);
if (r < 0)
return r;
if (r > 0) {
unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, *i, NULL);
- rp = skip_root(&paths, *i);
+ rp = skip_root(lp.root_dir, *i);
q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: *i);
if (q < 0)
return q;
}
- q = remove_marked_symlinks(remove_symlinks_to, paths.runtime_config, &paths, false, changes, n_changes);
+ q = remove_marked_symlinks(remove_symlinks_to, lp.runtime_config, &lp, false, changes, n_changes);
if (r >= 0)
r = q;
- q = remove_marked_symlinks(remove_symlinks_to, paths.persistent_config, &paths, false, changes, n_changes);
+ q = remove_marked_symlinks(remove_symlinks_to, lp.persistent_config, &lp, false, changes, n_changes);
if (r >= 0)
r = q;
UnitFileChange **changes,
size_t *n_changes) {
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_(install_context_done) InstallContext c = {};
UnitFileInstallInfo *i, *target_info;
const char *config_path;
if (!unit_name_is_valid(target, UNIT_NAME_ANY))
return -EINVAL;
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- config_path = (file_flags & UNIT_FILE_RUNTIME) ? paths.runtime_config : paths.persistent_config;
+ config_path = (file_flags & UNIT_FILE_RUNTIME) ? lp.runtime_config : lp.persistent_config;
if (!config_path)
return -ENXIO;
- r = install_info_discover_and_check(scope, &c, &paths, target, SEARCH_FOLLOW_CONFIG_SYMLINKS,
+ r = install_info_discover_and_check(scope, &c, &lp, target, SEARCH_FOLLOW_CONFIG_SYMLINKS,
&target_info, changes, n_changes);
if (r < 0)
return r;
STRV_FOREACH(f, files) {
char ***l;
- r = install_info_discover_and_check(scope, &c, &paths, *f, SEARCH_FOLLOW_CONFIG_SYMLINKS,
+ r = install_info_discover_and_check(scope, &c, &lp, *f, SEARCH_FOLLOW_CONFIG_SYMLINKS,
&i, changes, n_changes);
if (r < 0)
return r;
return -ENOMEM;
}
- return install_context_apply(scope, file_flags, &c, &paths, config_path,
+ return install_context_apply(scope, file_flags, &c, &lp, config_path,
SEARCH_FOLLOW_CONFIG_SYMLINKS, changes, n_changes);
}
UnitFileChange **changes,
size_t *n_changes) {
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_(install_context_done) InstallContext c = {};
const char *config_path;
UnitFileInstallInfo *i;
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- config_path = config_path_from_flags(&paths, file_flags);
+ config_path = config_path_from_flags(&lp, file_flags);
if (!config_path)
return -ENXIO;
STRV_FOREACH(f, files) {
- r = install_info_discover_and_check(scope, &c, &paths, *f, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
+ r = install_info_discover_and_check(scope, &c, &lp, *f, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
&i, changes, n_changes);
if (r < 0)
return r;
is useful to determine whether the passed files had any
installation data at all. */
- return install_context_apply(scope, file_flags, &c, &paths, config_path, SEARCH_LOAD, changes, n_changes);
+ return install_context_apply(scope, file_flags, &c, &lp, config_path, SEARCH_LOAD, changes, n_changes);
}
int unit_file_disable(
UnitFileChange **changes,
size_t *n_changes) {
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_(install_context_done) InstallContext c = {};
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
const char *config_path;
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- config_path = config_path_from_flags(&paths, flags);
+ config_path = config_path_from_flags(&lp, flags);
if (!config_path)
return -ENXIO;
if (!unit_name_is_valid(*i, UNIT_NAME_ANY))
return -EINVAL;
- r = install_info_add(&c, *i, NULL, paths.root_dir, /* auxiliary= */ false, NULL);
+ r = install_info_add(&c, *i, NULL, lp.root_dir, /* auxiliary= */ false, NULL);
if (r < 0)
return r;
}
- r = install_context_mark_for_removal(scope, &c, &paths, &remove_symlinks_to, config_path, changes, n_changes);
+ r = install_context_mark_for_removal(scope, &c, &lp, &remove_symlinks_to, config_path, changes, n_changes);
if (r < 0)
return r;
- return remove_marked_symlinks(remove_symlinks_to, config_path, &paths, !!(flags & UNIT_FILE_DRY_RUN), changes, n_changes);
+ return remove_marked_symlinks(remove_symlinks_to, config_path, &lp, !!(flags & UNIT_FILE_DRY_RUN), changes, n_changes);
}
int unit_file_reenable(
UnitFileChange **changes,
size_t *n_changes) {
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_(install_context_done) InstallContext c = {};
UnitFileInstallInfo *i;
const char *new_path;
if (streq(name, SPECIAL_DEFAULT_TARGET))
return -EINVAL;
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- r = install_info_discover_and_check(scope, &c, &paths, name, 0, &i, changes, n_changes);
+ r = install_info_discover_and_check(scope, &c, &lp, name, 0, &i, changes, n_changes);
if (r < 0)
return r;
- new_path = strjoina(paths.persistent_config, "/" SPECIAL_DEFAULT_TARGET);
- return create_symlink(&paths, i->path, new_path, !!(flags & UNIT_FILE_FORCE), changes, n_changes);
+ new_path = strjoina(lp.persistent_config, "/" SPECIAL_DEFAULT_TARGET);
+ return create_symlink(&lp, i->path, new_path, !!(flags & UNIT_FILE_FORCE), changes, n_changes);
}
int unit_file_get_default(
const char *root_dir,
char **name) {
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_(install_context_done) InstallContext c = {};
UnitFileInstallInfo *i;
char *n;
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(name);
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- r = install_info_discover(scope, &c, &paths, SPECIAL_DEFAULT_TARGET, SEARCH_FOLLOW_CONFIG_SYMLINKS,
+ r = install_info_discover(scope, &c, &lp, SPECIAL_DEFAULT_TARGET, SEARCH_FOLLOW_CONFIG_SYMLINKS,
&i, NULL, NULL);
if (r < 0)
return r;
- r = install_info_may_process(i, &paths, NULL, 0);
+ r = install_info_may_process(i, &lp, NULL, 0);
if (r < 0)
return r;
int unit_file_lookup_state(
UnitFileScope scope,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *name,
UnitFileState *ret) {
UnitFileState state;
int r;
- assert(paths);
+ assert(lp);
assert(name);
if (!unit_name_is_valid(name, UNIT_NAME_ANY))
return -EINVAL;
- r = install_info_discover(scope, &c, paths, name, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
+ r = install_info_discover(scope, &c, lp, name, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
&i, NULL, NULL);
if (r < 0)
return log_debug_errno(r, "Failed to discover unit %s: %m", name);
switch (i->type) {
case UNIT_FILE_TYPE_MASKED:
- r = path_is_runtime(paths, i->path, true);
+ r = path_is_runtime(lp, i->path, true);
if (r < 0)
return r;
break;
}
- r = path_is_generator(paths, i->path);
+ r = path_is_generator(lp, i->path);
if (r < 0)
return r;
if (r > 0) {
break;
}
- r = path_is_transient(paths, i->path);
+ r = path_is_transient(lp, i->path);
if (r < 0)
return r;
if (r > 0) {
/* Check if any of the Alias= symlinks have been created.
* We ignore other aliases, and only check those that would
* be created by systemctl enable for this unit. */
- r = find_symlinks_in_scope(scope, paths, i, true, &state);
+ r = find_symlinks_in_scope(scope, lp, i, true, &state);
if (r < 0)
return r;
if (r > 0)
/* Check if the file is known under other names. If it is,
* it might be in use. Report that as UNIT_FILE_INDIRECT. */
- r = find_symlinks_in_scope(scope, paths, i, false, &state);
+ r = find_symlinks_in_scope(scope, lp, i, false, &state);
if (r < 0)
return r;
if (r > 0)
const char *name,
UnitFileState *ret) {
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
int r;
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(name);
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- return unit_file_lookup_state(scope, &paths, name, ret);
+ return unit_file_lookup_state(scope, &lp, name, ret);
}
-int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name) {
+int unit_file_exists(UnitFileScope scope, const LookupPaths *lp, const char *name) {
_cleanup_(install_context_done) InstallContext c = {};
int r;
- assert(paths);
+ assert(lp);
assert(name);
if (!unit_name_is_valid(name, UNIT_NAME_ANY))
return -EINVAL;
- r = install_info_discover(scope, &c, paths, name, 0, NULL, NULL, NULL);
+ r = install_info_discover(scope, &c, lp, name, 0, NULL, NULL, NULL);
if (r == -ENOENT)
return 0;
if (r < 0)
UnitFileFlags file_flags,
InstallContext *plus,
InstallContext *minus,
- const LookupPaths *paths,
+ const LookupPaths *lp,
const char *config_path,
char **files,
UnitFilePresetMode mode,
assert(plus);
assert(minus);
- assert(paths);
+ assert(lp);
assert(config_path);
if (mode != UNIT_FILE_PRESET_ENABLE_ONLY) {
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
- r = install_context_mark_for_removal(scope, minus, paths, &remove_symlinks_to, config_path, changes, n_changes);
+ r = install_context_mark_for_removal(scope, minus, lp, &remove_symlinks_to, config_path, changes, n_changes);
if (r < 0)
return r;
- r = remove_marked_symlinks(remove_symlinks_to, config_path, paths, false, changes, n_changes);
+ r = remove_marked_symlinks(remove_symlinks_to, config_path, lp, false, changes, n_changes);
} else
r = 0;
/* Returns number of symlinks that where supposed to be installed. */
q = install_context_apply(scope,
file_flags | UNIT_FILE_IGNORE_AUXILIARY_FAILURE,
- plus, paths, config_path, SEARCH_LOAD, changes, n_changes);
+ plus, lp, config_path, SEARCH_LOAD, changes, n_changes);
if (r >= 0) {
if (q < 0)
r = q;
UnitFileScope scope,
InstallContext *plus,
InstallContext *minus,
- LookupPaths *paths,
+ LookupPaths *lp,
const char *name,
const UnitFilePresets *presets,
UnitFileChange **changes,
if (install_info_find(plus, name) || install_info_find(minus, name))
return 0;
- r = install_info_discover(scope, &tmp, paths, name, SEARCH_FOLLOW_CONFIG_SYMLINKS,
+ r = install_info_discover(scope, &tmp, lp, name, SEARCH_FOLLOW_CONFIG_SYMLINKS,
&i, changes, n_changes);
if (r < 0)
return r;
if (instance_name_list) {
char **s;
STRV_FOREACH(s, instance_name_list) {
- r = install_info_discover_and_check(scope, plus, paths, *s, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
+ r = install_info_discover_and_check(scope, plus, lp, *s, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
&i, changes, n_changes);
if (r < 0)
return r;
}
} else {
- r = install_info_discover_and_check(scope, plus, paths, name, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
+ r = install_info_discover_and_check(scope, plus, lp, name, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
&i, changes, n_changes);
if (r < 0)
return r;
}
} else
- r = install_info_discover(scope, minus, paths, name, SEARCH_FOLLOW_CONFIG_SYMLINKS,
+ r = install_info_discover(scope, minus, lp, name, SEARCH_FOLLOW_CONFIG_SYMLINKS,
&i, changes, n_changes);
return r;
size_t *n_changes) {
_cleanup_(install_context_done) InstallContext plus = {}, minus = {};
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_(unit_file_presets_freep) UnitFilePresets presets = {};
const char *config_path;
char **i;
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(mode < _UNIT_FILE_PRESET_MAX);
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- config_path = (file_flags & UNIT_FILE_RUNTIME) ? paths.runtime_config : paths.persistent_config;
+ config_path = (file_flags & UNIT_FILE_RUNTIME) ? lp.runtime_config : lp.persistent_config;
if (!config_path)
return -ENXIO;
return r;
STRV_FOREACH(i, files) {
- r = preset_prepare_one(scope, &plus, &minus, &paths, *i, &presets, changes, n_changes);
+ r = preset_prepare_one(scope, &plus, &minus, &lp, *i, &presets, changes, n_changes);
if (r < 0)
return r;
}
- return execute_preset(scope, file_flags, &plus, &minus, &paths, config_path, files, mode, changes, n_changes);
+ return execute_preset(scope, file_flags, &plus, &minus, &lp, config_path, files, mode, changes, n_changes);
}
int unit_file_preset_all(
size_t *n_changes) {
_cleanup_(install_context_done) InstallContext plus = {}, minus = {};
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_(unit_file_presets_freep) UnitFilePresets presets = {};
const char *config_path = NULL;
char **i;
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(mode < _UNIT_FILE_PRESET_MAX);
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- config_path = (file_flags & UNIT_FILE_RUNTIME) ? paths.runtime_config : paths.persistent_config;
+ config_path = (file_flags & UNIT_FILE_RUNTIME) ? lp.runtime_config : lp.persistent_config;
if (!config_path)
return -ENXIO;
if (r < 0)
return r;
- STRV_FOREACH(i, paths.search_path) {
+ STRV_FOREACH(i, lp.search_path) {
_cleanup_closedir_ DIR *d = NULL;
d = opendir(*i);
if (!IN_SET(de->d_type, DT_LNK, DT_REG))
continue;
- r = preset_prepare_one(scope, &plus, &minus, &paths, de->d_name, &presets, changes, n_changes);
+ r = preset_prepare_one(scope, &plus, &minus, &lp, de->d_name, &presets, changes, n_changes);
if (r < 0 &&
!IN_SET(r, -EEXIST, -ERFKILL, -EADDRNOTAVAIL, -EIDRM, -EUCLEAN, -ELOOP, -ENOENT))
/* Ignore generated/transient/missing/invalid units when applying preset, propagate other errors.
}
}
- return execute_preset(scope, file_flags, &plus, &minus, &paths, config_path, NULL, mode, changes, n_changes);
+ return execute_preset(scope, file_flags, &plus, &minus, &lp, config_path, NULL, mode, changes, n_changes);
}
static UnitFileList* unit_file_list_free_one(UnitFileList *f) {
char **states,
char **patterns) {
- _cleanup_(lookup_paths_free) LookupPaths paths = {};
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
char **dirname;
int r;
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(h);
- r = lookup_paths_init(&paths, scope, 0, root_dir);
+ r = lookup_paths_init(&lp, scope, 0, root_dir);
if (r < 0)
return r;
- STRV_FOREACH(dirname, paths.search_path) {
+ STRV_FOREACH(dirname, lp.search_path) {
_cleanup_closedir_ DIR *d = NULL;
d = opendir(*dirname);
if (!f->path)
return -ENOMEM;
- r = unit_file_lookup_state(scope, &paths, de->d_name, &f->state);
+ r = unit_file_lookup_state(scope, &lp, de->d_name, &f->state);
if (r < 0)
f->state = UNIT_FILE_BAD;