Merge pull request #32733 from YHNdnzj/core-some-cleanup

core: minor cleanups
This commit is contained in:
Daan De Meyer
2024-05-09 12:45:50 +02:00
committed by GitHub
5 changed files with 36 additions and 29 deletions

View File

@@ -217,8 +217,10 @@ int path_make_relative_parent(const char *from_child, const char *to, char **ret
return path_make_relative(from, to, ret);
}
char* path_startswith_strv(const char *p, char **set) {
STRV_FOREACH(s, set) {
char* path_startswith_strv(const char *p, char * const *strv) {
assert(p);
STRV_FOREACH(s, strv) {
char *t;
t = path_startswith(p, *s);
@@ -1368,7 +1370,9 @@ bool empty_or_root(const char *path) {
return path_equal(path, "/");
}
bool path_strv_contains(char **l, const char *path) {
bool path_strv_contains(char * const *l, const char *path) {
assert(path);
STRV_FOREACH(i, l)
if (path_equal(*i, path))
return true;
@@ -1376,7 +1380,9 @@ bool path_strv_contains(char **l, const char *path) {
return false;
}
bool prefixed_path_strv_contains(char **l, const char *path) {
bool prefixed_path_strv_contains(char * const *l, const char *path) {
assert(path);
STRV_FOREACH(i, l) {
const char *j = *i;
@@ -1384,6 +1390,7 @@ bool prefixed_path_strv_contains(char **l, const char *path) {
j++;
if (*j == '+')
j++;
if (path_equal(j, path))
return true;
}

View File

@@ -108,7 +108,7 @@ static inline int path_simplify_alloc(const char *path, char **ret) {
/* Note: the search terminates on the first NULL item. */
#define PATH_IN_SET(p, ...) path_strv_contains(STRV_MAKE(__VA_ARGS__), p)
char* path_startswith_strv(const char *p, char **set);
char* path_startswith_strv(const char *p, char * const *strv);
#define PATH_STARTSWITH_SET(p, ...) path_startswith_strv(p, STRV_MAKE(__VA_ARGS__))
int path_strv_make_absolute_cwd(char **l);
@@ -218,7 +218,7 @@ static inline const char* empty_to_root(const char *path) {
return isempty(path) ? "/" : path;
}
bool path_strv_contains(char **l, const char *path);
bool prefixed_path_strv_contains(char **l, const char *path);
bool path_strv_contains(char * const *l, const char *path);
bool prefixed_path_strv_contains(char * const *l, const char *path);
int path_glob_can_match(const char *pattern, const char *prefix, char **ret);

View File

@@ -1604,16 +1604,16 @@ const sd_bus_vtable bus_unit_cgroup_vtable[] = {
SD_BUS_PROPERTY("IOWriteOperations", "t", property_get_io_counter, 0, 0),
SD_BUS_METHOD_WITH_ARGS("GetProcesses",
SD_BUS_NO_ARGS,
SD_BUS_ARGS("a(sus)", processes),
bus_unit_method_get_processes,
SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_NO_ARGS,
SD_BUS_ARGS("a(sus)", processes),
bus_unit_method_get_processes,
SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD_WITH_ARGS("AttachProcesses",
SD_BUS_ARGS("s", subcgroup, "au", pids),
SD_BUS_NO_RESULT,
bus_unit_method_attach_processes,
SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_ARGS("s", subcgroup, "au", pids),
SD_BUS_NO_RESULT,
bus_unit_method_attach_processes,
SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END
};

View File

@@ -2057,9 +2057,9 @@ static bool root_read_only(
}
static bool home_read_only(
char** read_only_paths,
char** inaccessible_paths,
char** empty_directories,
char * const *read_only_paths,
char * const *inaccessible_paths,
char * const *empty_directories,
const BindMount *bind_mounts,
size_t n_bind_mounts,
const TemporaryFileSystem *temporary_filesystems,
@@ -2078,13 +2078,13 @@ static bool home_read_only(
prefixed_path_strv_contains(empty_directories, "/home"))
return true;
for (size_t i = 0; i < n_temporary_filesystems; i++)
if (path_equal(temporary_filesystems[i].path, "/home"))
FOREACH_ARRAY(i, temporary_filesystems, n_temporary_filesystems)
if (path_equal(i->path, "/home"))
return true;
/* If /home is overmounted with some dir from the host it's not writable. */
for (size_t i = 0; i < n_bind_mounts; i++)
if (path_equal(bind_mounts[i].destination, "/home"))
FOREACH_ARRAY(i, bind_mounts, n_bind_mounts)
if (path_equal(i->destination, "/home"))
return true;
return false;

View File

@@ -2218,16 +2218,16 @@ static void retroactively_start_dependencies(Unit *u) {
UNIT_FOREACH_DEPENDENCY(other, u, UNIT_ATOM_RETROACTIVE_START_REPLACE) /* Requires= + BindsTo= */
if (!unit_has_dependency(u, UNIT_ATOM_AFTER, other) &&
!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
manager_add_job(u->manager, JOB_START, other, JOB_REPLACE, NULL, NULL, NULL);
(void) manager_add_job(u->manager, JOB_START, other, JOB_REPLACE, NULL, NULL, NULL);
UNIT_FOREACH_DEPENDENCY(other, u, UNIT_ATOM_RETROACTIVE_START_FAIL) /* Wants= */
if (!unit_has_dependency(u, UNIT_ATOM_AFTER, other) &&
!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
manager_add_job(u->manager, JOB_START, other, JOB_FAIL, NULL, NULL, NULL);
(void) manager_add_job(u->manager, JOB_START, other, JOB_FAIL, NULL, NULL, NULL);
UNIT_FOREACH_DEPENDENCY(other, u, UNIT_ATOM_RETROACTIVE_STOP_ON_START) /* Conflicts= (and inverse) */
if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
manager_add_job(u->manager, JOB_STOP, other, JOB_REPLACE, NULL, NULL, NULL);
(void) manager_add_job(u->manager, JOB_STOP, other, JOB_REPLACE, NULL, NULL, NULL);
}
static void retroactively_stop_dependencies(Unit *u) {
@@ -2239,7 +2239,7 @@ static void retroactively_stop_dependencies(Unit *u) {
/* Pull down units which are bound to us recursively if enabled */
UNIT_FOREACH_DEPENDENCY(other, u, UNIT_ATOM_RETROACTIVE_STOP_ON_STOP) /* BoundBy= */
if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
manager_add_job(u->manager, JOB_STOP, other, JOB_REPLACE, NULL, NULL, NULL);
(void) manager_add_job(u->manager, JOB_STOP, other, JOB_REPLACE, NULL, NULL, NULL);
}
void unit_start_on_failure(
@@ -2928,7 +2928,7 @@ static int on_rewatch_pids_event(sd_event_source *s, void *userdata) {
assert(s);
unit_tidy_watch_pids(u);
unit_watch_all_pids(u);
(void) unit_watch_all_pids(u);
/* If the PID set is empty now, then let's finish this off. */
unit_synthesize_cgroup_empty_event(u);
@@ -4292,8 +4292,8 @@ int unit_patch_contexts(Unit *u) {
ec->restrict_suid_sgid = true;
}
for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++)
exec_directory_sort(ec->directories + dt);
FOREACH_ARRAY(d, ec->directories, _EXEC_DIRECTORY_TYPE_MAX)
exec_directory_sort(d);
}
cc = unit_get_cgroup_context(u);