mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
tree-wide: replace FOREACH_POINTER with FOREACH_ARGUMENT
The latter is more generic and while being compatible with the former.
This commit is contained in:
parent
e9a46668c3
commit
2d70878162
@ -266,12 +266,6 @@ static inline int __coverity_check_and_return__(int condition) {
|
||||
/* Pointers range from NULL to POINTER_MAX */
|
||||
#define POINTER_MAX ((void*) UINTPTR_MAX)
|
||||
|
||||
/* Iterates through a specified list of pointers. Accepts NULL pointers, but uses POINTER_MAX as internal marker for EOL. */
|
||||
#define FOREACH_POINTER(p, x, ...) \
|
||||
for (typeof(p) *_l = (typeof(p)[]) { ({ p = x; }), ##__VA_ARGS__, POINTER_MAX }; \
|
||||
p != (typeof(p)) POINTER_MAX; \
|
||||
p = *(++_l))
|
||||
|
||||
#define _FOREACH_ARRAY(i, array, num, m, end) \
|
||||
for (typeof(array[0]) *i = (array), *end = ({ \
|
||||
typeof(num) m = (num); \
|
||||
|
@ -446,14 +446,15 @@ bool fstype_needs_quota(const char *fstype) {
|
||||
}
|
||||
|
||||
bool fstype_is_api_vfs(const char *fstype) {
|
||||
const FilesystemSet *fs;
|
||||
assert(fstype);
|
||||
|
||||
FOREACH_POINTER(fs,
|
||||
filesystem_sets + FILESYSTEM_SET_BASIC_API,
|
||||
filesystem_sets + FILESYSTEM_SET_AUXILIARY_API,
|
||||
filesystem_sets + FILESYSTEM_SET_PRIVILEGED_API,
|
||||
filesystem_sets + FILESYSTEM_SET_TEMPORARY)
|
||||
if (nulstr_contains(fs->value, fstype))
|
||||
const FilesystemSet *fs;
|
||||
FOREACH_ARGUMENT(fs,
|
||||
filesystem_sets + FILESYSTEM_SET_BASIC_API,
|
||||
filesystem_sets + FILESYSTEM_SET_AUXILIARY_API,
|
||||
filesystem_sets + FILESYSTEM_SET_PRIVILEGED_API,
|
||||
filesystem_sets + FILESYSTEM_SET_TEMPORARY)
|
||||
if (nulstr_contains(fs->value, fstype))
|
||||
return true;
|
||||
|
||||
/* Filesystems not present in the internal database */
|
||||
|
@ -3959,7 +3959,7 @@ static int unit_pid_set(Unit *u, Set **pid_set) {
|
||||
/* Exclude the main/control pids from being killed via the cgroup */
|
||||
|
||||
PidRef *pid;
|
||||
FOREACH_POINTER(pid, unit_main_pid(u), unit_control_pid(u))
|
||||
FOREACH_ARGUMENT(pid, unit_main_pid(u), unit_control_pid(u))
|
||||
if (pidref_is_set(pid)) {
|
||||
r = set_ensure_put(pid_set, NULL, PID_TO_PTR(pid->pid));
|
||||
if (r < 0)
|
||||
|
@ -219,7 +219,6 @@ static int fscrypt_setup(
|
||||
_cleanup_free_ char *value = NULL;
|
||||
size_t salt_size, encrypted_size;
|
||||
const char *nr, *e;
|
||||
char **list;
|
||||
int n;
|
||||
|
||||
/* Check if this xattr has the format 'trusted.fscrypt_slot<nr>' where '<nr>' is a 32-bit unsigned integer */
|
||||
@ -248,21 +247,19 @@ static int fscrypt_setup(
|
||||
return log_error_errno(r, "Failed to decode encrypted key of %s: %m", xa);
|
||||
|
||||
r = -ENOANO;
|
||||
FOREACH_POINTER(list, cache->pkcs11_passwords, cache->fido2_passwords, password) {
|
||||
char **list;
|
||||
FOREACH_ARGUMENT(list, cache->pkcs11_passwords, cache->fido2_passwords, password) {
|
||||
r = fscrypt_slot_try_many(
|
||||
list,
|
||||
salt, salt_size,
|
||||
encrypted, encrypted_size,
|
||||
setup->fscrypt_key_descriptor,
|
||||
ret_volume_key, ret_volume_key_size);
|
||||
if (r != -ENOANO)
|
||||
break;
|
||||
}
|
||||
if (r < 0) {
|
||||
if (r >= 0)
|
||||
return 0;
|
||||
if (r != -ENOANO)
|
||||
return r;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENOKEY), "Failed to set up home directory with provided passwords.");
|
||||
|
@ -365,7 +365,6 @@ static int luks_setup(
|
||||
_cleanup_(erase_and_freep) void *vk = NULL;
|
||||
sd_id128_t p;
|
||||
size_t vks;
|
||||
char **list;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
@ -419,11 +418,13 @@ static int luks_setup(
|
||||
return log_oom();
|
||||
|
||||
r = -ENOKEY;
|
||||
FOREACH_POINTER(list,
|
||||
cache ? cache->keyring_passswords : NULL,
|
||||
cache ? cache->pkcs11_passwords : NULL,
|
||||
cache ? cache->fido2_passwords : NULL,
|
||||
passwords) {
|
||||
char **list;
|
||||
FOREACH_ARGUMENT(list,
|
||||
cache ? cache->keyring_passswords : NULL,
|
||||
cache ? cache->pkcs11_passwords : NULL,
|
||||
cache ? cache->fido2_passwords : NULL,
|
||||
passwords) {
|
||||
|
||||
r = luks_try_passwords(h, cd, list, vk, &vks, ret_key_serial ? &key_serial : NULL);
|
||||
if (r != -ENOKEY)
|
||||
break;
|
||||
@ -519,7 +520,6 @@ static int luks_open(
|
||||
|
||||
_cleanup_(erase_and_freep) void *vk = NULL;
|
||||
sd_id128_t p;
|
||||
char **list;
|
||||
size_t vks;
|
||||
int r;
|
||||
|
||||
@ -560,11 +560,13 @@ static int luks_open(
|
||||
return log_oom();
|
||||
|
||||
r = -ENOKEY;
|
||||
FOREACH_POINTER(list,
|
||||
cache ? cache->keyring_passswords : NULL,
|
||||
cache ? cache->pkcs11_passwords : NULL,
|
||||
cache ? cache->fido2_passwords : NULL,
|
||||
h->password) {
|
||||
char **list;
|
||||
FOREACH_ARGUMENT(list,
|
||||
cache ? cache->keyring_passswords : NULL,
|
||||
cache ? cache->pkcs11_passwords : NULL,
|
||||
cache ? cache->fido2_passwords : NULL,
|
||||
h->password) {
|
||||
|
||||
r = luks_try_passwords(h, setup->crypt_device, list, vk, &vks, NULL);
|
||||
if (r != -ENOKEY)
|
||||
break;
|
||||
@ -3583,7 +3585,6 @@ int home_passwd_luks(
|
||||
_cleanup_(erase_and_freep) void *volume_key = NULL;
|
||||
struct crypt_pbkdf_type good_pbkdf, minimal_pbkdf;
|
||||
const char *type;
|
||||
char **list;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
@ -3613,11 +3614,12 @@ int home_passwd_luks(
|
||||
return log_oom();
|
||||
|
||||
r = -ENOKEY;
|
||||
FOREACH_POINTER(list,
|
||||
cache ? cache->keyring_passswords : NULL,
|
||||
cache ? cache->pkcs11_passwords : NULL,
|
||||
cache ? cache->fido2_passwords : NULL,
|
||||
h->password) {
|
||||
char **list;
|
||||
FOREACH_ARGUMENT(list,
|
||||
cache ? cache->keyring_passswords : NULL,
|
||||
cache ? cache->pkcs11_passwords : NULL,
|
||||
cache ? cache->fido2_passwords : NULL,
|
||||
h->password) {
|
||||
|
||||
r = luks_try_passwords(h, setup->crypt_device, list, volume_key, &volume_key_size, NULL);
|
||||
if (r != -ENOKEY)
|
||||
@ -3736,7 +3738,6 @@ static int luks_try_resume(
|
||||
}
|
||||
|
||||
int home_unlock_luks(UserRecord *h, HomeSetup *setup, const PasswordCache *cache) {
|
||||
char **list;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
@ -3750,10 +3751,12 @@ int home_unlock_luks(UserRecord *h, HomeSetup *setup, const PasswordCache *cache
|
||||
log_info("Discovered used LUKS device %s.", setup->dm_node);
|
||||
|
||||
r = -ENOKEY;
|
||||
FOREACH_POINTER(list,
|
||||
cache ? cache->pkcs11_passwords : NULL,
|
||||
cache ? cache->fido2_passwords : NULL,
|
||||
h->password) {
|
||||
char **list;
|
||||
FOREACH_ARGUMENT(list,
|
||||
cache ? cache->pkcs11_passwords : NULL,
|
||||
cache ? cache->fido2_passwords : NULL,
|
||||
h->password) {
|
||||
|
||||
r = luks_try_resume(setup->crypt_device, setup->dm_name, list);
|
||||
if (r != -ENOKEY)
|
||||
break;
|
||||
|
@ -550,7 +550,6 @@ int pull_verify(ImportVerify verify,
|
||||
log_debug("Main download is a checksum file, can't validate its checksum with itself, skipping.");
|
||||
verify_job = main_job;
|
||||
} else {
|
||||
PullJob *j;
|
||||
assert(main_job->calc_checksum);
|
||||
assert(main_job->checksum);
|
||||
assert(checksum_job);
|
||||
@ -560,7 +559,8 @@ int pull_verify(ImportVerify verify,
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
|
||||
"Checksum is empty, cannot verify.");
|
||||
|
||||
FOREACH_POINTER(j, main_job, settings_job, roothash_job, roothash_signature_job, verity_job) {
|
||||
PullJob *j;
|
||||
FOREACH_ARGUMENT(j, main_job, settings_job, roothash_job, roothash_signature_job, verity_job) {
|
||||
r = verify_one(checksum_job, j);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -495,7 +495,6 @@ static int raw_pull_rename_auxiliary_file(
|
||||
|
||||
static void raw_pull_job_on_finished(PullJob *j) {
|
||||
RawPull *i;
|
||||
PullJob *jj;
|
||||
int r;
|
||||
|
||||
assert(j);
|
||||
@ -568,8 +567,9 @@ static void raw_pull_job_on_finished(PullJob *j) {
|
||||
}
|
||||
}
|
||||
|
||||
PullJob *jj;
|
||||
/* Let's close these auxiliary files now, we don't need access to them anymore. */
|
||||
FOREACH_POINTER(jj, i->settings_job, i->roothash_job, i->roothash_signature_job, i->verity_job)
|
||||
FOREACH_ARGUMENT(jj, i->settings_job, i->roothash_job, i->roothash_signature_job, i->verity_job)
|
||||
pull_job_close_disk_fd(jj);
|
||||
|
||||
if (!i->raw_job->etag_exists) {
|
||||
@ -820,7 +820,6 @@ int raw_pull_start(
|
||||
ImportVerify verify,
|
||||
const char *checksum) {
|
||||
|
||||
PullJob *j;
|
||||
int r;
|
||||
|
||||
assert(i);
|
||||
@ -959,14 +958,15 @@ int raw_pull_start(
|
||||
return r;
|
||||
}
|
||||
|
||||
FOREACH_POINTER(j,
|
||||
i->raw_job,
|
||||
i->checksum_job,
|
||||
i->signature_job,
|
||||
i->settings_job,
|
||||
i->roothash_job,
|
||||
i->roothash_signature_job,
|
||||
i->verity_job) {
|
||||
PullJob *j;
|
||||
FOREACH_ARGUMENT(j,
|
||||
i->raw_job,
|
||||
i->checksum_job,
|
||||
i->signature_job,
|
||||
i->settings_job,
|
||||
i->roothash_job,
|
||||
i->roothash_signature_job,
|
||||
i->verity_job) {
|
||||
|
||||
if (!j)
|
||||
continue;
|
||||
|
@ -581,7 +581,6 @@ int tar_pull_start(
|
||||
ImportVerify verify,
|
||||
const char *checksum) {
|
||||
|
||||
PullJob *j;
|
||||
int r;
|
||||
|
||||
assert(i);
|
||||
@ -656,11 +655,12 @@ int tar_pull_start(
|
||||
return r;
|
||||
}
|
||||
|
||||
FOREACH_POINTER(j,
|
||||
i->tar_job,
|
||||
i->checksum_job,
|
||||
i->signature_job,
|
||||
i->settings_job) {
|
||||
PullJob *j;
|
||||
FOREACH_ARGUMENT(j,
|
||||
i->tar_job,
|
||||
i->checksum_job,
|
||||
i->signature_job,
|
||||
i->settings_job) {
|
||||
|
||||
if (!j)
|
||||
continue;
|
||||
|
@ -92,7 +92,7 @@ static int manager_link_is_online(Manager *m, Link *l, const LinkOperationalStat
|
||||
l->state);
|
||||
|
||||
const LinkOperationalStateRange *range;
|
||||
FOREACH_POINTER(range, state_range, &m->required_operstate, &l->required_operstate)
|
||||
FOREACH_ARGUMENT(range, state_range, &m->required_operstate, &l->required_operstate)
|
||||
if (operational_state_range_is_valid(range))
|
||||
break;
|
||||
assert(range != POINTER_MAX);
|
||||
|
@ -141,7 +141,6 @@ static int condition_test_kernel_command_line(Condition *c, char **env) {
|
||||
}
|
||||
|
||||
static int condition_test_credential(Condition *c, char **env) {
|
||||
int (*gd)(const char **ret);
|
||||
int r;
|
||||
|
||||
assert(c);
|
||||
@ -155,7 +154,8 @@ static int condition_test_credential(Condition *c, char **env) {
|
||||
if (!credential_name_valid(c->parameter)) /* credentials with invalid names do not exist */
|
||||
return false;
|
||||
|
||||
FOREACH_POINTER(gd, get_credentials_dir, get_encrypted_credentials_dir) {
|
||||
int (*gd)(const char **ret);
|
||||
FOREACH_ARGUMENT(gd, get_credentials_dir, get_encrypted_credentials_dir) {
|
||||
_cleanup_free_ char *j = NULL;
|
||||
const char *cd;
|
||||
|
||||
|
@ -221,85 +221,6 @@ TEST(IN_SET) {
|
||||
assert_se(!IN_SET(t.x, 2, 3, 4));
|
||||
}
|
||||
|
||||
TEST(FOREACH_POINTER) {
|
||||
int a, b, c, *i;
|
||||
size_t k = 0;
|
||||
|
||||
FOREACH_POINTER(i, &a, &b, &c) {
|
||||
switch (k) {
|
||||
|
||||
case 0:
|
||||
assert_se(i == &a);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
assert_se(i == &b);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
assert_se(i == &c);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert_not_reached();
|
||||
break;
|
||||
}
|
||||
|
||||
k++;
|
||||
}
|
||||
|
||||
assert_se(k == 3);
|
||||
|
||||
FOREACH_POINTER(i, &b) {
|
||||
assert_se(k == 3);
|
||||
assert_se(i == &b);
|
||||
k = 4;
|
||||
}
|
||||
|
||||
assert_se(k == 4);
|
||||
|
||||
FOREACH_POINTER(i, NULL, &c, NULL, &b, NULL, &a, NULL) {
|
||||
switch (k) {
|
||||
|
||||
case 4:
|
||||
assert_se(i == NULL);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
assert_se(i == &c);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
assert_se(i == NULL);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
assert_se(i == &b);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
assert_se(i == NULL);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
assert_se(i == &a);
|
||||
break;
|
||||
|
||||
case 10:
|
||||
assert_se(i == NULL);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert_not_reached();
|
||||
break;
|
||||
}
|
||||
|
||||
k++;
|
||||
}
|
||||
|
||||
assert_se(k == 11);
|
||||
}
|
||||
|
||||
TEST(FOREACH_ARGUMENT) {
|
||||
size_t i;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user