mirror of
https://github.com/systemd/systemd.git
synced 2024-10-28 20:25:38 +03:00
install: various modernizations
This commit is contained in:
parent
e7b4d43ec3
commit
da39f6a63e
@ -319,7 +319,8 @@ static int remove_marked_symlinks(
|
|||||||
unsigned *n_changes,
|
unsigned *n_changes,
|
||||||
char** files) {
|
char** files) {
|
||||||
|
|
||||||
int fd, r = 0;
|
_cleanup_close_ int fd = -1;
|
||||||
|
int r = 0;
|
||||||
bool deleted;
|
bool deleted;
|
||||||
|
|
||||||
assert(config_path);
|
assert(config_path);
|
||||||
@ -347,8 +348,6 @@ static int remove_marked_symlinks(
|
|||||||
r = q;
|
r = q;
|
||||||
} while (deleted);
|
} while (deleted);
|
||||||
|
|
||||||
safe_close(fd);
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1830,11 +1829,11 @@ int unit_file_preset(
|
|||||||
UnitFileChange **changes,
|
UnitFileChange **changes,
|
||||||
unsigned *n_changes) {
|
unsigned *n_changes) {
|
||||||
|
|
||||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
|
||||||
_cleanup_install_context_done_ InstallContext plus = {}, minus = {};
|
_cleanup_install_context_done_ InstallContext plus = {}, minus = {};
|
||||||
char **i;
|
|
||||||
_cleanup_free_ char *config_path = NULL;
|
|
||||||
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
|
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
|
||||||
|
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||||
|
_cleanup_free_ char *config_path = NULL;
|
||||||
|
char **i;
|
||||||
int r, q;
|
int r, q;
|
||||||
|
|
||||||
assert(scope >= 0);
|
assert(scope >= 0);
|
||||||
@ -1861,16 +1860,13 @@ int unit_file_preset(
|
|||||||
r = install_info_add_auto(&plus, *i);
|
r = install_info_add_auto(&plus, *i);
|
||||||
else
|
else
|
||||||
r = install_info_add_auto(&minus, *i);
|
r = install_info_add_auto(&minus, *i);
|
||||||
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = install_context_mark_for_removal(&minus, &paths, &remove_symlinks_to,
|
r = install_context_mark_for_removal(&minus, &paths, &remove_symlinks_to, config_path, root_dir);
|
||||||
config_path, root_dir);
|
|
||||||
|
|
||||||
q = remove_marked_symlinks(remove_symlinks_to, config_path,
|
q = remove_marked_symlinks(remove_symlinks_to, config_path, changes, n_changes, files);
|
||||||
changes, n_changes, files);
|
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
r = q;
|
r = q;
|
||||||
|
|
||||||
@ -1899,8 +1895,6 @@ int unit_file_get_list(
|
|||||||
|
|
||||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||||
char **i;
|
char **i;
|
||||||
_cleanup_free_ char *buf = NULL;
|
|
||||||
_cleanup_closedir_ DIR *d = NULL;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(scope >= 0);
|
assert(scope >= 0);
|
||||||
@ -1915,22 +1909,19 @@ int unit_file_get_list(
|
|||||||
return r;
|
return r;
|
||||||
|
|
||||||
STRV_FOREACH(i, paths.unit_path) {
|
STRV_FOREACH(i, paths.unit_path) {
|
||||||
|
_cleanup_closedir_ DIR *d = NULL;
|
||||||
|
_cleanup_free_ char *buf = NULL;
|
||||||
const char *units_dir;
|
const char *units_dir;
|
||||||
|
|
||||||
free(buf);
|
if (!isempty(root_dir)) {
|
||||||
buf = NULL;
|
buf = strjoin(root_dir, "/", *i, NULL);
|
||||||
|
if (!buf)
|
||||||
if (root_dir) {
|
|
||||||
if (asprintf(&buf, "%s/%s", root_dir, *i) < 0)
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
units_dir = buf;
|
units_dir = buf;
|
||||||
} else
|
} else
|
||||||
units_dir = *i;
|
units_dir = *i;
|
||||||
|
|
||||||
if (d)
|
|
||||||
closedir(d);
|
|
||||||
|
|
||||||
d = opendir(units_dir);
|
d = opendir(units_dir);
|
||||||
if (!d) {
|
if (!d) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
@ -1960,15 +1951,9 @@ int unit_file_get_list(
|
|||||||
if (hashmap_get(h, de->d_name))
|
if (hashmap_get(h, de->d_name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
r = dirent_ensure_type(d, de);
|
dirent_ensure_type(d, de);
|
||||||
if (r < 0) {
|
|
||||||
if (r == -ENOENT)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
return r;
|
if (!IN_SET(de->d_type, DT_LNK, DT_REG))
|
||||||
}
|
|
||||||
|
|
||||||
if (de->d_type != DT_LNK && de->d_type != DT_REG)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
f = new0(UnitFileList, 1);
|
f = new0(UnitFileList, 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user