r = user_runtime_dir(&p);
else
r = user_config_home(&p);
-
- if (r <= 0)
- return r < 0 ? r : -ENOENT;
+ if (r < 0)
+ return r;
+ if (r == 0)
+ return -ENOENT;
break;
path_kill_slashes(n);
r = set_consume(*remove_symlinks_to, n);
+ if (r == -EEXIST)
+ return 0;
if (r < 0)
- return r == -EEXIST ? 0 : r;
+ return r;
return 0;
}
char** instance_whitelist) {
_cleanup_closedir_ DIR *d = NULL;
+ struct dirent *de;
int r = 0;
assert(remove_symlinks_to);
rewinddir(d);
- for (;;) {
- struct dirent *de;
-
- errno = 0;
- de = readdir(d);
- if (!de && errno != 0) {
- r = -errno;
- break;
- }
-
- if (!de)
- break;
-
- if (hidden_file(de->d_name))
- continue;
+ FOREACH_DIRENT(de, d, return -errno) {
dirent_ensure_type(d, de);
if (de->d_type == DT_DIR) {
- int nfd, q;
_cleanup_free_ char *p = NULL;
+ int nfd, q;
nfd = openat(fd, de->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
if (nfd < 0) {
char** instance_whitelist) {
_cleanup_close_ int fd = -1;
- int r = 0;
bool deleted;
+ int r = 0;
assert(config_path);
deleted = false;
cfd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
- if (cfd < 0) {
- r = -errno;
- break;
- }
+ if (cfd < 0)
+ return -errno;
/* This takes possession of cfd and closes it */
q = remove_marked_symlinks_fd(remove_symlinks_to, cfd, config_path, config_path, &deleted, changes, n_changes, instance_whitelist);
const char *config_path,
bool *same_name_link) {
- int r = 0;
_cleanup_closedir_ DIR *d = NULL;
+ struct dirent *de;
+ int r = 0;
assert(name);
assert(fd >= 0);
return -errno;
}
- for (;;) {
- struct dirent *de;
-
- errno = 0;
- de = readdir(d);
- if (!de && errno != 0)
- return -errno;
-
- if (!de)
- return r;
-
- if (hidden_file(de->d_name))
- continue;
+ FOREACH_DIRENT(de, d, return -errno) {
dirent_ensure_type(d, de);
if (de->d_type == DT_DIR) {
- int nfd, q;
_cleanup_free_ char *p = NULL;
+ int nfd, q;
nfd = openat(fd, de->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
if (nfd < 0) {
/* Acquire symlink destination */
q = readlink_and_canonicalize(p, &dest);
+ if (q == -ENOENT)
+ continue;
if (q < 0) {
- if (q == -ENOENT)
- continue;
-
if (r == 0)
r = q;
continue;
return 1;
}
}
+
+ return r;
}
static int find_symlinks(
UnitFileChange **changes,
unsigned *n_changes) {
- char **i;
_cleanup_free_ char *prefix = NULL;
+ char **i;
int r;
assert(scope >= 0);
}
path = path_make_absolute(*i, prefix);
- if (!path) {
- r = -ENOMEM;
- break;
- }
+ if (!path)
+ return -ENOMEM;
if (symlink("/dev/null", path) >= 0) {
unit_file_changes_add(changes, n_changes, UNIT_FILE_SYMLINK, path, "/dev/null");
UnitFileChange **changes,
unsigned *n_changes) {
- char **i, *config_path = NULL;
+ _cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
+ _cleanup_free_ char *config_path = NULL;
+ char **i;
int r, q;
- Set *remove_symlinks_to = NULL;
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
r = get_config_path(scope, runtime, root_dir, &config_path);
if (r < 0)
- goto finish;
+ return r;
STRV_FOREACH(i, files) {
_cleanup_free_ char *path = NULL;
}
path = path_make_absolute(*i, config_path);
- if (!path) {
- r = -ENOMEM;
- break;
- }
+ if (!path)
+ return -ENOMEM;
q = null_or_empty_path(path);
if (q > 0) {
r = q;
}
-
-finish:
q = remove_marked_symlinks(remove_symlinks_to, config_path, changes, n_changes, files);
if (r == 0)
r = q;
- set_free_free(remove_symlinks_to);
- free(config_path);
-
return r;
}
unsigned *n_changes) {
_cleanup_lookup_paths_free_ LookupPaths paths = {};
- char **i;
_cleanup_free_ char *config_path = NULL;
+ char **i;
int r, q;
assert(scope >= 0);
q = in_search_path(*i, paths.unit_path);
if (q < 0)
return q;
-
if (q > 0)
continue;
}
static void install_info_free(UnitFileInstallInfo *i) {
- assert(i);
+
+ if (!i)
+ return;
free(i->name);
free(i->path);
return 0;
fail:
- if (i)
- install_info_free(i);
-
+ install_info_free(i);
return r;
}
assert(info);
assert(path);
- if (!isempty(root_dir))
- path = strjoina(root_dir, "/", path);
+ path = prefix_roota(root_dir, path);
if (!load) {
- r = access(path, F_OK) ? -errno : 0;
- return r;
+ if (access(path, F_OK) < 0)
+ return -errno;
+
+ return 0;
}
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|(allow_symlink ? 0 : O_NOFOLLOW));
assert(paths);
assert(config_path);
- if (!ordered_hashmap_isempty(c->will_install)) {
- r = ordered_hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
- if (r < 0)
- return r;
+ if (ordered_hashmap_isempty(c->will_install))
+ return 0;
- r = ordered_hashmap_reserve(c->have_installed, ordered_hashmap_size(c->will_install));
- if (r < 0)
- return r;
- }
+ r = ordered_hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
+ if (r < 0)
+ return r;
r = 0;
while ((i = ordered_hashmap_first(c->will_install))) {
/* Marks all items for removal */
- if (!ordered_hashmap_isempty(c->will_install)) {
- r = ordered_hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
- if (r < 0)
- return r;
+ if (ordered_hashmap_isempty(c->will_install))
+ return 0;
- r = ordered_hashmap_reserve(c->have_installed, ordered_hashmap_size(c->will_install));
- if (r < 0)
- return r;
- }
+ r = ordered_hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
+ if (r < 0)
+ return r;
r = 0;
while ((i = ordered_hashmap_first(c->will_install))) {
}
/* This will return the number of symlink rules that were
- supposed to be created, not the ones actually created. This is
- useful to determine whether the passed files had any
- installation data at all. */
+ supposed to be created, not the ones actually created. This
+ is useful to determine whether the passed files had any
+ installation data at all. */
return install_context_apply(&c, &paths, config_path, root_dir, force, changes, n_changes);
}
unsigned *n_changes) {
int r;
- r = unit_file_disable(scope, runtime, root_dir, files,
- changes, n_changes);
+ r = unit_file_disable(scope, runtime, root_dir, files, changes, n_changes);
if (r < 0)
return r;
- return unit_file_enable(scope, runtime, root_dir, files, force,
- changes, n_changes);
+ return unit_file_enable(scope, runtime, root_dir, files, force, changes, n_changes);
}
int unit_file_set_default(
return r;
else if (r > 0)
return UNIT_FILE_DISABLED;
- else if (r == 0) {
- if (also)
- return UNIT_FILE_INDIRECT;
- return UNIT_FILE_STATIC;
- }
+ else if (r == 0)
+ return also ? UNIT_FILE_INDIRECT : UNIT_FILE_STATIC;
}
return r < 0 ? r : state;
r = install_context_mark_for_removal(&minus, &paths, &remove_symlinks_to, config_path, root_dir);
q = remove_marked_symlinks(remove_symlinks_to, config_path, changes, n_changes, files);
- if (r == 0)
+ if (r >= 0)
r = q;
}
if (mode != UNIT_FILE_PRESET_DISABLE_ONLY) {
/* Returns number of symlinks that where supposed to be installed. */
q = install_context_apply(&plus, &paths, config_path, root_dir, force, changes, n_changes);
- if (r == 0)
+ if (r >= 0)
r = q;
}
STRV_FOREACH(i, paths.unit_path) {
_cleanup_closedir_ DIR *d = NULL;
_cleanup_free_ char *units_dir;
+ struct dirent *de;
units_dir = path_join(root_dir, *i, NULL);
if (!units_dir)
return -errno;
}
- for (;;) {
- struct dirent *de;
-
- errno = 0;
- de = readdir(d);
- if (!de && errno != 0)
- return -errno;
-
- if (!de)
- break;
-
- if (hidden_file(de->d_name))
- continue;
+ FOREACH_DIRENT(de, d, return -errno) {
if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY))
continue;
r = install_context_mark_for_removal(&minus, &paths, &remove_symlinks_to, config_path, root_dir);
q = remove_marked_symlinks(remove_symlinks_to, config_path, changes, n_changes, NULL);
- if (r == 0)
+ if (r >= 0)
r = q;
}
if (mode != UNIT_FILE_PRESET_DISABLE_ONLY) {
q = install_context_apply(&plus, &paths, config_path, root_dir, force, changes, n_changes);
- if (r == 0)
+ if (r >= 0)
r = q;
}
STRV_FOREACH(i, paths.unit_path) {
_cleanup_closedir_ DIR *d = NULL;
_cleanup_free_ char *units_dir;
+ struct dirent *de;
units_dir = path_join(root_dir, *i, NULL);
if (!units_dir)
return -errno;
}
- for (;;) {
+ FOREACH_DIRENT(de, d, return -errno) {
_cleanup_(unit_file_list_free_onep) UnitFileList *f = NULL;
- struct dirent *de;
_cleanup_free_ char *path = NULL;
bool also = false;
- errno = 0;
- de = readdir(d);
- if (!de && errno != 0)
- return -errno;
-
- if (!de)
- break;
-
- if (hidden_file(de->d_name))
- continue;
-
if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY))
continue;
r = null_or_empty_path(f->path);
if (r < 0 && r != -ENOENT)
return r;
- else if (r > 0) {
+ if (r > 0) {
f->state =
path_startswith(*i, "/run") ?
UNIT_FILE_MASKED_RUNTIME : UNIT_FILE_MASKED;
r = find_symlinks_in_scope(scope, root_dir, de->d_name, &f->state);
if (r < 0)
return r;
- else if (r > 0) {
+ if (r > 0) {
f->state = UNIT_FILE_ENABLED;
goto found;
}