diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-03-15 08:14:53 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-03-19 00:10:29 +0100 |
commit | 03677889f0ef42cdc534bf3b31265a054b20a354 (patch) | |
tree | 53caa0977a8afc5d0ee90e038ffd566e9e22451f /src/core | |
parent | various: make parse_env_file error handling the same in various places (diff) | |
download | systemd-03677889f0ef42cdc534bf3b31265a054b20a354.tar.xz systemd-03677889f0ef42cdc534bf3b31265a054b20a354.zip |
list: declare iterator of LIST_FOREACH() in the loop
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/bpf-foreign.c | 1 | ||||
-rw-r--r-- | src/core/bpf-socket-bind.c | 2 | ||||
-rw-r--r-- | src/core/cgroup.c | 34 | ||||
-rw-r--r-- | src/core/core-varlink.c | 5 | ||||
-rw-r--r-- | src/core/dbus-cgroup.c | 70 | ||||
-rw-r--r-- | src/core/dbus-execute.c | 12 | ||||
-rw-r--r-- | src/core/dbus-path.c | 1 | ||||
-rw-r--r-- | src/core/dbus-socket.c | 1 | ||||
-rw-r--r-- | src/core/dbus-timer.c | 2 | ||||
-rw-r--r-- | src/core/dbus-unit.c | 2 | ||||
-rw-r--r-- | src/core/device.c | 8 | ||||
-rw-r--r-- | src/core/execute.c | 15 | ||||
-rw-r--r-- | src/core/load-fragment.c | 22 | ||||
-rw-r--r-- | src/core/manager.c | 1 | ||||
-rw-r--r-- | src/core/mount.c | 1 | ||||
-rw-r--r-- | src/core/namespace.c | 1 | ||||
-rw-r--r-- | src/core/path.c | 25 | ||||
-rw-r--r-- | src/core/service.c | 13 | ||||
-rw-r--r-- | src/core/socket.c | 22 | ||||
-rw-r--r-- | src/core/swap.c | 10 | ||||
-rw-r--r-- | src/core/timer.c | 5 | ||||
-rw-r--r-- | src/core/transaction.c | 39 | ||||
-rw-r--r-- | src/core/unit.c | 2 |
23 files changed, 80 insertions, 214 deletions
diff --git a/src/core/bpf-foreign.c b/src/core/bpf-foreign.c index 8538792b60..7f50f57389 100644 --- a/src/core/bpf-foreign.c +++ b/src/core/bpf-foreign.c @@ -123,7 +123,6 @@ static int bpf_foreign_prepare( int bpf_foreign_install(Unit *u) { _cleanup_free_ char *cgroup_path = NULL; - CGroupBPFForeignProgram *p; CGroupContext *cc; int r; diff --git a/src/core/bpf-socket-bind.c b/src/core/bpf-socket-bind.c index 806df84ea7..09f83dc667 100644 --- a/src/core/bpf-socket-bind.c +++ b/src/core/bpf-socket-bind.c @@ -27,7 +27,6 @@ static int update_rules_map( int map_fd, CGroupSocketBindItem *head) { - CGroupSocketBindItem *item; uint32_t i = 0; assert(map_fd >= 0); @@ -58,7 +57,6 @@ static int prepare_socket_bind_bpf( _cleanup_(socket_bind_bpf_freep) struct socket_bind_bpf *obj = NULL; size_t allow_count = 0, deny_count = 0; int allow_map_fd, deny_map_fd, r; - CGroupSocketBindItem *item; assert(ret_obj); diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 98bf5e8db7..f294451df6 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -414,15 +414,7 @@ static char *format_cgroup_memory_limit_comparison(char *buf, size_t l, Unit *u, void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { _cleanup_free_ char *disable_controllers_str = NULL, *cpuset_cpus = NULL, *cpuset_mems = NULL, *startup_cpuset_cpus = NULL, *startup_cpuset_mems = NULL; - CGroupIODeviceLimit *il; - CGroupIODeviceWeight *iw; - CGroupIODeviceLatency *l; - CGroupBlockIODeviceBandwidth *b; - CGroupBlockIODeviceWeight *w; - CGroupBPFForeignProgram *p; - CGroupDeviceAllow *a; CGroupContext *c; - CGroupSocketBindItem *bi; struct in_addr_prefix *iaai; char **path; @@ -1219,7 +1211,6 @@ static int cgroup_apply_devices(Unit *u) { _cleanup_(bpf_program_freep) BPFProgram *prog = NULL; const char *path; CGroupContext *c; - CGroupDeviceAllow *a; CGroupDevicePolicy policy; int r; @@ -1440,10 +1431,6 @@ static void cgroup_context_apply( set_io_weight(u, weight); if (has_io) { - CGroupIODeviceLatency *latency; - CGroupIODeviceLimit *limit; - CGroupIODeviceWeight *w; - LIST_FOREACH(device_weights, w, c->io_device_weights) cgroup_apply_io_device_weight(u, w->path, w->weight); @@ -1454,9 +1441,6 @@ static void cgroup_context_apply( cgroup_apply_io_device_latency(u, latency->path, latency->target_usec); } else if (has_blockio) { - CGroupBlockIODeviceWeight *w; - CGroupBlockIODeviceBandwidth *b; - LIST_FOREACH(device_weights, w, c->blockio_device_weights) { weight = cgroup_weight_blkio_to_io(w->weight); @@ -1509,9 +1493,7 @@ static void cgroup_context_apply( set_blkio_weight(u, weight); - if (has_io) { - CGroupIODeviceWeight *w; - + if (has_io) LIST_FOREACH(device_weights, w, c->io_device_weights) { weight = cgroup_weight_io_to_blkio(w->weight); @@ -1520,32 +1502,24 @@ static void cgroup_context_apply( cgroup_apply_blkio_device_weight(u, w->path, weight); } - } else if (has_blockio) { - CGroupBlockIODeviceWeight *w; - + else if (has_blockio) LIST_FOREACH(device_weights, w, c->blockio_device_weights) cgroup_apply_blkio_device_weight(u, w->path, w->weight); - } } /* The bandwidth limits are something that make sense to be applied to the host's root but not container * roots, as there we want the container manager to handle it */ if (is_host_root || !is_local_root) { - if (has_io) { - CGroupIODeviceLimit *l; - + if (has_io) LIST_FOREACH(device_limits, l, c->io_device_limits) { log_cgroup_compat(u, "Applying IO{Read|Write}Bandwidth=%" PRIu64 " %" PRIu64 " as BlockIO{Read|Write}BandwidthMax= for %s", l->limits[CGROUP_IO_RBPS_MAX], l->limits[CGROUP_IO_WBPS_MAX], l->path); cgroup_apply_blkio_device_limit(u, l->path, l->limits[CGROUP_IO_RBPS_MAX], l->limits[CGROUP_IO_WBPS_MAX]); } - } else if (has_blockio) { - CGroupBlockIODeviceBandwidth *b; - + else if (has_blockio) LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) cgroup_apply_blkio_device_limit(u, b->path, b->rbps, b->wbps); - } } } diff --git a/src/core/core-varlink.c b/src/core/core-varlink.c index a75f9fb66f..40cfd0cc7a 100644 --- a/src/core/core-varlink.c +++ b/src/core/core-varlink.c @@ -157,9 +157,7 @@ static int build_managed_oom_cgroups_json(Manager *m, JsonVariant **ret) { if (r < 0) return r; - for (size_t i = 0; i < ELEMENTSOF(supported_unit_types); i++) { - Unit *u; - + for (size_t i = 0; i < ELEMENTSOF(supported_unit_types); i++) LIST_FOREACH(units_by_type, u, m->units_by_type[supported_unit_types[i]]) { CGroupContext *c; @@ -188,7 +186,6 @@ static int build_managed_oom_cgroups_json(Manager *m, JsonVariant **ret) { return r; } } - } r = json_build(&v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("cgroups", JSON_BUILD_VARIANT(arr)))); if (r < 0) diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index f0d8759e85..d4a3b55fc1 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -112,7 +112,6 @@ static int property_get_io_device_weight( sd_bus_error *error) { CGroupContext *c = userdata; - CGroupIODeviceWeight *w; int r; assert(bus); @@ -142,7 +141,6 @@ static int property_get_io_device_limits( sd_bus_error *error) { CGroupContext *c = userdata; - CGroupIODeviceLimit *l; int r; assert(bus); @@ -178,7 +176,6 @@ static int property_get_io_device_latency( sd_bus_error *error) { CGroupContext *c = userdata; - CGroupIODeviceLatency *l; int r; assert(bus); @@ -208,7 +205,6 @@ static int property_get_blockio_device_weight( sd_bus_error *error) { CGroupContext *c = userdata; - CGroupBlockIODeviceWeight *w; int r; assert(bus); @@ -238,7 +234,6 @@ static int property_get_blockio_device_bandwidths( sd_bus_error *error) { CGroupContext *c = userdata; - CGroupBlockIODeviceBandwidth *b; int r; assert(bus); @@ -278,7 +273,6 @@ static int property_get_device_allow( sd_bus_error *error) { CGroupContext *c = userdata; - CGroupDeviceAllow *a; int r; assert(bus); @@ -364,7 +358,6 @@ static int property_get_bpf_foreign_program( void *userdata, sd_bus_error *error) { CGroupContext *c = userdata; - CGroupBPFForeignProgram *p; int r; r = sd_bus_message_open_container(reply, 'a', "(ss)"); @@ -390,7 +383,8 @@ static int property_get_socket_bind( sd_bus_message *reply, void *userdata, sd_bus_error *error) { - CGroupSocketBindItem **items = userdata, *i; + + CGroupSocketBindItem **items = userdata; int r; assert(items); @@ -720,7 +714,6 @@ static int bus_cgroup_set_transient_property( if (!UNIT_WRITE_FLAGS_NOOP(flags)) { _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; - CGroupBPFForeignProgram *fp; size_t size = 0; if (n == 0) @@ -1228,14 +1221,13 @@ int bus_cgroup_set_property( return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path '%s' specified in %s= is not normalized.", name, path); if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - CGroupIODeviceLimit *a = NULL, *b; + CGroupIODeviceLimit *a = NULL; - LIST_FOREACH(device_limits, b, c->io_device_limits) { + LIST_FOREACH(device_limits, b, c->io_device_limits) if (path_equal(path, b->path)) { a = b; break; } - } if (!a) { CGroupIOLimitType type; @@ -1269,15 +1261,13 @@ int bus_cgroup_set_property( return r; if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - CGroupIODeviceLimit *a; _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; size_t size = 0; - if (n == 0) { + if (n == 0) LIST_FOREACH(device_limits, a, c->io_device_limits) a->limits[iol_type] = cgroup_io_limit_defaults[iol_type]; - } unit_invalidate_cgroup(u, CGROUP_MASK_IO); @@ -1287,8 +1277,8 @@ int bus_cgroup_set_property( fprintf(f, "%s=\n", name); LIST_FOREACH(device_limits, a, c->io_device_limits) - if (a->limits[iol_type] != cgroup_io_limit_defaults[iol_type]) - fprintf(f, "%s=%s %" PRIu64 "\n", name, a->path, a->limits[iol_type]); + if (a->limits[iol_type] != cgroup_io_limit_defaults[iol_type]) + fprintf(f, "%s=%s %" PRIu64 "\n", name, a->path, a->limits[iol_type]); r = fflush_and_check(f); if (r < 0) @@ -1316,14 +1306,13 @@ int bus_cgroup_set_property( return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "IODeviceWeight= value out of range"); if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - CGroupIODeviceWeight *a = NULL, *b; + CGroupIODeviceWeight *a = NULL; - LIST_FOREACH(device_weights, b, c->io_device_weights) { + LIST_FOREACH(device_weights, b, c->io_device_weights) if (path_equal(b->path, path)) { a = b; break; } - } if (!a) { a = new0(CGroupIODeviceWeight, 1); @@ -1351,13 +1340,11 @@ int bus_cgroup_set_property( if (!UNIT_WRITE_FLAGS_NOOP(flags)) { _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; - CGroupIODeviceWeight *a; size_t size = 0; - if (n == 0) { + if (n == 0) while (c->io_device_weights) cgroup_context_free_io_device_weight(c, c->io_device_weights); - } unit_invalidate_cgroup(u, CGROUP_MASK_IO); @@ -1392,14 +1379,13 @@ int bus_cgroup_set_property( return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path '%s' specified in %s= is not normalized.", name, path); if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - CGroupIODeviceLatency *a = NULL, *b; + CGroupIODeviceLatency *a = NULL; - LIST_FOREACH(device_latencies, b, c->io_device_latencies) { + LIST_FOREACH(device_latencies, b, c->io_device_latencies) if (path_equal(b->path, path)) { a = b; break; } - } if (!a) { a = new0(CGroupIODeviceLatency, 1); @@ -1427,13 +1413,11 @@ int bus_cgroup_set_property( if (!UNIT_WRITE_FLAGS_NOOP(flags)) { _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; - CGroupIODeviceLatency *a; size_t size = 0; - if (n == 0) { + if (n == 0) while (c->io_device_latencies) cgroup_context_free_io_device_latency(c, c->io_device_latencies); - } unit_invalidate_cgroup(u, CGROUP_MASK_IO); @@ -1473,14 +1457,13 @@ int bus_cgroup_set_property( return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path '%s' specified in %s= is not normalized.", name, path); if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - CGroupBlockIODeviceBandwidth *a = NULL, *b; + CGroupBlockIODeviceBandwidth *a = NULL; - LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) { + LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) if (path_equal(path, b->path)) { a = b; break; } - } if (!a) { a = new0(CGroupBlockIODeviceBandwidth, 1); @@ -1514,19 +1497,17 @@ int bus_cgroup_set_property( return r; if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - CGroupBlockIODeviceBandwidth *a; _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; size_t size = 0; - if (n == 0) { + if (n == 0) LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths) { if (read) a->rbps = CGROUP_LIMIT_MAX; else a->wbps = CGROUP_LIMIT_MAX; } - } unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO); @@ -1573,14 +1554,13 @@ int bus_cgroup_set_property( return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "BlockIODeviceWeight= out of range"); if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - CGroupBlockIODeviceWeight *a = NULL, *b; + CGroupBlockIODeviceWeight *a = NULL; - LIST_FOREACH(device_weights, b, c->blockio_device_weights) { + LIST_FOREACH(device_weights, b, c->blockio_device_weights) if (path_equal(b->path, path)) { a = b; break; } - } if (!a) { a = new0(CGroupBlockIODeviceWeight, 1); @@ -1608,13 +1588,11 @@ int bus_cgroup_set_property( if (!UNIT_WRITE_FLAGS_NOOP(flags)) { _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; - CGroupBlockIODeviceWeight *a; size_t size = 0; - if (n == 0) { + if (n == 0) while (c->blockio_device_weights) cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights); - } unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO); @@ -1674,14 +1652,13 @@ int bus_cgroup_set_property( return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "DeviceAllow= requires combination of rwm flags"); if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - CGroupDeviceAllow *a = NULL, *b; + CGroupDeviceAllow *a = NULL; - LIST_FOREACH(device_allow, b, c->device_allow) { + LIST_FOREACH(device_allow, b, c->device_allow) if (path_equal(b->path, path)) { a = b; break; } - } if (!a) { a = new0(CGroupDeviceAllow, 1); @@ -1714,13 +1691,11 @@ int bus_cgroup_set_property( if (!UNIT_WRITE_FLAGS_NOOP(flags)) { _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; - CGroupDeviceAllow *a; size_t size = 0; - if (n == 0) { + if (n == 0) while (c->device_allow) cgroup_context_free_device_allow(c, c->device_allow); - } unit_invalidate_cgroup(u, CGROUP_MASK_DEVICES); @@ -1995,7 +1970,6 @@ int bus_cgroup_set_property( if (!UNIT_WRITE_FLAGS_NOOP(flags)) { _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; - CGroupSocketBindItem *item; size_t size = 0; if (n == 0) diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 8a8d9c9b2e..3967abbafb 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -960,7 +960,6 @@ static int property_get_root_image_options( sd_bus_error *error) { ExecContext *c = userdata; - MountOptions *m; int r; assert(bus); @@ -1005,8 +1004,6 @@ static int property_get_mount_images( return r; for (size_t i = 0; i < c->n_mount_images; i++) { - MountOptions *m; - r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "ssba(ss)"); if (r < 0) return r; @@ -1060,8 +1057,6 @@ static int property_get_extension_images( return r; for (size_t i = 0; i < c->n_extension_images; i++) { - MountOptions *m; - r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "sba(ss)"); if (r < 0) return r; @@ -1449,7 +1444,7 @@ int bus_property_get_exec_command_list( void *userdata, sd_bus_error *ret_error) { - ExecCommand *c = *(ExecCommand**) userdata; + ExecCommand *exec_command = *(ExecCommand**) userdata; int r; assert(bus); @@ -1459,7 +1454,7 @@ int bus_property_get_exec_command_list( if (r < 0) return r; - LIST_FOREACH(command, c, c) { + LIST_FOREACH(command, c, exec_command) { r = append_exec_command(reply, c); if (r < 0) return r; @@ -1477,7 +1472,7 @@ int bus_property_get_exec_ex_command_list( void *userdata, sd_bus_error *ret_error) { - ExecCommand *c, *exec_command = *(ExecCommand**) userdata; + ExecCommand *exec_command = *(ExecCommand**) userdata; int r; assert(bus); @@ -1587,7 +1582,6 @@ int bus_set_transient_exec_command( if (!UNIT_WRITE_FLAGS_NOOP(flags)) { _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; - ExecCommand *c; size_t size = 0; if (n == 0) diff --git a/src/core/dbus-path.c b/src/core/dbus-path.c index f143ad5d4a..09b353ba3f 100644 --- a/src/core/dbus-path.c +++ b/src/core/dbus-path.c @@ -22,7 +22,6 @@ static int property_get_paths( sd_bus_error *error) { Path *p = userdata; - PathSpec *k; int r; assert(bus); diff --git a/src/core/dbus-socket.c b/src/core/dbus-socket.c index a3b1e0442f..3dc744a017 100644 --- a/src/core/dbus-socket.c +++ b/src/core/dbus-socket.c @@ -32,7 +32,6 @@ static int property_get_listen( sd_bus_error *error) { Socket *s = SOCKET(userdata); - SocketPort *p; int r; assert(bus); diff --git a/src/core/dbus-timer.c b/src/core/dbus-timer.c index 9d823279dd..8110fb1fb7 100644 --- a/src/core/dbus-timer.c +++ b/src/core/dbus-timer.c @@ -20,7 +20,6 @@ static int property_get_monotonic_timers( sd_bus_error *error) { Timer *t = userdata; - TimerValue *v; int r; assert(bus); @@ -69,7 +68,6 @@ static int property_get_calendar_timers( sd_bus_error *error) { Timer *t = userdata; - TimerValue *v; int r; assert(bus); diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 6542d50330..7265bb1908 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -273,7 +273,7 @@ static int property_get_conditions( sd_bus_error *error) { const char *(*to_string)(ConditionType type) = NULL; - Condition **list = userdata, *c; + Condition **list = userdata; int r; assert(bus); diff --git a/src/core/device.c b/src/core/device.c index 43f49573b9..e1cef86a1b 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -710,7 +710,7 @@ static void device_update_found_one(Device *d, DeviceFound found, DeviceFound ma } static void device_update_found_by_sysfs(Manager *m, const char *sysfs, DeviceFound found, DeviceFound mask) { - Device *d, *l, *n; + Device *l; assert(m); assert(sysfs); @@ -765,7 +765,7 @@ static bool device_is_ready(sd_device *dev) { static Unit *device_following(Unit *u) { Device *d = DEVICE(u); - Device *other, *first = NULL; + Device *first = NULL; assert(d); @@ -788,7 +788,7 @@ static Unit *device_following(Unit *u) { } static int device_following_set(Unit *u, Set **_set) { - Device *d = DEVICE(u), *other; + Device *d = DEVICE(u); _cleanup_set_free_ Set *set = NULL; int r; @@ -898,7 +898,7 @@ fail: } static void device_propagate_reload_by_sysfs(Manager *m, const char *sysfs) { - Device *d, *l, *n; + Device *l; int r; assert(m); diff --git a/src/core/execute.c b/src/core/execute.c index b6021397ce..5127da5705 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -5423,12 +5423,9 @@ void exec_command_reset_status_array(ExecCommand *c, size_t n) { } void exec_command_reset_status_list_array(ExecCommand **c, size_t n) { - for (size_t i = 0; i < n; i++) { - ExecCommand *z; - + for (size_t i = 0; i < n; i++) LIST_FOREACH(command, z, c[i]) exec_status_reset(&z->exec_status); - } } typedef struct InvalidEnvInfo { @@ -5713,8 +5710,6 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) { fprintf(f, "%sRootImage: %s\n", prefix, c->root_image); if (c->root_image_options) { - MountOptions *o; - fprintf(f, "%sRootImageOptions:", prefix); LIST_FOREACH(mount_options, o, c->root_image_options) if (!isempty(o->options)) @@ -6113,8 +6108,6 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) { } for (size_t i = 0; i < c->n_mount_images; i++) { - MountOptions *o; - fprintf(f, "%sMountImages: %s%s:%s", prefix, c->mount_images[i].ignore_enoent ? "-": "", c->mount_images[i].source, @@ -6127,8 +6120,6 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) { } for (size_t i = 0; i < c->n_extension_images; i++) { - MountOptions *o; - fprintf(f, "%sExtensionImages: %s%s", prefix, c->extension_images[i].ignore_enoent ? "-": "", c->extension_images[i].source); @@ -6395,8 +6386,8 @@ void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix) { prefix = strempty(prefix); - LIST_FOREACH(command, c, c) - exec_command_dump(c, f, prefix); + LIST_FOREACH(command, i, c) + exec_command_dump(i, f, prefix); } void exec_command_append_list(ExecCommand **l, ExecCommand *e) { diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 92a52819e2..1ee18f8b5c 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -4328,7 +4328,7 @@ int config_parse_io_limit( void *userdata) { _cleanup_free_ char *path = NULL, *resolved = NULL; - CGroupIODeviceLimit *l = NULL, *t; + CGroupIODeviceLimit *l = NULL; CGroupContext *c = data; CGroupIOLimitType type; const char *p = rvalue; @@ -4343,8 +4343,8 @@ int config_parse_io_limit( assert(type >= 0); if (isempty(rvalue)) { - LIST_FOREACH(device_limits, l, c->io_device_limits) - l->limits[type] = cgroup_io_limit_defaults[type]; + LIST_FOREACH(device_limits, t, c->io_device_limits) + t->limits[type] = cgroup_io_limit_defaults[type]; return 0; } @@ -4378,12 +4378,11 @@ int config_parse_io_limit( } } - LIST_FOREACH(device_limits, t, c->io_device_limits) { + LIST_FOREACH(device_limits, t, c->io_device_limits) if (path_equal(resolved, t->path)) { l = t; break; } - } if (!l) { CGroupIOLimitType ttype; @@ -4486,7 +4485,7 @@ int config_parse_blockio_bandwidth( void *userdata) { _cleanup_free_ char *path = NULL, *resolved = NULL; - CGroupBlockIODeviceBandwidth *b = NULL, *t; + CGroupBlockIODeviceBandwidth *b = NULL; CGroupContext *c = data; const char *p = rvalue; uint64_t bytes; @@ -4500,9 +4499,9 @@ int config_parse_blockio_bandwidth( read = streq("BlockIOReadBandwidth", lvalue); if (isempty(rvalue)) { - LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) { - b->rbps = CGROUP_LIMIT_MAX; - b->wbps = CGROUP_LIMIT_MAX; + LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths) { + t->rbps = CGROUP_LIMIT_MAX; + t->wbps = CGROUP_LIMIT_MAX; } return 0; } @@ -4533,14 +4532,13 @@ int config_parse_blockio_bandwidth( return 0; } - LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths) { + LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths) if (path_equal(resolved, t->path)) { b = t; break; } - } - if (!t) { + if (!b) { b = new0(CGroupBlockIODeviceBandwidth, 1); if (!b) return log_oom(); diff --git a/src/core/manager.c b/src/core/manager.c index 4c59506ccb..be3673cf63 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -1222,7 +1222,6 @@ static void unit_gc_sweep(Unit *u, unsigned gc_marker) { is_bad = false; } - const UnitRef *ref; LIST_FOREACH(refs_by_target, ref, u->refs_by_target) { unit_gc_sweep(ref->source, gc_marker); diff --git a/src/core/mount.c b/src/core/mount.c index c650b5abe2..329abfdaa8 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -1957,7 +1957,6 @@ static int drain_libmount(Manager *m) { static int mount_process_proc_self_mountinfo(Manager *m) { _cleanup_set_free_free_ Set *around = NULL, *gone = NULL; const char *what; - Unit *u; int r; assert(m); diff --git a/src/core/namespace.c b/src/core/namespace.c index e6293882fe..0dbb03724a 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -2562,7 +2562,6 @@ MountImage* mount_image_free_many(MountImage *m, size_t *n) { int mount_image_add(MountImage **m, size_t *n, const MountImage *item) { _cleanup_free_ char *s = NULL, *d = NULL; _cleanup_(mount_options_free_allp) MountOptions *options = NULL; - MountOptions *i; MountImage *c; assert(m); diff --git a/src/core/path.c b/src/core/path.c index 0b736f00bf..d9b136f10c 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -292,7 +292,6 @@ static void path_done(Unit *u) { } static int path_add_mount_dependencies(Path *p) { - PathSpec *s; int r; assert(p); @@ -401,7 +400,6 @@ static int path_load(Unit *u) { static void path_dump(Unit *u, FILE *f, const char *prefix) { Path *p = PATH(u); Unit *trigger; - PathSpec *s; assert(p); assert(f); @@ -429,8 +427,6 @@ static void path_dump(Unit *u, FILE *f, const char *prefix) { } static void path_unwatch(Path *p) { - PathSpec *s; - assert(p); LIST_FOREACH(spec, s, p->specs) @@ -439,7 +435,6 @@ static void path_unwatch(Path *p) { static int path_watch(Path *p) { int r; - PathSpec *s; assert(p); @@ -539,8 +534,6 @@ fail: } static bool path_check_good(Path *p, bool initial, bool from_trigger_notify) { - PathSpec *s; - assert(p); LIST_FOREACH(spec, s, p->specs) @@ -591,8 +584,6 @@ fail: } static void path_mkdir(Path *p) { - PathSpec *s; - assert(p); if (!p->make_directory) @@ -637,7 +628,6 @@ static int path_stop(Unit *u) { static int path_serialize(Unit *u, FILE *f, FDSet *fds) { Path *p = PATH(u); - PathSpec *s; assert(u); assert(f); @@ -700,7 +690,6 @@ static int path_deserialize_item(Unit *u, const char *key, const char *value, FD _cleanup_free_ char *unescaped = NULL; ssize_t l; PathType type; - PathSpec *s; type = path_type_from_string(type_str); if (type < 0) { @@ -742,7 +731,7 @@ _pure_ static const char *path_sub_state_to_string(Unit *u) { } static int path_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) { - PathSpec *s = userdata; + PathSpec *s = userdata, *found = NULL; Path *p; int changed; @@ -755,18 +744,18 @@ static int path_dispatch_io(sd_event_source *source, int fd, uint32_t revents, v if (!IN_SET(p->state, PATH_WAITING, PATH_RUNNING)) return 0; - /* log_debug("inotify wakeup on %s.", UNIT(p)->id); */ - - LIST_FOREACH(spec, s, p->specs) - if (path_spec_owns_inotify_fd(s, fd)) + LIST_FOREACH(spec, i, p->specs) + if (path_spec_owns_inotify_fd(i, fd)) { + found = i; break; + } - if (!s) { + if (!found) { log_error("Got event on unknown fd."); goto fail; } - changed = path_spec_fd_event(s, revents); + changed = path_spec_fd_event(found, revents); if (changed < 0) goto fail; diff --git a/src/core/service.c b/src/core/service.c index 92485875f7..65aed4c06b 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -434,8 +434,8 @@ static int service_add_fd_store(Service *s, int fd, const char *name, bool do_po * Use this errno rather than E[NM]FILE to distinguish from * the case where systemd itself hits the file limit. */ - LIST_FOREACH(fd_store, fs, s->fd_store) { - r = same_fd(fs->fd, fd); + LIST_FOREACH(fd_store, i, s->fd_store) { + r = same_fd(i->fd, fd); if (r < 0) return r; if (r > 0) { @@ -504,8 +504,6 @@ static int service_add_fd_store_set(Service *s, FDSet *fds, const char *name, bo } static void service_remove_fd_store(Service *s, const char *name) { - ServiceFDStore *fs, *n; - assert(s); assert(name); @@ -567,9 +565,7 @@ static int service_verify(Service *s) { assert(s); assert(UNIT(s)->load_state == UNIT_LOADED); - for (ServiceExecCommand c = 0; c < _SERVICE_EXEC_COMMAND_MAX; c++) { - ExecCommand *command; - + for (ServiceExecCommand c = 0; c < _SERVICE_EXEC_COMMAND_MAX; c++) LIST_FOREACH(command, command, s->exec_command[c]) { if (!path_is_absolute(command->path) && !filename_is_valid(command->path)) return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), @@ -581,7 +577,6 @@ static int service_verify(Service *s) { "Service has an empty argv in %s=. Refusing.", service_exec_command_to_string(c)); } - } if (!s->exec_command[SERVICE_EXEC_START] && !s->exec_command[SERVICE_EXEC_STOP] && UNIT(s)->success_action == EMERGENCY_ACTION_NONE) @@ -1334,7 +1329,6 @@ static int service_collect_fds( } if (s->n_fd_store > 0) { - ServiceFDStore *fs; size_t n_fds; char **nl; int *t; @@ -2712,7 +2706,6 @@ static int service_serialize_exec_command(Unit *u, FILE *f, ExecCommand *command static int service_serialize(Unit *u, FILE *f, FDSet *fds) { Service *s = SERVICE(u); - ServiceFDStore *fs; int r; assert(u); diff --git a/src/core/socket.c b/src/core/socket.c index 8a5c7fdd0a..8eb7298b25 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -208,8 +208,6 @@ static int socket_arm_timer(Socket *s, usec_t usec) { } static bool have_non_accept_socket(Socket *s) { - SocketPort *p; - assert(s); if (!s->accept) @@ -228,7 +226,6 @@ static bool have_non_accept_socket(Socket *s) { } static int socket_add_mount_dependencies(Socket *s) { - SocketPort *p; int r; assert(s); @@ -368,7 +365,6 @@ static int socket_add_extras(Socket *s) { static const char *socket_find_symlink_target(Socket *s) { const char *found = NULL; - SocketPort *p; LIST_FOREACH(port, p, s->ports) { const char *f = NULL; @@ -565,7 +561,6 @@ _const_ static const char* listen_lookup(int family, int type) { static void socket_dump(Unit *u, FILE *f, const char *prefix) { Socket *s = SOCKET(u); - SocketPort *p; const char *prefix2, *str; assert(s); @@ -923,7 +918,6 @@ static int instance_from_socket(int fd, unsigned nr, char **instance) { } static void socket_close_fds(Socket *s) { - SocketPort *p; char **i; assert(s); @@ -1624,7 +1618,6 @@ static int socket_open_fds(Socket *orig_s) { _cleanup_(socket_close_fdsp) Socket *s = orig_s; _cleanup_(mac_selinux_freep) char *label = NULL; bool know_label = false; - SocketPort *p; int r; assert(s); @@ -1734,7 +1727,6 @@ static int socket_open_fds(Socket *orig_s) { } static void socket_unwatch_fds(Socket *s) { - SocketPort *p; int r; assert(s); @@ -1753,7 +1745,6 @@ static void socket_unwatch_fds(Socket *s) { } static int socket_watch_fds(Socket *s) { - SocketPort *p; int r; assert(s); @@ -1791,7 +1782,6 @@ enum { static int socket_check_open(Socket *s) { bool have_open = false, have_closed = false; - SocketPort *p; assert(s); @@ -1995,7 +1985,6 @@ static int socket_chown(Socket *s, pid_t *_pid) { if (r == 0) { uid_t uid = UID_INVALID; gid_t gid = GID_INVALID; - SocketPort *p; /* Child */ @@ -2294,7 +2283,7 @@ fail: } static void flush_ports(Socket *s) { - SocketPort *p; + assert(s); /* Flush all incoming traffic, regardless if actual bytes or new connections, so that this socket isn't busy * anymore */ @@ -2563,7 +2552,6 @@ static int socket_stop(Unit *u) { static int socket_serialize(Unit *u, FILE *f, FDSet *fds) { Socket *s = SOCKET(u); - SocketPort *p; int r; assert(u); @@ -2674,7 +2662,6 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, } } else if (streq(key, "fifo")) { int fd, skip = 0; - SocketPort *p; if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd)) log_unit_debug(u, "Failed to parse fifo value: %s", value); @@ -2695,7 +2682,6 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, } else if (streq(key, "special")) { int fd, skip = 0; - SocketPort *p; if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd)) log_unit_debug(u, "Failed to parse special value: %s", value); @@ -2716,7 +2702,6 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, } else if (streq(key, "mqueue")) { int fd, skip = 0; - SocketPort *p; if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd)) log_unit_debug(u, "Failed to parse mqueue value: %s", value); @@ -2737,7 +2722,6 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, } else if (streq(key, "socket")) { int fd, type, skip = 0; - SocketPort *p; if (sscanf(value, "%i %i %n", &fd, &type, &skip) < 2 || fd < 0 || type < 0 || !fdset_contains(fds, fd)) log_unit_debug(u, "Failed to parse socket value: %s", value); @@ -2758,7 +2742,6 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, } else if (streq(key, "netlink")) { int fd, skip = 0; - SocketPort *p; if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd)) log_unit_debug(u, "Failed to parse socket value: %s", value); @@ -2778,7 +2761,6 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, } else if (streq(key, "ffs")) { int fd, skip = 0; - SocketPort *p; if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd)) log_unit_debug(u, "Failed to parse ffs value: %s", value); @@ -2805,7 +2787,6 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, static void socket_distribute_fds(Unit *u, FDSet *fds) { Socket *s = SOCKET(u); - SocketPort *p; assert(u); @@ -3227,7 +3208,6 @@ static int socket_dispatch_timer(sd_event_source *source, usec_t usec, void *use int socket_collect_fds(Socket *s, int **fds) { size_t k = 0, n = 0; - SocketPort *p; int *rfds; assert(s); diff --git a/src/core/swap.c b/src/core/swap.c index 9c0d4fb227..0de73970ad 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -537,7 +537,6 @@ static void swap_process_new(Manager *m, const char *device, int prio, bool set_ static void swap_set_state(Swap *s, SwapState state) { SwapState old_state; - Swap *other; assert(s); @@ -745,8 +744,6 @@ static void swap_enter_dead_or_active(Swap *s, SwapResult f) { assert(s); if (s->from_proc_swaps) { - Swap *other; - swap_enter_active(s, f); LIST_FOREACH_OTHERS(same_devnode, other, s) @@ -902,7 +899,7 @@ static void swap_cycle_clear(Swap *s) { } static int swap_start(Unit *u) { - Swap *s = SWAP(u), *other; + Swap *s = SWAP(u); int r; assert(s); @@ -1207,7 +1204,6 @@ static int swap_load_proc_swaps(Manager *m, bool set_flags) { } static int swap_process_proc_swaps(Manager *m) { - Unit *u; int r; assert(m); @@ -1300,7 +1296,7 @@ static int swap_dispatch_io(sd_event_source *source, int fd, uint32_t revents, v static Unit *swap_following(Unit *u) { Swap *s = SWAP(u); - Swap *other, *first = NULL; + Swap *first = NULL; assert(s); @@ -1336,7 +1332,7 @@ static Unit *swap_following(Unit *u) { } static int swap_following_set(Unit *u, Set **_set) { - Swap *s = SWAP(u), *other; + Swap *s = SWAP(u); _cleanup_set_free_ Set *set = NULL; int r; diff --git a/src/core/timer.c b/src/core/timer.c index a13b864741..69a4ea652a 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -83,7 +83,6 @@ static int timer_verify(Timer *t) { static int timer_add_default_dependencies(Timer *t) { int r; - TimerValue *v; assert(t); @@ -236,7 +235,6 @@ static int timer_load(Unit *u) { static void timer_dump(Unit *u, FILE *f, const char *prefix) { Timer *t = TIMER(u); Unit *trigger; - TimerValue *v; trigger = UNIT_TRIGGER(u); @@ -375,7 +373,6 @@ static void timer_enter_waiting(Timer *t, bool time_change) { bool found_monotonic = false, found_realtime = false; bool leave_around = false; triple_timestamp ts; - TimerValue *v; Unit *trigger; int r; @@ -617,7 +614,6 @@ fail: static int timer_start(Unit *u) { Timer *t = TIMER(u); - TimerValue *v; int r; assert(t); @@ -756,7 +752,6 @@ static int timer_dispatch(sd_event_source *s, uint64_t usec, void *userdata) { static void timer_trigger_notify(Unit *u, Unit *other) { Timer *t = TIMER(u); - TimerValue *v; assert(u); assert(other); diff --git a/src/core/transaction.c b/src/core/transaction.c index ebe5f1910d..897d4386f6 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -46,7 +46,7 @@ void transaction_abort(Transaction *tr) { } static void transaction_find_jobs_that_matter_to_anchor(Job *j, unsigned generation) { - JobDependency *l; + assert(j); /* A recursive sweep through the graph that marks all units * that matter to the anchor job, i.e. are directly or @@ -71,7 +71,7 @@ static void transaction_find_jobs_that_matter_to_anchor(Job *j, unsigned generat } static void transaction_merge_and_delete_job(Transaction *tr, Job *j, Job *other, JobType t) { - JobDependency *l, *last; + JobDependency *last; assert(j); assert(other); @@ -124,8 +124,6 @@ static void transaction_merge_and_delete_job(Transaction *tr, Job *j, Job *other } _pure_ static bool job_is_conflicted_by(Job *j) { - JobDependency *l; - assert(j); /* Returns true if this job is pulled in by a least one @@ -138,10 +136,8 @@ _pure_ static bool job_is_conflicted_by(Job *j) { return false; } -static int delete_one_unmergeable_job(Transaction *tr, Job *j) { - Job *k; - - assert(j); +static int delete_one_unmergeable_job(Transaction *tr, Job *job) { + assert(job); /* Tries to delete one item in the linked list * j->transaction_next->transaction_next->... that conflicts @@ -150,7 +146,7 @@ static int delete_one_unmergeable_job(Transaction *tr, Job *j) { /* We rely here on the fact that if a merged with b does not * merge with c, either a or b merge with c neither */ - LIST_FOREACH(transaction, j, j) + LIST_FOREACH(transaction, j, job) LIST_FOREACH(transaction, k, j->transaction_next) { Job *d; @@ -226,7 +222,6 @@ static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) { * task conflict. If so, try to drop one of them. */ HASHMAP_FOREACH(j, tr->jobs) { JobType t; - Job *k; t = j->type; LIST_FOREACH(transaction, k, j->transaction_next) { @@ -257,12 +252,12 @@ static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) { /* Second step, merge the jobs. */ HASHMAP_FOREACH(j, tr->jobs) { JobType t = j->type; - Job *k; /* Merge all transaction jobs for j->unit */ LIST_FOREACH(transaction, k, j->transaction_next) assert_se(job_type_merge_and_collapse(&t, k->type, j->unit) == 0); + Job *k; while ((k = j->transaction_next)) { if (tr->anchor_job == k) { transaction_merge_and_delete_job(tr, k, j, t); @@ -293,7 +288,6 @@ static void transaction_drop_redundant(Transaction *tr) { HASHMAP_FOREACH(j, tr->jobs) { bool keep = false; - Job *k; LIST_FOREACH(transaction, k, j) if (tr->anchor_job == k || @@ -314,14 +308,15 @@ static void transaction_drop_redundant(Transaction *tr) { } while (again); } -_pure_ static bool unit_matters_to_anchor(Unit *u, Job *j) { +_pure_ static bool unit_matters_to_anchor(Unit *u, Job *job) { assert(u); - assert(!j->transaction_prev); + assert(job); + assert(!job->transaction_prev); /* Checks whether at least one of the jobs for this unit * matters to the anchor. */ - LIST_FOREACH(transaction, j, j) + LIST_FOREACH(transaction, j, job) if (j->matters_to_anchor) return true; @@ -558,7 +553,7 @@ static int transaction_is_destructive(Transaction *tr, JobMode mode, sd_bus_erro } static void transaction_minimize_impact(Transaction *tr) { - Job *j; + Job *head; assert(tr); @@ -566,8 +561,8 @@ static void transaction_minimize_impact(Transaction *tr) { * or that stop a running service. */ rescan: - HASHMAP_FOREACH(j, tr->jobs) { - LIST_FOREACH(transaction, j, j) { + HASHMAP_FOREACH(head, tr->jobs) { + LIST_FOREACH(transaction, j, head) { bool stops_running_service, changes_existing_job; /* If it matters, we shouldn't drop it */ @@ -804,13 +799,13 @@ static Job* transaction_add_one_job(Transaction *tr, JobType type, Unit *unit, b f = hashmap_get(tr->jobs, unit); - LIST_FOREACH(transaction, j, f) { - assert(j->unit == unit); + LIST_FOREACH(transaction, i, f) { + assert(i->unit == unit); - if (j->type == type) { + if (i->type == type) { if (is_new) *is_new = false; - return j; + return i; } } diff --git a/src/core/unit.c b/src/core/unit.c index bd11049c77..d7bb680e00 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -5869,7 +5869,7 @@ int unit_thaw_vtable_common(Unit *u) { } Condition *unit_find_failed_condition(Unit *u) { - Condition *c, *failed_trigger = NULL; + Condition *failed_trigger = NULL; bool has_succeeded_trigger = false; if (u->condition_result) |