mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-24 21:34:08 +03:00
Merge pull request #22835 from keszybz/foreach_string-inline-iterator
Inline the iterator declaration in FOREACH_STRING
This commit is contained in:
commit
904447ce5a
@ -123,7 +123,6 @@ static int open_sockets(int *epoll_fd, bool accept) {
|
||||
|
||||
static int exec_process(const char *name, char **argv, int start_fd, size_t n_fds) {
|
||||
_cleanup_strv_free_ char **envp = NULL;
|
||||
const char *var;
|
||||
int r;
|
||||
|
||||
if (arg_inetd && n_fds != 1)
|
||||
|
@ -570,7 +570,6 @@ int get_files_in_directory(const char *path, char ***list) {
|
||||
}
|
||||
|
||||
static int getenv_tmp_dir(const char **ret_path) {
|
||||
const char *n;
|
||||
int r, ret = 0;
|
||||
|
||||
assert(ret_path);
|
||||
|
@ -170,8 +170,6 @@ int open_extension_release(const char *root, const char *extension, char **ret_p
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const char *p;
|
||||
|
||||
FOREACH_STRING(p, "/etc/os-release", "/usr/lib/os-release") {
|
||||
r = chase_symlinks(p, root, CHASE_PREFIX_ROOT,
|
||||
ret_path ? &q : NULL,
|
||||
|
@ -218,7 +218,7 @@ void strv_print(char * const *l);
|
||||
})
|
||||
|
||||
#define _FOREACH_STRING(uniq, x, y, ...) \
|
||||
for (char **UNIQ_T(l, uniq) = STRV_MAKE(({ x = y; }), ##__VA_ARGS__); \
|
||||
for (const char *x, * const*UNIQ_T(l, uniq) = STRV_MAKE_CONST(({ x = y; }), ##__VA_ARGS__); \
|
||||
x; \
|
||||
x = *(++UNIQ_T(l, uniq)))
|
||||
|
||||
|
@ -236,7 +236,6 @@ bool lookup_paths_timestamp_hash_same(const LookupPaths *lp, uint64_t timestamp_
|
||||
}
|
||||
|
||||
static int directory_name_is_valid(const char *name) {
|
||||
const char *suffix;
|
||||
|
||||
/* Accept a directory whose name is a valid unit file name ending in .wants/, .requires/ or .d/ */
|
||||
|
||||
|
@ -1255,12 +1255,11 @@ static int remove_variables(sd_id128_t uuid, const char *path, bool in_order) {
|
||||
}
|
||||
|
||||
static int remove_loader_variables(void) {
|
||||
const char *variable;
|
||||
int r = 0;
|
||||
|
||||
/* Remove all persistent loader variables we define */
|
||||
|
||||
FOREACH_STRING(variable,
|
||||
FOREACH_STRING(var,
|
||||
EFI_LOADER_VARIABLE(LoaderConfigTimeout),
|
||||
EFI_LOADER_VARIABLE(LoaderConfigTimeoutOneShot),
|
||||
EFI_LOADER_VARIABLE(LoaderEntryDefault),
|
||||
@ -1269,15 +1268,15 @@ static int remove_loader_variables(void) {
|
||||
|
||||
int q;
|
||||
|
||||
q = efi_set_variable(variable, NULL, 0);
|
||||
q = efi_set_variable(var, NULL, 0);
|
||||
if (q == -ENOENT)
|
||||
continue;
|
||||
if (q < 0) {
|
||||
log_warning_errno(q, "Failed to remove EFI variable %s: %m", variable);
|
||||
log_warning_errno(q, "Failed to remove EFI variable %s: %m", var);
|
||||
if (r >= 0)
|
||||
r = q;
|
||||
} else
|
||||
log_info("Removed EFI variable %s.", variable);
|
||||
log_info("Removed EFI variable %s.", var);
|
||||
}
|
||||
|
||||
return r;
|
||||
|
@ -510,7 +510,6 @@ static int refresh_one(
|
||||
}
|
||||
|
||||
static int refresh(const char *root, Hashmap *a, Hashmap *b, unsigned iteration) {
|
||||
const char *c;
|
||||
int r;
|
||||
|
||||
FOREACH_STRING(c, SYSTEMD_CGROUP_CONTROLLER, "cpu", "cpuacct", "memory", "io", "blkio", "pids") {
|
||||
|
@ -24,7 +24,6 @@ int mac_apparmor_setup(void) {
|
||||
#if HAVE_APPARMOR
|
||||
_cleanup_(aa_policy_cache_unrefp) aa_policy_cache *policy_cache = NULL;
|
||||
_cleanup_(aa_features_unrefp) aa_features *features = NULL;
|
||||
const char *current_file;
|
||||
_cleanup_free_ char *current_profile = NULL, *cache_dir_path = NULL;
|
||||
int r;
|
||||
|
||||
|
@ -786,7 +786,6 @@ void cgroup_oomd_xattr_apply(Unit *u, const char *cgroup_path) {
|
||||
}
|
||||
|
||||
static void cgroup_xattr_apply(Unit *u) {
|
||||
const char *xn;
|
||||
bool b;
|
||||
|
||||
assert(u);
|
||||
|
@ -20,24 +20,23 @@
|
||||
* is suitably validated. */
|
||||
|
||||
static void lock_down_efi_variables(void) {
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
/* Paranoia: let's restrict access modes of these a bit, so that unprivileged users can't use them to
|
||||
* identify the system or gain too much insight into what we might have credited to the entropy
|
||||
* pool. */
|
||||
FOREACH_STRING(p,
|
||||
FOREACH_STRING(path,
|
||||
EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderRandomSeed)),
|
||||
EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderSystemToken))) {
|
||||
|
||||
r = chattr_path(p, 0, FS_IMMUTABLE_FL, NULL);
|
||||
r = chattr_path(path, 0, FS_IMMUTABLE_FL, NULL);
|
||||
if (r == -ENOENT)
|
||||
continue;
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to drop FS_IMMUTABLE_FL from %s, ignoring: %m", p);
|
||||
log_warning_errno(r, "Failed to drop FS_IMMUTABLE_FL from %s, ignoring: %m", path);
|
||||
|
||||
if (chmod(p, 0600) < 0)
|
||||
log_warning_errno(errno, "Failed to reduce access mode of %s, ignoring: %m", p);
|
||||
if (chmod(path, 0600) < 0)
|
||||
log_warning_errno(errno, "Failed to reduce access mode of %s, ignoring: %m", path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3043,7 +3043,6 @@ static int setup_credentials(
|
||||
uid_t uid) {
|
||||
|
||||
_cleanup_free_ char *p = NULL, *q = NULL;
|
||||
const char *i;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
|
@ -99,8 +99,6 @@ static int timer_add_default_dependencies(Timer *t) {
|
||||
return r;
|
||||
|
||||
LIST_FOREACH(value, v, t->values) {
|
||||
const char *target;
|
||||
|
||||
if (v->base != TIMER_CALENDAR)
|
||||
continue;
|
||||
|
||||
|
@ -4133,7 +4133,6 @@ int unit_patch_contexts(Unit *u) {
|
||||
|
||||
if ((ec->root_image || !LIST_IS_EMPTY(ec->mount_images)) &&
|
||||
(cc->device_policy != CGROUP_DEVICE_POLICY_AUTO || cc->device_allow)) {
|
||||
const char *p;
|
||||
|
||||
/* When RootImage= or MountImages= is specified, the following devices are touched. */
|
||||
FOREACH_STRING(p, "/dev/loop-control", "/dev/mapper/control") {
|
||||
|
@ -215,9 +215,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Automatically add in a serial getty on the first
|
||||
* virtualizer console */
|
||||
const char *j;
|
||||
/* Automatically add in a serial getty on the first virtualizer console */
|
||||
FOREACH_STRING(j,
|
||||
"hvc0",
|
||||
"xvc0",
|
||||
|
@ -2949,8 +2949,6 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
case ARG_DISK_SIZE:
|
||||
if (isempty(optarg)) {
|
||||
const char *prop;
|
||||
|
||||
FOREACH_STRING(prop, "diskSize", "diskSizeRelative", "rebalanceWeight") {
|
||||
r = drop_from_identity(prop);
|
||||
if (r < 0)
|
||||
@ -3452,9 +3450,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ARG_PKCS11_TOKEN_URI: {
|
||||
const char *p;
|
||||
|
||||
case ARG_PKCS11_TOKEN_URI:
|
||||
if (streq(optarg, "list"))
|
||||
return pkcs11_list_tokens();
|
||||
|
||||
@ -3488,11 +3484,8 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
strv_uniq(arg_pkcs11_token_uri);
|
||||
break;
|
||||
}
|
||||
|
||||
case ARG_FIDO2_DEVICE: {
|
||||
const char *p;
|
||||
|
||||
case ARG_FIDO2_DEVICE:
|
||||
if (streq(optarg, "list"))
|
||||
return fido2_list_devices();
|
||||
|
||||
@ -3522,7 +3515,6 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
strv_uniq(arg_fido2_device);
|
||||
break;
|
||||
}
|
||||
|
||||
case ARG_FIDO2_WITH_PIN: {
|
||||
bool lock_with_pin;
|
||||
@ -3557,9 +3549,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ARG_RECOVERY_KEY: {
|
||||
const char *p;
|
||||
|
||||
case ARG_RECOVERY_KEY:
|
||||
r = parse_boolean(optarg);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --recovery-key= argument: %s", optarg);
|
||||
@ -3573,7 +3563,6 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ARG_AUTO_RESIZE_MODE:
|
||||
if (isempty(optarg)) {
|
||||
|
@ -482,7 +482,6 @@ static int manager_enumerate_records(Manager *m) {
|
||||
static int search_quota(uid_t uid, const char *exclude_quota_path) {
|
||||
struct stat exclude_st = {};
|
||||
dev_t previous_devno = 0;
|
||||
const char *where;
|
||||
int r;
|
||||
|
||||
/* Checks whether the specified UID owns any files on the files system, but ignore any file system
|
||||
|
@ -332,7 +332,6 @@ _public_ int sd_device_new_from_subsystem_sysname(
|
||||
const char *subsystem,
|
||||
const char *sysname) {
|
||||
|
||||
const char *s;
|
||||
char *name;
|
||||
int r;
|
||||
|
||||
@ -341,7 +340,6 @@ _public_ int sd_device_new_from_subsystem_sysname(
|
||||
assert_return(path_is_normalized(sysname), -EINVAL);
|
||||
|
||||
if (streq(subsystem, "subsystem")) {
|
||||
|
||||
FOREACH_STRING(s, "/sys/subsystem/", "/sys/bus/", "/sys/class/") {
|
||||
r = device_strjoin_new(s, sysname, NULL, NULL, ret);
|
||||
if (r < 0)
|
||||
@ -351,7 +349,6 @@ _public_ int sd_device_new_from_subsystem_sysname(
|
||||
}
|
||||
|
||||
} else if (streq(subsystem, "module")) {
|
||||
|
||||
r = device_strjoin_new("/sys/module/", sysname, NULL, NULL, ret);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -363,9 +360,8 @@ _public_ int sd_device_new_from_subsystem_sysname(
|
||||
|
||||
sep = strchr(sysname, ':');
|
||||
if (sep && sep[1] != '\0') { /* Require ":" and something non-empty after that. */
|
||||
const char *subsys;
|
||||
|
||||
subsys = memdupa_suffix0(sysname, sep - sysname);
|
||||
const char *subsys = memdupa_suffix0(sysname, sep - sysname);
|
||||
sep++;
|
||||
|
||||
FOREACH_STRING(s, "/sys/subsystem/", "/sys/bus/") {
|
||||
|
@ -474,7 +474,7 @@ static int method_set_locale(sd_bus_message *m, void *userdata, sd_bus_error *er
|
||||
|
||||
static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_error *error) {
|
||||
Context *c = userdata;
|
||||
const char *name, *keymap, *keymap_toggle;
|
||||
const char *keymap, *keymap_toggle;
|
||||
int convert, interactive, r;
|
||||
|
||||
assert(m);
|
||||
|
@ -627,7 +627,6 @@ int user_check_linger_file(User *u) {
|
||||
}
|
||||
|
||||
static bool user_unit_active(User *u) {
|
||||
const char *i;
|
||||
int r;
|
||||
|
||||
assert(u->service);
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
static int chown_cgroup_path(const char *path, uid_t uid_shift) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
const char *fn;
|
||||
|
||||
fd = open(path, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
|
||||
if (fd < 0)
|
||||
|
@ -404,7 +404,7 @@ int tmpfs_patch_options(
|
||||
}
|
||||
|
||||
int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {
|
||||
const char *full, *top, *x;
|
||||
const char *full, *top;
|
||||
int r;
|
||||
unsigned long extra_flags = 0;
|
||||
|
||||
@ -464,7 +464,7 @@ int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {
|
||||
/* Create mountpoint for cgroups. Otherwise we are not allowed since we
|
||||
* remount /sys read-only.
|
||||
*/
|
||||
x = prefix_roota(top, "/fs/cgroup");
|
||||
const char *x = prefix_roota(top, "/fs/cgroup");
|
||||
(void) mkdir_p(x, 0755);
|
||||
|
||||
return mount_nofollow_verbose(LOG_ERR, NULL, top, NULL,
|
||||
|
@ -2564,7 +2564,7 @@ static int setup_hostname(void) {
|
||||
|
||||
static int setup_journal(const char *directory) {
|
||||
_cleanup_free_ char *d = NULL;
|
||||
const char *dirname, *p, *q;
|
||||
const char *p, *q;
|
||||
sd_id128_t this_id;
|
||||
bool try;
|
||||
int r;
|
||||
@ -3512,7 +3512,6 @@ static int inner_child(
|
||||
(void) fdset_close_others(fds);
|
||||
|
||||
if (arg_start_mode == START_BOOT) {
|
||||
const char *init;
|
||||
char **a;
|
||||
size_t m;
|
||||
|
||||
@ -4603,7 +4602,7 @@ static int load_settings(void) {
|
||||
_cleanup_(settings_freep) Settings *settings = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_free_ char *p = NULL;
|
||||
const char *fn, *i;
|
||||
const char *fn;
|
||||
int r;
|
||||
|
||||
if (arg_oci_bundle)
|
||||
|
@ -4533,9 +4533,8 @@ static int acquire_root_devno(
|
||||
}
|
||||
|
||||
static int find_root(char **ret, int *ret_fd) {
|
||||
const char *p;
|
||||
int r;
|
||||
_cleanup_free_ char *device = NULL;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
assert(ret_fd);
|
||||
|
@ -1599,7 +1599,6 @@ int portable_detach(
|
||||
|
||||
SET_FOREACH(item, unit_files) {
|
||||
_cleanup_free_ char *md = NULL;
|
||||
const char *suffix;
|
||||
|
||||
if (unlinkat(dirfd(d), item, 0) < 0) {
|
||||
log_debug_errno(errno, "Can't remove unit file %s/%s: %m", where, item);
|
||||
|
@ -50,8 +50,6 @@ int manager_check_resolv_conf(const Manager *m) {
|
||||
}
|
||||
|
||||
static bool file_is_our_own(const struct stat *st) {
|
||||
const char *path;
|
||||
|
||||
assert(st);
|
||||
|
||||
FOREACH_STRING(path,
|
||||
|
@ -41,7 +41,6 @@ TEST(parse_etc_hosts) {
|
||||
|
||||
int fd;
|
||||
_cleanup_fclose_ FILE *f;
|
||||
const char *s;
|
||||
|
||||
fd = mkostemp_safe(t);
|
||||
assert_se(fd >= 0);
|
||||
|
@ -1702,8 +1702,6 @@ static int start_transient_trigger(
|
||||
}
|
||||
|
||||
static bool shall_make_executable_absolute(void) {
|
||||
const char *f;
|
||||
|
||||
if (strv_isempty(arg_cmdline))
|
||||
return false;
|
||||
if (arg_transport != BUS_TRANSPORT_LOCAL)
|
||||
|
@ -21,7 +21,6 @@ static int chown_one(
|
||||
gid_t gid,
|
||||
mode_t mask) {
|
||||
|
||||
const char *n;
|
||||
int r;
|
||||
|
||||
assert(fd >= 0);
|
||||
|
@ -85,7 +85,7 @@ DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(image_hash_ops, char, string_hash_func, st
|
||||
|
||||
static char **image_settings_path(Image *image) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
const char *fn, *s;
|
||||
const char *fn;
|
||||
unsigned i = 0;
|
||||
|
||||
assert(image);
|
||||
|
@ -3041,7 +3041,6 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_
|
||||
|
||||
case META_HAS_INIT_SYSTEM: {
|
||||
bool found = false;
|
||||
const char *init;
|
||||
|
||||
FOREACH_STRING(init,
|
||||
"/usr/lib/systemd/systemd", /* systemd on /usr merged system */
|
||||
|
@ -435,7 +435,8 @@ int find_esp_and_warn(
|
||||
goto found;
|
||||
}
|
||||
|
||||
FOREACH_STRING(path, "/efi", "/boot", "/boot/efi") {
|
||||
FOREACH_STRING(_path, "/efi", "/boot", "/boot/efi") {
|
||||
path = _path;
|
||||
|
||||
r = verify_esp(path, /* searching= */ true, unprivileged_mode, ret_part, ret_pstart, ret_psize, ret_uuid, ret_devid);
|
||||
if (r >= 0)
|
||||
|
@ -197,7 +197,7 @@ finish:
|
||||
|
||||
int machine_id_commit(const char *root) {
|
||||
_cleanup_close_ int fd = -1, initial_mntns_fd = -1;
|
||||
const char *etc_machine_id, *sync_path;
|
||||
const char *etc_machine_id;
|
||||
sd_id128_t id;
|
||||
int r;
|
||||
|
||||
|
@ -126,9 +126,6 @@ bool mount_point_is_api(const char *path) {
|
||||
}
|
||||
|
||||
bool mount_point_ignore(const char *path) {
|
||||
|
||||
const char *i;
|
||||
|
||||
/* These are API file systems that might be mounted by other software, we just list them here so that
|
||||
* we know that we should ignore them. */
|
||||
FOREACH_STRING(i,
|
||||
@ -515,7 +512,6 @@ int mount_setup(bool loaded_policy, bool leave_propagation) {
|
||||
* use the same label for all their files. */
|
||||
if (loaded_policy) {
|
||||
usec_t before_relabel, after_relabel;
|
||||
const char *i;
|
||||
int n_extra;
|
||||
|
||||
before_relabel = now(CLOCK_MONOTONIC);
|
||||
|
@ -54,14 +54,15 @@ int net_get_type_string(sd_device *device, uint16_t iftype, char **ret) {
|
||||
}
|
||||
|
||||
const char *net_get_persistent_name(sd_device *device) {
|
||||
const char *name, *field;
|
||||
|
||||
assert(device);
|
||||
|
||||
/* fetch some persistent data unique (on this machine) to this device */
|
||||
FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", "ID_NET_NAME_PATH", "ID_NET_NAME_MAC")
|
||||
FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", "ID_NET_NAME_PATH", "ID_NET_NAME_MAC") {
|
||||
const char *name;
|
||||
|
||||
if (sd_device_get_property_value(device, field, &name) >= 0)
|
||||
return name;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ void pager_open(PagerFlags flags) {
|
||||
if (r < 0)
|
||||
return;
|
||||
if (r == 0) {
|
||||
const char *less_charset, *exe;
|
||||
const char *less_charset;
|
||||
|
||||
/* In the child start the pager */
|
||||
|
||||
|
@ -106,8 +106,6 @@ int read_resource_pressure(const char *path, PressureType type, ResourcePressure
|
||||
}
|
||||
|
||||
int is_pressure_supported(void) {
|
||||
const char *p;
|
||||
|
||||
/* The pressure files, both under /proc and in cgroups, will exist
|
||||
* even if the kernel has PSI support disabled; we have to read
|
||||
* the file to make sure it doesn't return -EOPNOTSUPP */
|
||||
|
@ -33,7 +33,6 @@ int switch_root(const char *new_root,
|
||||
_cleanup_free_ char *resolved_old_root_after = NULL;
|
||||
_cleanup_close_ int old_root_fd = -1;
|
||||
bool old_root_remove;
|
||||
const char *i;
|
||||
int r;
|
||||
|
||||
assert(new_root);
|
||||
@ -64,12 +63,12 @@ int switch_root(const char *new_root,
|
||||
if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) < 0)
|
||||
return log_error_errno(errno, "Failed to set \"/\" mount propagation to private: %m");
|
||||
|
||||
FOREACH_STRING(i, "/sys", "/dev", "/run", "/proc") {
|
||||
FOREACH_STRING(path, "/sys", "/dev", "/run", "/proc") {
|
||||
_cleanup_free_ char *chased = NULL;
|
||||
|
||||
r = chase_symlinks(i, new_root, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &chased, NULL);
|
||||
r = chase_symlinks(path, new_root, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &chased, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to resolve %s/%s: %m", new_root, i);
|
||||
return log_error_errno(r, "Failed to resolve %s/%s: %m", new_root, path);
|
||||
if (r > 0) {
|
||||
/* Already exists. Let's see if it is a mount point already. */
|
||||
r = path_is_mount_point(chased, NULL, 0);
|
||||
@ -81,8 +80,8 @@ int switch_root(const char *new_root,
|
||||
/* Doesn't exist yet? */
|
||||
(void) mkdir_p_label(chased, 0755);
|
||||
|
||||
if (mount(i, chased, NULL, mount_flags, NULL) < 0)
|
||||
return log_error_errno(errno, "Failed to mount %s to %s: %m", i, chased);
|
||||
if (mount(path, chased, NULL, mount_flags, NULL) < 0)
|
||||
return log_error_errno(errno, "Failed to mount %s to %s: %m", path, chased);
|
||||
}
|
||||
|
||||
/* Do not fail if base_filesystem_create() fails. Not all switch roots are like base_filesystem_create() wants
|
||||
|
@ -306,16 +306,15 @@ const char *ci_environment(void) {
|
||||
* just the general CI environment type, but also whether we're sanitizing or not, etc. The caller is
|
||||
* expected to use strstr on the returned value. */
|
||||
static const char *ans = POINTER_MAX;
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
if (ans != POINTER_MAX)
|
||||
return ans;
|
||||
|
||||
/* We allow specifying the environment with $CITYPE. Nobody uses this so far, but we are ready. */
|
||||
p = getenv("CITYPE");
|
||||
if (!isempty(p))
|
||||
return (ans = p);
|
||||
const char *citype = getenv("CITYPE");
|
||||
if (!isempty(citype))
|
||||
return (ans = citype);
|
||||
|
||||
if (getenv_bool("TRAVIS") > 0)
|
||||
return (ans = "travis");
|
||||
@ -326,12 +325,12 @@ const char *ci_environment(void) {
|
||||
if (getenv("AUTOPKGTEST_ARTIFACTS") || getenv("AUTOPKGTEST_TMP"))
|
||||
return (ans = "autopkgtest");
|
||||
|
||||
FOREACH_STRING(p, "CI", "CONTINOUS_INTEGRATION") {
|
||||
FOREACH_STRING(var, "CI", "CONTINOUS_INTEGRATION") {
|
||||
/* Those vars are booleans according to Semaphore and Travis docs:
|
||||
* https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
|
||||
* https://docs.semaphoreci.com/ci-cd-environment/environment-variables/#ci
|
||||
*/
|
||||
r = getenv_bool(p);
|
||||
r = getenv_bool(var);
|
||||
if (r > 0)
|
||||
return (ans = "unknown"); /* Some other unknown thing */
|
||||
if (r == 0)
|
||||
|
@ -318,7 +318,7 @@ static int run_editor(char **paths) {
|
||||
if (r == 0) {
|
||||
char **editor_args = NULL;
|
||||
size_t n_editor_args = 0, i = 1, argc;
|
||||
const char **args, *editor, *p;
|
||||
const char **args, *editor;
|
||||
|
||||
argc = strv_length(paths)/2 + 1;
|
||||
|
||||
@ -356,13 +356,13 @@ static int run_editor(char **paths) {
|
||||
if (n_editor_args > 0)
|
||||
execvp(args[0], (char* const*) args);
|
||||
|
||||
FOREACH_STRING(p, "editor", "nano", "vim", "vi") {
|
||||
args[0] = p;
|
||||
execvp(p, (char* const*) args);
|
||||
FOREACH_STRING(name, "editor", "nano", "vim", "vi") {
|
||||
args[0] = name;
|
||||
execvp(name, (char* const*) args);
|
||||
/* We do not fail if the editor doesn't exist because we want to try each one of them
|
||||
* before failing. */
|
||||
if (errno != ENOENT) {
|
||||
log_error_errno(errno, "Failed to execute %s: %m", editor);
|
||||
log_error_errno(errno, "Failed to execute %s: %m", name);
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,8 @@
|
||||
|
||||
int talk_initctl(char rl) {
|
||||
#if HAVE_SYSV_COMPAT
|
||||
struct init_request request;
|
||||
_cleanup_close_ int fd = -1;
|
||||
const char *p;
|
||||
const char *path;
|
||||
int r;
|
||||
|
||||
/* Try to switch to the specified SysV runlevel. Returns == 0 if the operation does not apply on this
|
||||
@ -29,19 +28,19 @@ int talk_initctl(char rl) {
|
||||
if (rl == 0)
|
||||
return 0;
|
||||
|
||||
FOREACH_STRING(p, "/run/initctl", "/dev/initctl") {
|
||||
fd = open(p, O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
|
||||
if (fd >= 0 || errno != ENOENT)
|
||||
FOREACH_STRING(_path, "/run/initctl", "/dev/initctl") {
|
||||
path = _path;
|
||||
|
||||
fd = open(path, O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
|
||||
if (fd < 0 && errno != ENOENT)
|
||||
return log_error_errno(errno, "Failed to open %s: %m", path);
|
||||
if (fd >= 0)
|
||||
break;
|
||||
}
|
||||
if (fd < 0) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
|
||||
return log_error_errno(errno, "Failed to open initctl fifo: %m");
|
||||
}
|
||||
|
||||
request = (struct init_request) {
|
||||
struct init_request request = {
|
||||
.magic = INIT_MAGIC,
|
||||
.sleeptime = 0,
|
||||
.cmd = INIT_CMD_RUNLVL,
|
||||
@ -50,7 +49,7 @@ int talk_initctl(char rl) {
|
||||
|
||||
r = loop_write(fd, &request, sizeof(request), false);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to write to %s: %m", p);
|
||||
return log_error_errno(r, "Failed to write to %s: %m", path);
|
||||
|
||||
return 1;
|
||||
#else
|
||||
|
@ -30,7 +30,6 @@ static void test_policy_closed(const char *cgroup_path, BPFProgram **installed_p
|
||||
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_CLOSED, true, cgroup_path, installed_prog);
|
||||
assert_se(r >= 0);
|
||||
|
||||
const char *s;
|
||||
FOREACH_STRING(s, "/dev/null",
|
||||
"/dev/zero",
|
||||
"/dev/full",
|
||||
|
@ -64,18 +64,14 @@ static void test_ellipsize_mem_one(const char *s, size_t old_length, size_t new_
|
||||
}
|
||||
|
||||
TEST(ellipsize_mem) {
|
||||
const char *s;
|
||||
ssize_t l, k;
|
||||
|
||||
FOREACH_STRING(s,
|
||||
"_XXXXXXXXXXX_", /* ASCII */
|
||||
"_aąęółśćńżźć_", /* two-byte utf-8 */
|
||||
"გამარჯობა", /* multi-byte utf-8 */
|
||||
"你好世界", /* wide characters */
|
||||
"你გą世óoó界") /* a mix */
|
||||
|
||||
for (l = strlen(s); l >= 0; l--)
|
||||
for (k = strlen(s) + 1; k >= 0; k--)
|
||||
for (ssize_t l = strlen(s); l >= 0; l--)
|
||||
for (ssize_t k = strlen(s) + 1; k >= 0; k--)
|
||||
test_ellipsize_mem_one(s, l, k);
|
||||
}
|
||||
|
||||
|
@ -166,8 +166,6 @@ TEST(load_env_file_6) {
|
||||
}
|
||||
|
||||
TEST(write_and_load_env_file) {
|
||||
const char *v;
|
||||
|
||||
/* Make sure that our writer, parser and the shell agree on what our env var files mean */
|
||||
|
||||
FOREACH_STRING(v,
|
||||
|
@ -190,19 +190,15 @@ static bool check_user_has_group_with_same_name(const char *name) {
|
||||
}
|
||||
|
||||
static bool is_inaccessible_available(void) {
|
||||
const char *p;
|
||||
|
||||
FOREACH_STRING(p,
|
||||
"/run/systemd/inaccessible/reg",
|
||||
"/run/systemd/inaccessible/dir",
|
||||
"/run/systemd/inaccessible/chr",
|
||||
"/run/systemd/inaccessible/blk",
|
||||
"/run/systemd/inaccessible/fifo",
|
||||
"/run/systemd/inaccessible/sock"
|
||||
) {
|
||||
"/run/systemd/inaccessible/reg",
|
||||
"/run/systemd/inaccessible/dir",
|
||||
"/run/systemd/inaccessible/chr",
|
||||
"/run/systemd/inaccessible/blk",
|
||||
"/run/systemd/inaccessible/fifo",
|
||||
"/run/systemd/inaccessible/sock")
|
||||
if (access(p, F_OK) < 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -998,7 +998,6 @@ TEST(read_full_file_offset_size) {
|
||||
}
|
||||
|
||||
static void test_read_virtual_file_one(size_t max_size) {
|
||||
const char *filename;
|
||||
int r;
|
||||
|
||||
log_info("/* %s (max_size=%zu) */", __func__, max_size);
|
||||
|
@ -11,16 +11,13 @@
|
||||
#include "util.h"
|
||||
|
||||
TEST(gpt_types_against_architectures) {
|
||||
const char *prefix;
|
||||
int r;
|
||||
|
||||
/* Dumps a table indicating for which architectures we know we have matching GPT partition
|
||||
* types. Also validates whether we can properly categorize the entries. */
|
||||
|
||||
FOREACH_STRING(prefix, "root-", "usr-")
|
||||
for (int a = 0; a < _ARCHITECTURE_MAX; a++) {
|
||||
const char *suffix;
|
||||
|
||||
for (int a = 0; a < _ARCHITECTURE_MAX; a++)
|
||||
FOREACH_STRING(suffix, "", "-verity", "-verity-sig") {
|
||||
_cleanup_free_ char *joined = NULL;
|
||||
sd_id128_t id;
|
||||
@ -48,7 +45,6 @@ TEST(gpt_types_against_architectures) {
|
||||
|
||||
assert_se(gpt_partition_type_uuid_to_arch(id) == a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -39,7 +39,6 @@ static int test_hash_password(void) {
|
||||
/* As a warm-up exercise, check if we can hash passwords. */
|
||||
|
||||
bool have_sane_hash = false;
|
||||
const char *hash;
|
||||
|
||||
FOREACH_STRING(hash,
|
||||
"ew3bU1.hoKk4o",
|
||||
@ -68,7 +67,6 @@ static void test_hash_password_full(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
_cleanup_free_ void *cd_data = NULL;
|
||||
const char *i;
|
||||
int cd_size = 0;
|
||||
|
||||
log_info("sizeof(struct crypt_data): %zu bytes", sizeof(struct crypt_data));
|
||||
|
@ -114,7 +114,6 @@ int main(int argc, char *argv[]) {
|
||||
_cleanup_(dissected_image_unrefp) DissectedImage *dissected = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *mounted = NULL;
|
||||
pthread_t threads[N_THREADS];
|
||||
const char *fs;
|
||||
sd_id128_t id;
|
||||
int r;
|
||||
|
||||
|
@ -128,7 +128,6 @@ TEST(mount_flags_to_string) {
|
||||
TEST(bind_remount_recursive) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
|
||||
_cleanup_free_ char *subdir = NULL;
|
||||
const char *p;
|
||||
|
||||
if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
|
||||
(void) log_tests_skipped("not running privileged");
|
||||
|
@ -67,7 +67,6 @@ TEST(path_is_fs_type) {
|
||||
}
|
||||
|
||||
TEST(path_is_temporary_fs) {
|
||||
const char *s;
|
||||
int r;
|
||||
|
||||
FOREACH_STRING(s, "/", "/run", "/sys", "/sys/", "/proc", "/i-dont-exist", "/var", "/var/lib") {
|
||||
@ -85,7 +84,6 @@ TEST(path_is_temporary_fs) {
|
||||
}
|
||||
|
||||
TEST(path_is_read_only_fs) {
|
||||
const char *s;
|
||||
int r;
|
||||
|
||||
FOREACH_STRING(s, "/", "/run", "/sys", "/sys/", "/proc", "/i-dont-exist", "/var", "/var/lib") {
|
||||
|
@ -924,12 +924,10 @@ TEST(foreach_string) {
|
||||
"waldo",
|
||||
NULL
|
||||
};
|
||||
const char *x;
|
||||
unsigned i = 0;
|
||||
|
||||
unsigned i = 0;
|
||||
FOREACH_STRING(x, "foo", "bar", "waldo")
|
||||
assert_se(streq_ptr(t[i++], x));
|
||||
|
||||
assert_se(i == 3);
|
||||
|
||||
FOREACH_STRING(x, "zzz")
|
||||
|
@ -144,7 +144,6 @@ TEST(utf8_escape_non_printable) {
|
||||
}
|
||||
|
||||
TEST(utf8_escape_non_printable_full) {
|
||||
const char *s;
|
||||
FOREACH_STRING(s,
|
||||
"goo goo goo", /* ASCII */
|
||||
"\001 \019\20\a", /* control characters */
|
||||
@ -210,8 +209,6 @@ TEST(utf8_console_width) {
|
||||
}
|
||||
|
||||
TEST(utf8_to_utf16) {
|
||||
const char *p;
|
||||
|
||||
FOREACH_STRING(p,
|
||||
"abc",
|
||||
"zażółcić gęślą jaźń",
|
||||
|
@ -39,7 +39,6 @@ static int populate_uid_cache(const char *root, Hashmap **ret) {
|
||||
/* The directory list is hardcoded here: /etc is the standard, and rpm-ostree uses /usr/lib. This
|
||||
* could be made configurable, but I don't see the point right now. */
|
||||
|
||||
const char *fname;
|
||||
FOREACH_STRING(fname, "/etc/passwd", "/usr/lib/passwd") {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
|
||||
@ -78,7 +77,6 @@ static int populate_gid_cache(const char *root, Hashmap **ret) {
|
||||
if (!cache)
|
||||
return -ENOMEM;
|
||||
|
||||
const char *fname;
|
||||
FOREACH_STRING(fname, "/etc/group", "/usr/lib/group") {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user