Merge pull request #21990 from keszybz/indentation-and-comments

Indentation and comments
This commit is contained in:
Luca Boccassi
2022-01-04 00:18:10 +00:00
committed by GitHub
48 changed files with 86 additions and 141 deletions
+19 -19
View File
@@ -1237,8 +1237,6 @@ char *file_in_same_dir(const char *path, const char *filename) {
}
bool hidden_or_backup_file(const char *filename) {
const char *p;
assert(filename);
if (filename[0] == '.' ||
@@ -1248,24 +1246,25 @@ bool hidden_or_backup_file(const char *filename) {
endswith(filename, "~"))
return true;
p = strrchr(filename, '.');
if (!p)
const char *dot = strrchr(filename, '.');
if (!dot)
return false;
/* Please, let's not add more entries to the list below. If external projects think it's a good idea to come up
* with always new suffixes and that everybody else should just adjust to that, then it really should be on
* them. Hence, in future, let's not add any more entries. Instead, let's ask those packages to instead adopt
* one of the generic suffixes/prefixes for hidden files or backups, possibly augmented with an additional
* string. Specifically: there's now:
/* Please, let's not add more entries to the list below. If external projects think it's a good idea
* to come up with always new suffixes and that everybody else should just adjust to that, then it
* really should be on them. Hence, in future, let's not add any more entries. Instead, let's ask
* those packages to instead adopt one of the generic suffixes/prefixes for hidden files or backups,
* possibly augmented with an additional string. Specifically: there's now:
*
* The generic suffixes "~" and ".bak" for backup files
* The generic prefix "." for hidden files
*
* Thus, if a new package manager "foopkg" wants its own set of ".foopkg-new", ".foopkg-old", ".foopkg-dist"
* or so registered, let's refuse that and ask them to use ".foopkg.new", ".foopkg.old" or ".foopkg~" instead.
* Thus, if a new package manager "foopkg" wants its own set of ".foopkg-new", ".foopkg-old",
* ".foopkg-dist" or so registered, let's refuse that and ask them to use ".foopkg.new",
* ".foopkg.old" or ".foopkg~" instead.
*/
return STR_IN_SET(p + 1,
return STR_IN_SET(dot + 1,
"rpmnew",
"rpmsave",
"rpmorig",
@@ -1287,15 +1286,16 @@ bool hidden_or_backup_file(const char *filename) {
bool is_device_path(const char *path) {
/* Returns true on paths that likely refer to a device, either by path in sysfs or to something in /dev */
/* Returns true for paths that likely refer to a device, either by path in sysfs or to something in
* /dev. */
return PATH_STARTSWITH_SET(path, "/dev/", "/sys/");
}
bool valid_device_node_path(const char *path) {
/* Some superficial checks whether the specified path is a valid device node path, all without looking at the
* actual device node. */
/* Some superficial checks whether the specified path is a valid device node path, all without
* looking at the actual device node. */
if (!PATH_STARTSWITH_SET(path, "/dev/", "/run/systemd/inaccessible/"))
return false;
@@ -1309,8 +1309,8 @@ bool valid_device_node_path(const char *path) {
bool valid_device_allow_pattern(const char *path) {
assert(path);
/* Like valid_device_node_path(), but also allows full-subsystem expressions, like DeviceAllow= and DeviceDeny=
* accept it */
/* Like valid_device_node_path(), but also allows full-subsystem expressions like those accepted by
* DeviceAllow= and DeviceDeny=. */
if (STARTSWITH_SET(path, "block-", "char-"))
return true;
@@ -1401,8 +1401,8 @@ bool dot_or_dot_dot(const char *path) {
bool empty_or_root(const char *path) {
/* For operations relative to some root directory, returns true if the specified root directory is redundant,
* i.e. either / or NULL or the empty string or any equivalent. */
/* For operations relative to some root directory, returns true if the specified root directory is
* redundant, i.e. either / or NULL or the empty string or any equivalent. */
if (isempty(path))
return true;
+26 -40
View File
@@ -64,10 +64,10 @@ static int prepare_restrict_fs_bpf(struct restrict_fs_bpf **ret_obj) {
/* TODO Maybe choose a number based on runtime information? */
r = sym_bpf_map__resize(obj->maps.cgroup_hash, CGROUP_HASH_SIZE_MAX);
if (r != 0)
return log_error_errno(r,
"Failed to resize BPF map '%s': %m",
sym_bpf_map__name(obj->maps.cgroup_hash));
assert(r <= 0);
if (r < 0)
return log_error_errno(r, "Failed to resize BPF map '%s': %m",
sym_bpf_map__name(obj->maps.cgroup_hash));
/* Dummy map to satisfy the verifier */
inner_map_fd = sym_bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(uint32_t), sizeof(uint32_t), 128, 0);
@@ -75,11 +75,13 @@ static int prepare_restrict_fs_bpf(struct restrict_fs_bpf **ret_obj) {
return log_error_errno(errno, "Failed to create BPF map: %m");
r = sym_bpf_map__set_inner_map_fd(obj->maps.cgroup_hash, inner_map_fd);
assert(r <= 0);
if (r < 0)
return log_error_errno(r, "Failed to set inner map fd: %m");
r = restrict_fs_bpf__load(obj);
if (r)
assert(r <= 0);
if (r < 0)
return log_error_errno(r, "Failed to load BPF object");
*ret_obj = TAKE_PTR(obj);
@@ -99,34 +101,27 @@ static int mac_bpf_use(void) {
r = read_one_line_file("/sys/kernel/security/lsm", &lsm_list);
if (r < 0) {
if (errno != ENOENT)
log_debug_errno(r, "Failed to read /sys/kernel/security/lsm, ignoring: %m");
if (r != -ENOENT)
log_notice_errno(r, "Failed to read /sys/kernel/security/lsm, assuming bpf is unavailable: %m");
return 0;
}
const char *p = lsm_list;
for (;;) {
for (const char *p = lsm_list;;) {
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, ",", 0);
if (r == 0)
break;
return 0;
if (r == -ENOMEM)
return log_oom();
if (r < 0) {
log_debug_errno(r, "Failed to parse /sys/kernel/security/lsm, ignoring: %m");
log_notice_errno(r, "Failed to parse /sys/kernel/security/lsm, assuming bpf is unavailable: %m");
return 0;
}
if (streq(word, "bpf")) {
cached_use = 1;
break;
}
if (streq(word, "bpf"))
return cached_use = 1;
}
return cached_use;
}
int lsm_bpf_supported(void) {
@@ -181,7 +176,7 @@ int lsm_bpf_supported(void) {
}
int lsm_bpf_setup(Manager *m) {
struct restrict_fs_bpf *obj = NULL;
struct restrict_fs_bpf *obj;
_cleanup_(bpf_link_freep) struct bpf_link *link = NULL;
int r;
@@ -207,7 +202,6 @@ int lsm_bpf_setup(Manager *m) {
}
int lsm_bpf_unit_restrict_filesystems(Unit *u, const Set *filesystems, bool allow_list) {
int inner_map_fd = -1, outer_map_fd = -1;
uint32_t dummy_value = 1, zero = 0;
const char *fs;
const statfs_f_type_t *magic;
@@ -216,7 +210,7 @@ int lsm_bpf_unit_restrict_filesystems(Unit *u, const Set *filesystems, bool allo
assert(filesystems);
assert(u);
inner_map_fd = sym_bpf_create_map(
int inner_map_fd = sym_bpf_create_map(
BPF_MAP_TYPE_HASH,
sizeof(uint32_t),
sizeof(uint32_t),
@@ -225,7 +219,7 @@ int lsm_bpf_unit_restrict_filesystems(Unit *u, const Set *filesystems, bool allo
if (inner_map_fd < 0)
return log_unit_error_errno(u, errno, "Failed to create inner LSM map: %m");
outer_map_fd = sym_bpf_map__fd(u->manager->restrict_fs->maps.cgroup_hash);
int outer_map_fd = sym_bpf_map__fd(u->manager->restrict_fs->maps.cgroup_hash);
if (outer_map_fd < 0)
return log_unit_error_errno(u, errno, "Failed to get BPF map fd: %m");
@@ -266,8 +260,6 @@ int lsm_bpf_unit_restrict_filesystems(Unit *u, const Set *filesystems, bool allo
}
int lsm_bpf_cleanup(const Unit *u) {
int fd = -1;
assert(u);
assert(u->manager);
@@ -277,7 +269,7 @@ int lsm_bpf_cleanup(const Unit *u) {
if (!u->manager->restrict_fs)
return 0;
fd = sym_bpf_map__fd(u->manager->restrict_fs->maps.cgroup_hash);
int fd = sym_bpf_map__fd(u->manager->restrict_fs->maps.cgroup_hash);
if (fd < 0)
return log_unit_error_errno(u, errno, "Failed to get BPF map fd: %m");
@@ -350,10 +342,10 @@ int lsm_bpf_parse_filesystem(
}
NULSTR_FOREACH(i, set->value) {
/* Call ourselves again, for the group to parse. Note that we downgrade logging here (i.e. take
* away the FILESYSTEM_PARSE_LOG flag) since any issues in the group table are our own problem,
* not a problem in user configuration data and we shouldn't pretend otherwise by complaining
* about them. */
/* Call ourselves again, for the group to parse. Note that we downgrade logging here
* (i.e. take away the FILESYSTEM_PARSE_LOG flag) since any issues in the group table
* are our own problem, not a problem in user configuration data and we shouldn't
* pretend otherwise by complaining about them. */
r = lsm_bpf_parse_filesystem(i, filesystems, flags &~ FILESYSTEM_PARSE_LOG, unit, filename, line);
if (r < 0)
return r;
@@ -363,16 +355,10 @@ int lsm_bpf_parse_filesystem(
* we want to allow it, then remove it from the list. */
if (!(flags & FILESYSTEM_PARSE_INVERT) == !!(flags & FILESYSTEM_PARSE_ALLOW_LIST)) {
r = set_put_strdup(filesystems, name);
if (r < 0)
switch (r) {
case -ENOMEM:
return flags & FILESYSTEM_PARSE_LOG ? log_oom() : -ENOMEM;
case -EEXIST:
/* Already in set, ignore */
break;
default:
return r;
}
if (r == -ENOMEM)
return flags & FILESYSTEM_PARSE_LOG ? log_oom() : -ENOMEM;
if (r < 0 && r != -EEXIST) /* When already in set, ignore */
return r;
} else
free(set_remove(*filesystems, name));
}
+2 -4
View File
@@ -51,13 +51,11 @@ static int test_restrict_filesystems(Manager *m, const char *unit_name, const ch
}
cld_code = SERVICE(u)->exec_command[SERVICE_EXEC_START]->exec_status.code;
if (cld_code != CLD_EXITED) {
if (cld_code != CLD_EXITED)
return log_error_errno(-SYNTHETIC_ERRNO(EBUSY), "ExecStart didn't exited, code='%s'", sigchld_code_to_string(cld_code));
}
if (SERVICE(u)->state != SERVICE_DEAD) {
if (SERVICE(u)->state != SERVICE_DEAD)
return log_error_errno(-SYNTHETIC_ERRNO(EBUSY), "Service is not dead");
}
return 0;
}
+17 -20
View File
@@ -6,27 +6,24 @@
#include "unit.h"
int main(int argc, char *argv[]) {
JobType a, b, c, ab, bc, ab_c, bc_a, a_bc;
const ServiceState test_states[] = { SERVICE_DEAD, SERVICE_RUNNING };
unsigned i;
bool merged_ab;
/* fake a unit */
static Service s = {
.meta.load_state = UNIT_LOADED,
.type = SERVICE_SIMPLE,
};
Unit *u = UNIT(&s);
for (size_t i = 0; i < ELEMENTSOF(test_states); i++) {
/* fake a unit */
Service s = {
.meta.load_state = UNIT_LOADED,
.type = SERVICE_SIMPLE,
.state = test_states[i],
};
Unit *u = UNIT(&s);
for (i = 0; i < ELEMENTSOF(test_states); i++) {
s.state = test_states[i];
printf("\nWith collapsing for service state %s\n"
"=========================================\n", service_state_to_string(s.state));
for (a = 0; a < _JOB_TYPE_MAX_MERGING; a++) {
for (b = 0; b < _JOB_TYPE_MAX_MERGING; b++) {
for (JobType a = 0; a < _JOB_TYPE_MAX_MERGING; a++) {
for (JobType b = 0; b < _JOB_TYPE_MAX_MERGING; b++) {
ab = a;
merged_ab = (job_type_merge_and_collapse(&ab, b, u) >= 0);
JobType ab = a;
bool merged_ab = job_type_merge_and_collapse(&ab, b, u) >= 0;
if (!job_type_is_mergeable(a, b)) {
assert_se(!merged_ab);
@@ -37,7 +34,7 @@ int main(int argc, char *argv[]) {
assert_se(merged_ab);
printf("%s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(ab));
for (c = 0; c < _JOB_TYPE_MAX_MERGING; c++) {
for (JobType c = 0; c < _JOB_TYPE_MAX_MERGING; c++) {
/* Verify transitivity of mergeability of job types */
assert_se(!job_type_is_mergeable(a, b) ||
@@ -53,18 +50,18 @@ int main(int argc, char *argv[]) {
* either a or b is not mergeable with c either. */
assert_se(job_type_is_mergeable(ab, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c));
bc = b;
JobType bc = b;
if (job_type_merge_and_collapse(&bc, c, u) >= 0) {
/* Verify associativity */
ab_c = ab;
JobType ab_c = ab;
assert_se(job_type_merge_and_collapse(&ab_c, c, u) == 0);
bc_a = bc;
JobType bc_a = bc;
assert_se(job_type_merge_and_collapse(&bc_a, a, u) == 0);
a_bc = a;
JobType a_bc = a;
assert_se(job_type_merge_and_collapse(&a_bc, bc, u) == 0);
assert_se(ab_c == bc_a);