strv: declare iterator of FOREACH_STRING() in the loop
Same idea as 03677889f0.
No functional change intended. The type of the iterator is generally changed to
be 'const char*' instead of 'char*'. Despite the type commonly used, modifying
the string was not allowed.
I adjusted the naming of some short variables for clarity and reduced the scope
of some variable declarations in code that was being touched anyway.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+5
-6
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user