diff --git a/backport-core-use-ASSERT_PTR-CAST-u-everywhere.patch b/backport-core-use-ASSERT_PTR-CAST-u-everywhere.patch new file mode 100644 index 0000000000000000000000000000000000000000..790c88586418e4060a572d20fdba3d3304344d64 --- /dev/null +++ b/backport-core-use-ASSERT_PTR-CAST-u-everywhere.patch @@ -0,0 +1,2805 @@ +From c5180aaf9a00fbb4e56815fafcd33d6b53b01800 Mon Sep 17 00:00:00 2001 +From: rpm-build +Date: Fri, 24 May 2024 15:43:34 +0800 +Subject: [PATCH] core: use ASSERT_PTR(CAST(u)) everywhere + +--- + src/core/automount.c | 41 +++++-------- + src/core/device.c | 68 ++++++++++------------ + src/core/mount.c | 96 ++++++++++++------------------- + src/core/path.c | 63 +++++++++----------- + src/core/scope.c | 61 ++++++++------------ + src/core/service.c | 115 ++++++++++++++++--------------------- + src/core/slice.c | 57 +++++++++--------- + src/core/socket.c | 89 +++++++++++++++------------- + src/core/swap.c | 134 ++++++++++++++++++++++--------------------- + src/core/target.c | 46 +++++++-------- + src/core/timer.c | 89 ++++++++++++++-------------- + 11 files changed, 393 insertions(+), 466 deletions(-) + +diff --git a/src/core/automount.c b/src/core/automount.c +index 14bf7e6..7e91004 100644 +--- a/src/core/automount.c ++++ b/src/core/automount.c +@@ -51,10 +51,8 @@ static void automount_stop_expire(Automount *a); + static int automount_send_ready(Automount *a, Set *tokens, int status); + + static void automount_init(Unit *u) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + +- assert(a); +- assert(u); + assert(u->load_state == UNIT_STUB); + + a->pipe_fd = -EBADF; +@@ -88,9 +86,8 @@ static void unmount_autofs(Automount *a) { + } + + static void automount_done(Unit *u) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + +- assert(a); + + unmount_autofs(a); + +@@ -227,10 +224,9 @@ static int automount_add_extras(Automount *a) { + } + + static int automount_load(Unit *u) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + int r; + +- assert(u); + assert(u->load_state == UNIT_STUB); + + /* Load a .automount file */ +@@ -271,10 +267,9 @@ static void automount_set_state(Automount *a, AutomountState state) { + } + + static int automount_coldplug(Unit *u) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + int r; + +- assert(a); + assert(a->state == AUTOMOUNT_DEAD); + + if (a->deserialized_state == a->state) +@@ -310,9 +305,8 @@ static int automount_coldplug(Unit *u) { + } + + static void automount_dump(Unit *u, FILE *f, const char *prefix) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + +- assert(a); + + fprintf(f, + "%sAutomount State: %s\n" +@@ -498,10 +492,9 @@ static int automount_send_ready(Automount *a, Set *tokens, int status) { + } + + static void automount_trigger_notify(Unit *u, Unit *other) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + int r; + +- assert(a); + assert(other); + + /* Filter out invocations with bogus state */ +@@ -698,10 +691,9 @@ static int asynchronous_expire(int dev_autofs_fd, int ioctl_fd) { + + static int automount_dispatch_expire(sd_event_source *source, usec_t usec, void *userdata) { + _cleanup_close_ int ioctl_fd = -EBADF; +- Automount *a = AUTOMOUNT(userdata); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(userdata)); + int r; + +- assert(a); + assert(source == a->expire_event_source); + + ioctl_fd = open_ioctl_fd(UNIT(a)->manager->dev_autofs_fd, a->where, a->dev_id); +@@ -815,10 +807,9 @@ fail: + } + + static int automount_start(Unit *u) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + int r; + +- assert(a); + assert(IN_SET(a->state, AUTOMOUNT_DEAD, AUTOMOUNT_FAILED)); + + if (path_is_mount_point(a->where, NULL, 0) > 0) +@@ -848,11 +839,10 @@ static int automount_stop(Unit *u) { + } + + static int automount_serialize(Unit *u, FILE *f, FDSet *fds) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + void *p; + int r; + +- assert(a); + assert(f); + assert(fds); + +@@ -873,10 +863,9 @@ static int automount_serialize(Unit *u, FILE *f, FDSet *fds) { + } + + static int automount_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + int r; + +- assert(a); + assert(fds); + + if (streq(key, "state")) { +@@ -958,13 +947,12 @@ static bool automount_may_gc(Unit *u) { + } + + static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, void *userdata) { ++ Automount *a = ASSERT_PTR(AUTOMOUNT(userdata)); + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + union autofs_v5_packet_union packet; +- Automount *a = AUTOMOUNT(userdata); + Unit *trigger; + int r; + +- assert(a); + assert(fd == a->pipe_fd); + + if (events & (EPOLLHUP|EPOLLERR)) { +@@ -1048,9 +1036,8 @@ static void automount_shutdown(Manager *m) { + } + + static void automount_reset_failed(Unit *u) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + +- assert(a); + + if (a->state == AUTOMOUNT_FAILED) + automount_set_state(a, AUTOMOUNT_DEAD); +@@ -1068,11 +1055,9 @@ static bool automount_supported(void) { + } + + static int automount_can_start(Unit *u) { +- Automount *a = AUTOMOUNT(u); ++ Automount *a = ASSERT_PTR(AUTOMOUNT(u)); + int r; + +- assert(a); +- + r = unit_test_start_limit(u); + if (r < 0) { + automount_enter_dead(a, AUTOMOUNT_FAILURE_START_LIMIT_HIT); +diff --git a/src/core/device.c b/src/core/device.c +index d07adb2..e3651c3 100644 +--- a/src/core/device.c ++++ b/src/core/device.c +@@ -119,10 +119,9 @@ static int device_set_sysfs(Device *d, const char *sysfs) { + } + + static void device_init(Unit *u) { +- Device *d = DEVICE(u); ++ Device *d = ASSERT_PTR(DEVICE(u)); + +- assert(d); +- assert(UNIT(d)->load_state == UNIT_STUB); ++ assert(u->load_state == UNIT_STUB); + + /* In contrast to all other unit types we timeout jobs waiting + * for devices by default. This is because they otherwise wait +@@ -137,9 +136,8 @@ static void device_init(Unit *u) { + } + + static void device_done(Unit *u) { +- Device *d = DEVICE(u); ++ Device *d = ASSERT_PTR(DEVICE(u)); + +- assert(d); + + device_unset_sysfs(d); + d->deserialized_sysfs = mfree(d->deserialized_sysfs); +@@ -258,9 +256,8 @@ static void device_update_found_by_name(Manager *m, const char *path, DeviceFoun + } + + static int device_coldplug(Unit *u) { +- Device *d = DEVICE(u); ++ Device *d = ASSERT_PTR(DEVICE(u)); + +- assert(d); + assert(d->state == DEVICE_DEAD); + + /* First, let's put the deserialized state and found mask into effect, if we have it. */ +@@ -336,9 +333,8 @@ static int device_coldplug(Unit *u) { + } + + static void device_catchup(Unit *u) { +- Device *d = DEVICE(u); ++ Device *d = ASSERT_PTR(DEVICE(u)); + +- assert(d); + + /* Second, let's update the state with the enumerated state */ + device_update_found_one(d, d->enumerated_found, DEVICE_FOUND_MASK); +@@ -405,11 +401,9 @@ static int device_found_from_string_many(const char *name, DeviceFound *ret) { + } + + static int device_serialize(Unit *u, FILE *f, FDSet *fds) { ++ Device *d = ASSERT_PTR(DEVICE(u)); + _cleanup_free_ char *s = NULL; +- Device *d = DEVICE(u); + +- assert(d); +- assert(u); + assert(f); + assert(fds); + +@@ -428,11 +422,9 @@ static int device_serialize(Unit *u, FILE *f, FDSet *fds) { + } + + static int device_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Device *d = DEVICE(u); ++ Device *d = ASSERT_PTR(DEVICE(u)); + int r; + +- assert(d); +- assert(u); + assert(key); + assert(value); + assert(fds); +@@ -472,10 +464,11 @@ static int device_deserialize_item(Unit *u, const char *key, const char *value, + } + + static void device_dump(Unit *u, FILE *f, const char *prefix) { +- Device *d = DEVICE(u); ++ Device *d = ASSERT_PTR(DEVICE(u)); + _cleanup_free_ char *s = NULL; + +- assert(d); ++ assert(f); ++ assert(prefix); + + (void) device_found_to_string_many(d->found, &s); + +@@ -495,15 +488,15 @@ static void device_dump(Unit *u, FILE *f, const char *prefix) { + } + + static UnitActiveState device_active_state(Unit *u) { +- assert(u); ++ Device *d = ASSERT_PTR(DEVICE(u)); + +- return state_translation_table[DEVICE(u)->state]; ++ return state_translation_table[d->state]; + } + + static const char *device_sub_state_to_string(Unit *u) { +- assert(u); ++ Device *d = ASSERT_PTR(DEVICE(u)); + +- return device_state_to_string(DEVICE(u)->state); ++ return device_state_to_string(d->state); + } + + static int device_update_description(Unit *u, sd_device *dev, const char *path) { +@@ -538,12 +531,11 @@ static int device_update_description(Unit *u, sd_device *dev, const char *path) + } + + static int device_add_udev_wants(Unit *u, sd_device *dev) { ++ Device *d = ASSERT_PTR(DEVICE(u)); + _cleanup_strv_free_ char **added = NULL; + const char *wants, *property; +- Device *d = DEVICE(u); + int r; + +- assert(d); + assert(dev); + + property = MANAGER_IS_USER(u->manager) ? "SYSTEMD_USER_WANTS" : "SYSTEMD_WANTS"; +@@ -645,6 +637,7 @@ static void device_upgrade_mount_deps(Unit *u) { + int r; + + /* Let's upgrade Requires= to BindsTo= on us. (Used when SYSTEMD_MOUNT_DEVICE_BOUND is set) */ ++ assert(u) + + HASHMAP_FOREACH_KEY(v, other, unit_get_dependencies(u, UNIT_REQUIRED_BY)) { + if (other->type != UNIT_MOUNT) +@@ -706,16 +699,18 @@ static int device_setup_unit(Manager *m, sd_device *dev, const char *path, bool + unit_add_to_load_queue(u); + } + +- if (!DEVICE(u)->path) { +- DEVICE(u)->path = strdup(path); +- if (!DEVICE(u)->path) ++ Device *d = ASSERT_PTR(DEVICE(u)); ++ ++ if (!d->path) { ++ d->path = strdup(path); ++ if (!d->path) + return log_oom(); + } + + /* If this was created via some dependency and has not actually been seen yet ->sysfs will not be + * initialized. Hence initialize it if necessary. */ + if (sysfs) { +- r = device_set_sysfs(DEVICE(u), sysfs); ++ r = device_set_sysfs(d, sysfs); + if (r < 0) + return log_unit_error_errno(u, r, "Failed to set sysfs path %s: %m", sysfs); + +@@ -730,11 +725,11 @@ static int device_setup_unit(Manager *m, sd_device *dev, const char *path, bool + * by systemd before the device appears on its radar. In this case the device unit is partially + * initialized and includes the deps on the mount unit but at that time the "bind mounts" flag wasn't + * present. Fix this up now. */ +- if (dev && device_is_bound_by_mounts(DEVICE(u), dev)) ++ if (dev && device_is_bound_by_mounts(d, dev)) + device_upgrade_mount_deps(u); + + if (units) { +- r = set_ensure_put(units, NULL, DEVICE(u)); ++ r = set_ensure_put(units, NULL, d); + if (r < 0) + return log_unit_error_errno(u, r, "Failed to store unit: %m"); + } +@@ -950,10 +945,8 @@ static int device_setup_units(Manager *m, sd_device *dev, Set **ready_units, Set + } + + static Unit *device_following(Unit *u) { +- Device *d = DEVICE(u); +- Device *first = NULL; ++ Device *d = ASSERT_PTR(DEVICE(u)), *first = NULL; + +- assert(d); + + if (startswith(u->id, "sys-")) + return NULL; +@@ -973,16 +966,15 @@ static Unit *device_following(Unit *u) { + return UNIT(first); + } + +-static int device_following_set(Unit *u, Set **_set) { +- Device *d = DEVICE(u); ++static int device_following_set(Unit *u, Set **ret) { ++ Device *d = ASSERT_PTR(DEVICE(u)); + _cleanup_set_free_ Set *set = NULL; + int r; + +- assert(d); +- assert(_set); ++ assert(ret); + + if (LIST_JUST_US(same_sysfs, d)) { +- *_set = NULL; ++ *ret = NULL; + return 0; + } + +@@ -1002,7 +994,7 @@ static int device_following_set(Unit *u, Set **_set) { + return r; + } + +- *_set = TAKE_PTR(set); ++ *ret = TAKE_PTR(set); + return 1; + } + +diff --git a/src/core/mount.c b/src/core/mount.c +index 26cade1..e3565cb 100644 +--- a/src/core/mount.c ++++ b/src/core/mount.c +@@ -185,10 +185,8 @@ static bool mount_needs_quota(const MountParameters *p) { + } + + static void mount_init(Unit *u) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + +- assert(m); +- assert(u); + assert(u->load_state == UNIT_STUB); + + m->timeout_usec = u->manager->defaults.timeout_start_usec; +@@ -235,9 +233,8 @@ static void mount_parameters_done(MountParameters *p) { + } + + static void mount_done(Unit *u) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + +- assert(m); + + m->where = mfree(m->where); + +@@ -262,6 +259,8 @@ static int update_parameters_proc_self_mountinfo( + MountParameters *p; + int r, q, w; + ++ assert(m); ++ + p = &m->parameters_proc_self_mountinfo; + + r = free_and_strdup(&p->what, what); +@@ -443,9 +442,8 @@ static int mount_add_quota_dependencies(Mount *m) { + } + + static bool mount_is_extrinsic(Unit *u) { ++ Mount *m = ASSERT_PTR(MOUNT(u)); + MountParameters *p; +- Mount *m = MOUNT(u); +- assert(m); + + /* Returns true for all units that are "magic" and should be excluded from the usual + * start-up and shutdown dependencies. We call them "extrinsic" here, as they are generally +@@ -668,10 +666,9 @@ static int mount_add_non_exec_dependencies(Mount *m) { + } + + static int mount_add_extras(Mount *m) { +- Unit *u = UNIT(m); ++ Unit *u = UNIT(ASSERT_PTR(m)); + int r; + +- assert(m); + + /* Note: this call might be called after we already have been loaded once (and even when it has already been + * activated), in case data from /proc/self/mountinfo has changed. This means all code here needs to be ready +@@ -717,7 +714,7 @@ static int mount_add_extras(Mount *m) { + } + + static void mount_load_root_mount(Unit *u) { +- assert(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + + if (!unit_has_name(u, SPECIAL_ROOT_MOUNT)) + return; +@@ -726,19 +723,17 @@ static void mount_load_root_mount(Unit *u) { + u->default_dependencies = false; + + /* The stdio/kmsg bridge socket is on /, in order to avoid a dep loop, don't use kmsg logging for -.mount */ +- MOUNT(u)->exec_context.std_output = EXEC_OUTPUT_NULL; +- MOUNT(u)->exec_context.std_input = EXEC_INPUT_NULL; ++ m->exec_context.std_output = EXEC_OUTPUT_NULL; ++ m->exec_context.std_input = EXEC_INPUT_NULL; + + if (!u->description) + u->description = strdup("Root Mount"); + } + + static int mount_load(Unit *u) { +- Mount *m = MOUNT(u); +- int r, q = 0; ++ Mount *m = ASSERT_PTR(MOUNT(u)); ++ int r; + +- assert(m); +- assert(u); + assert(u->load_state == UNIT_STUB); + + mount_load_root_mount(u); +@@ -787,10 +782,9 @@ static void mount_set_state(Mount *m, MountState state) { + } + + static int mount_coldplug(Unit *u) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + int r; + +- assert(m); + assert(m->state == MOUNT_DEAD); + + if (m->deserialized_state == m->state) +@@ -817,9 +811,8 @@ static int mount_coldplug(Unit *u) { + } + + static void mount_catchup(Unit *u) { +- Mount *m = MOUNT(ASSERT_PTR(u)); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + +- assert(m); + + /* Adjust the deserialized state. See comments in mount_process_proc_self_mountinfo(). */ + if (m->from_proc_self_mountinfo) +@@ -854,10 +847,9 @@ static void mount_catchup(Unit *u) { + } + + static void mount_dump(Unit *u, FILE *f, const char *prefix) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + MountParameters *p; + +- assert(m); + assert(f); + + p = get_mount_parameters(m); +@@ -1163,9 +1155,9 @@ static int mount_set_mount_command(Mount *m, ExecCommand *c, const MountParamete + } + + static void mount_enter_mounting(Mount *m) { +- int r; + MountParameters *p; + bool source_is_dir = true; ++ int r; + + assert(m); + +@@ -1246,8 +1238,8 @@ static void mount_set_reload_result(Mount *m, MountResult result) { + } + + static void mount_enter_remounting(Mount *m) { +- int r; + MountParameters *p; ++ int r; + + assert(m); + +@@ -1313,10 +1305,9 @@ static void mount_cycle_clear(Mount *m) { + } + + static int mount_start(Unit *u) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + int r; + +- assert(m); + + /* We cannot fulfill this request right now, try again later + * please! */ +@@ -1344,9 +1335,8 @@ static int mount_start(Unit *u) { + } + + static int mount_stop(Unit *u) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + +- assert(m); + + /* When we directly call umount() for a path, then the state of the corresponding mount unit may be + * outdated. Let's re-read mountinfo now and update the state. */ +@@ -1398,9 +1388,8 @@ static int mount_stop(Unit *u) { + } + + static int mount_reload(Unit *u) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + +- assert(m); + assert(m->state == MOUNT_MOUNTED); + + mount_enter_remounting(m); +@@ -1409,9 +1398,8 @@ static int mount_reload(Unit *u) { + } + + static int mount_serialize(Unit *u, FILE *f, FDSet *fds) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + +- assert(m); + assert(f); + assert(fds); + +@@ -1428,11 +1416,9 @@ static int mount_serialize(Unit *u, FILE *f, FDSet *fds) { + } + + static int mount_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + int r; + +- assert(m); +- assert(u); + assert(key); + assert(value); + assert(fds); +@@ -1498,15 +1484,14 @@ static UnitActiveState mount_active_state(Unit *u) { + } + + static const char *mount_sub_state_to_string(Unit *u) { +- assert(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + +- return mount_state_to_string(MOUNT(u)->state); ++ return mount_state_to_string(m->state); + } + + static bool mount_may_gc(Unit *u) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + +- assert(m); + + if (m->from_proc_self_mountinfo) + return false; +@@ -1515,10 +1500,9 @@ static bool mount_may_gc(Unit *u) { + } + + static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + MountResult f; + +- assert(m); + assert(pid >= 0); + + if (pid != m->control_pid.pid) +@@ -1641,9 +1625,8 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) { + } + + static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) { +- Mount *m = MOUNT(userdata); ++ Mount *m = ASSERT_PTR(MOUNT(userdata)); + +- assert(m); + assert(m->timer_event_source == source); + + switch (m->state) { +@@ -1775,14 +1758,15 @@ static int mount_setup_existing_unit( + const char *fstype, + MountProcFlags *ret_flags) { + ++ Mount *m = ASSERT_PTR(MOUNT(u)); + int r; + + assert(u); + assert(ret_flags); + +- if (!MOUNT(u)->where) { +- MOUNT(u)->where = strdup(where); +- if (!MOUNT(u)->where) ++ if (!m->where) { ++ m->where = strdup(where); ++ if (!m->where) + return -ENOMEM; + } + +@@ -1791,9 +1775,9 @@ static int mount_setup_existing_unit( + * /proc/self/mountinfo, hence we know for sure anything already set here is from the current + * iteration and thus worthy of taking into account. */ + MountProcFlags flags = +- MOUNT(u)->proc_flags | MOUNT_PROC_IS_MOUNTED; ++ m->proc_flags | MOUNT_PROC_IS_MOUNTED; + +- r = update_parameters_proc_self_mountinfo(MOUNT(u), what, options, fstype); ++ r = update_parameters_proc_self_mountinfo(m, what, options, fstype); + if (r < 0) + return r; + if (r > 0) +@@ -1806,10 +1790,10 @@ static int mount_setup_existing_unit( + * from the serialized state), and need to catch up. Since we know that the MOUNT_MOUNTING state is + * reached when we wait for the mount to appear we hence can assume that if we are in it, we are + * actually seeing it established for the first time. */ +- if (!MOUNT(u)->from_proc_self_mountinfo || MOUNT(u)->state == MOUNT_MOUNTING) ++ if (!m->from_proc_self_mountinfo || m->state == MOUNT_MOUNTING) + flags |= MOUNT_PROC_JUST_MOUNTED; + +- MOUNT(u)->from_proc_self_mountinfo = true; ++ m->from_proc_self_mountinfo = true; + + if (IN_SET(u->load_state, UNIT_NOT_FOUND, UNIT_BAD_SETTING, UNIT_ERROR)) { + /* The unit was previously not found or otherwise not loaded. Now that the unit shows up in +@@ -1823,7 +1807,7 @@ static int mount_setup_existing_unit( + if (FLAGS_SET(flags, MOUNT_PROC_JUST_CHANGED)) { + /* If things changed, then make sure that all deps are regenerated. Let's + * first remove all automatic deps, and then add in the new ones. */ +- r = mount_add_non_exec_dependencies(MOUNT(u)); ++ r = mount_add_non_exec_dependencies(m); + if (r < 0) + return r; + } +@@ -1939,12 +1923,10 @@ static void mount_shutdown(Manager *m) { + } + + static int mount_get_timeout(Unit *u, usec_t *timeout) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + usec_t t; + int r; + +- assert(m); +- assert(u); + + if (!m->timer_event_source) + return 0; +@@ -2319,18 +2301,16 @@ fail: + } + + static int mount_can_clean(Unit *u, ExecCleanMask *ret) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + +- assert(m); + + return exec_context_get_clean_mask(&m->exec_context, ret); + } + + static int mount_can_start(Unit *u) { +- Mount *m = MOUNT(u); ++ Mount *m = ASSERT_PTR(MOUNT(u)); + int r; + +- assert(m); + + r = unit_test_start_limit(u); + if (r < 0) { +diff --git a/src/core/path.c b/src/core/path.c +index 44481a9..7ece176 100644 +--- a/src/core/path.c ++++ b/src/core/path.c +@@ -249,6 +249,8 @@ static bool path_spec_check_good(PathSpec *s, bool initial, bool from_trigger_no + static void path_spec_mkdir(PathSpec *s, mode_t mode) { + int r; + ++ assert(s); ++ + if (IN_SET(s->type, PATH_EXISTS, PATH_EXISTS_GLOB)) + return; + +@@ -259,6 +261,10 @@ static void path_spec_mkdir(PathSpec *s, mode_t mode) { + + static void path_spec_dump(PathSpec *s, FILE *f, const char *prefix) { + const char *type; ++ ++ assert(s); ++ assert(f); ++ assert(prefix); + + assert_se(type = path_type_to_string(s->type)); + fprintf(f, "%s%s: %s\n", prefix, type, s->path); +@@ -272,9 +278,8 @@ void path_spec_done(PathSpec *s) { + } + + static void path_init(Unit *u) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + +- assert(u); + assert(u->load_state == UNIT_STUB); + + p->directory_mode = 0755; +@@ -295,9 +300,8 @@ void path_free_specs(Path *p) { + } + + static void path_done(Unit *u) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + +- assert(p); + + p->trigger_notify_event_source = sd_event_source_disable_unref(p->trigger_notify_event_source); + path_free_specs(p); +@@ -389,10 +393,9 @@ static int path_add_extras(Path *p) { + } + + static int path_load(Unit *u) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + int r; + +- assert(u); + assert(u->load_state == UNIT_STUB); + + r = unit_load_fragment_and_dropin(u, true); +@@ -410,11 +413,11 @@ static int path_load(Unit *u) { + } + + static void path_dump(Unit *u, FILE *f, const char *prefix) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + Unit *trigger; + +- assert(p); + assert(f); ++ assert(prefix); + + trigger = UNIT_TRIGGER(u); + +@@ -481,9 +484,8 @@ static void path_set_state(Path *p, PathState state) { + static void path_enter_waiting(Path *p, bool initial, bool from_trigger_notify); + + static int path_coldplug(Unit *u) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + +- assert(p); + assert(p->state == PATH_DEAD); + + if (p->deserialized_state != p->state) { +@@ -625,10 +627,9 @@ static void path_mkdir(Path *p) { + } + + static int path_start(Unit *u) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + int r; + +- assert(p); + assert(IN_SET(p->state, PATH_DEAD, PATH_FAILED)); + + r = unit_test_trigger_loaded(u); +@@ -658,9 +659,8 @@ static int path_stop(Unit *u) { + } + + static int path_serialize(Unit *u, FILE *f, FDSet *fds) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + +- assert(u); + assert(f); + assert(fds); + +@@ -688,9 +688,8 @@ static int path_serialize(Unit *u, FILE *f, FDSet *fds) { + } + + static int path_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + +- assert(u); + assert(key); + assert(value); + assert(fds); +@@ -755,27 +754,24 @@ static int path_deserialize_item(Unit *u, const char *key, const char *value, FD + } + + static UnitActiveState path_active_state(Unit *u) { +- assert(u); ++ Path *p = ASSERT_PTR(PATH(u)); + +- return state_translation_table[PATH(u)->state]; ++ return state_translation_table[p->state]; + } + + static const char *path_sub_state_to_string(Unit *u) { +- assert(u); ++ Path *p = ASSERT_PTR(PATH(u)); + +- return path_state_to_string(PATH(u)->state); ++ return path_state_to_string(p->state); + } + + static int path_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) { +- PathSpec *s = userdata, *found = NULL; +- Path *p; ++ PathSpec *s = ASSERT_PTR(userdata), *found = NULL; ++ Path *p = ASSERT_PTR(PATH(s->unit)); + int changed; + +- assert(s); +- assert(s->unit); + assert(fd >= 0); + +- p = PATH(s->unit); + + if (!IN_SET(p->state, PATH_WAITING, PATH_RUNNING)) + return 0; +@@ -827,10 +823,9 @@ static int path_trigger_notify_on_defer(sd_event_source *s, void *userdata) { + } + + static void path_trigger_notify_impl(Unit *u, Unit *other, bool on_defer) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + int r; + +- assert(u); + assert(other); + + /* Invoked whenever the unit we trigger changes state or gains or loses a job */ +@@ -897,9 +892,8 @@ static void path_trigger_notify(Unit *u, Unit *other) { + } + + static void path_reset_failed(Unit *u) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + +- assert(p); + + if (p->state == PATH_FAILED) + path_set_state(p, PATH_DEAD); +@@ -908,10 +902,9 @@ static void path_reset_failed(Unit *u) { + } + + static int path_can_start(Unit *u) { +- Path *p = PATH(u); ++ Path *p = ASSERT_PTR(PATH(u)); + int r; + +- assert(p); + + r = unit_test_start_limit(u); + if (r < 0) { +@@ -961,13 +954,11 @@ static int activation_details_path_deserialize(const char *key, const char *valu + } + + static int activation_details_path_append_env(ActivationDetails *details, char ***strv) { +- ActivationDetailsPath *p = ACTIVATION_DETAILS_PATH(details); ++ ActivationDetailsPath *p = ASSERT_PTR(ACTIVATION_DETAILS_PATH(details)); + char *s; + int r; + +- assert(details); + assert(strv); +- assert(p); + + if (isempty(p->trigger_path_filename)) + return 0; +@@ -984,12 +975,10 @@ static int activation_details_path_append_env(ActivationDetails *details, char * + } + + static int activation_details_path_append_pair(ActivationDetails *details, char ***strv) { +- ActivationDetailsPath *p = ACTIVATION_DETAILS_PATH(details); ++ ActivationDetailsPath *p = ASSERT_PTR(ACTIVATION_DETAILS_PATH(details)); + int r; + +- assert(details); + assert(strv); +- assert(p); + + if (isempty(p->trigger_path_filename)) + return 0; +diff --git a/src/core/scope.c b/src/core/scope.c +index e4c27da..eaf14dc 100644 +--- a/src/core/scope.c ++++ b/src/core/scope.c +@@ -35,9 +35,8 @@ static const UnitActiveState state_translation_table[_SCOPE_STATE_MAX] = { + static int scope_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata); + + static void scope_init(Unit *u) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + +- assert(u); + assert(u->load_state == UNIT_STUB); + + s->runtime_max_usec = USEC_INFINITY; +@@ -48,9 +47,8 @@ static void scope_init(Unit *u) { + } + + static void scope_done(Unit *u) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + +- assert(u); + + s->controller = mfree(s->controller); + s->controller_track = sd_bus_track_unref(s->controller_track); +@@ -181,10 +179,9 @@ static int scope_add_extras(Scope *s) { + } + + static int scope_load(Unit *u) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + int r; + +- assert(s); + assert(u->load_state == UNIT_STUB); + + if (!u->transient && !MANAGER_IS_RELOADING(u->manager)) +@@ -227,10 +224,9 @@ static usec_t scope_coldplug_timeout(Scope *s) { + } + + static int scope_coldplug(Unit *u) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + int r; + +- assert(s); + assert(s->state == SCOPE_DEAD); + + if (s->deserialized_state == s->state) +@@ -260,10 +256,10 @@ static int scope_coldplug(Unit *u) { + } + + static void scope_dump(Unit *u, FILE *f, const char *prefix) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + +- assert(s); + assert(f); ++ assert(prefix); + + fprintf(f, + "%sScope State: %s\n" +@@ -277,7 +273,7 @@ static void scope_dump(Unit *u, FILE *f, const char *prefix) { + prefix, FORMAT_TIMESPAN(s->runtime_rand_extra_usec, USEC_PER_SEC), + prefix, oom_policy_to_string(s->oom_policy)); + +- cgroup_context_dump(UNIT(s), f, prefix); ++ cgroup_context_dump(u, f, prefix); + kill_context_dump(&s->kill_context, f, prefix); + } + +@@ -350,11 +346,10 @@ fail: + } + + static int scope_enter_start_chown(Scope *s) { ++ Unit *u = UNIT(ASSERT_PTR(s)); + _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; +- Unit *u = UNIT(s); + int r; + +- assert(s); + assert(s->user); + + r = scope_arm_timer(s, /* relative= */ true, u->manager->defaults.timeout_start_usec); +@@ -411,11 +406,9 @@ fail: + } + + static int scope_enter_running(Scope *s) { +- Unit *u = UNIT(s); ++ Unit *u = UNIT(ASSERT_PTR(s)); + int r; + +- assert(s); +- + (void) bus_scope_track_controller(s); + + r = unit_acquire_invocation_id(u); +@@ -458,9 +451,8 @@ fail: + } + + static int scope_start(Unit *u) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + +- assert(s); + + if (unit_has_name(u, SPECIAL_INIT_SCOPE)) + return -EPERM; +@@ -489,9 +481,8 @@ static int scope_start(Unit *u) { + } + + static int scope_stop(Unit *u) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + +- assert(s); + + if (IN_SET(s->state, SCOPE_STOP_SIGTERM, SCOPE_STOP_SIGKILL)) + return 0; +@@ -503,9 +494,8 @@ static int scope_stop(Unit *u) { + } + + static void scope_reset_failed(Unit *u) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + +- assert(s); + + if (s->state == SCOPE_FAILED) + scope_set_state(s, SCOPE_DEAD); +@@ -514,7 +504,7 @@ static void scope_reset_failed(Unit *u) { + } + + static int scope_get_timeout(Unit *u, usec_t *timeout) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + usec_t t; + int r; + +@@ -532,10 +522,9 @@ static int scope_get_timeout(Unit *u, usec_t *timeout) { + } + + static int scope_serialize(Unit *u, FILE *f, FDSet *fds) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + PidRef *pid; + +- assert(s); + assert(f); + assert(fds); + +@@ -552,10 +541,9 @@ static int scope_serialize(Unit *u, FILE *f, FDSet *fds) { + } + + static int scope_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + int r; + +- assert(u); + assert(key); + assert(value); + assert(fds); +@@ -598,8 +586,7 @@ static int scope_deserialize_item(Unit *u, const char *key, const char *value, F + } + + static void scope_notify_cgroup_empty_event(Unit *u) { +- Scope *s = SCOPE(u); +- assert(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + + log_unit_debug(u, "cgroup is empty"); + +@@ -608,7 +595,7 @@ static void scope_notify_cgroup_empty_event(Unit *u) { + } + + static void scope_notify_cgroup_oom_event(Unit *u, bool managed_oom) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + + if (managed_oom) + log_unit_debug(u, "Process(es) of control group were killed by systemd-oomd."); +@@ -640,9 +627,8 @@ static void scope_notify_cgroup_oom_event(Unit *u, bool managed_oom) { + } + + static void scope_sigchld_event(Unit *u, pid_t pid, int code, int status) { +- Scope *s = SCOPE(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + +- assert(s); + + if (s->state == SCOPE_START_CHOWN) { + if (!is_clean_exit(code, status, EXIT_CLEAN_COMMAND, NULL)) +@@ -660,9 +646,8 @@ static void scope_sigchld_event(Unit *u, pid_t pid, int code, int status) { + } + + static int scope_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) { +- Scope *s = SCOPE(userdata); ++ Scope *s = ASSERT_PTR(SCOPE(userdata)); + +- assert(s); + assert(s->timer_event_source == source); + + switch (s->state) { +@@ -724,15 +709,15 @@ int scope_abandon(Scope *s) { + } + + static UnitActiveState scope_active_state(Unit *u) { +- assert(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + +- return state_translation_table[SCOPE(u)->state]; ++ return state_translation_table[s->state]; + } + + static const char *scope_sub_state_to_string(Unit *u) { +- assert(u); ++ Scope *s = ASSERT_PTR(SCOPE(u)); + +- return scope_state_to_string(SCOPE(u)->state); ++ return scope_state_to_string(s->state); + } + + static void scope_enumerate_perpetual(Manager *m) { +diff --git a/src/core/service.c b/src/core/service.c +index 9d5ef04..0939336 100644 +--- a/src/core/service.c ++++ b/src/core/service.c +@@ -170,6 +170,7 @@ static void service_unwatch_main_pid(Service *s) { + } + + static void service_unwatch_pid_file(Service *s) { ++ assert(s); + if (!s->pid_file_pathspec) + return; + +@@ -439,9 +440,8 @@ static void service_release_stdio_fd(Service *s) { + s->stderr_fd = asynchronous_close(s->stderr_fd); + } + static void service_done(Unit *u) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + +- assert(s); + + open_file_free_many(&s->open_files); + +@@ -857,7 +857,7 @@ static int service_add_extras(Service *s) { + } + + static int service_load(Unit *u) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + int r; + + r = unit_load_fragment_and_dropin(u, true); +@@ -912,10 +912,9 @@ static void service_dump_fdstore(Service *s, FILE *f, const char *prefix) { + } + + static void service_dump(Unit *u, FILE *f, const char *prefix) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + const char *prefix2; + +- assert(s); + + prefix = strempty(prefix); + prefix2 = strjoina(prefix, "\t"); +@@ -2770,9 +2769,8 @@ static int service_start(Unit *u) { + } + + static int service_stop(Unit *u) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + +- assert(s); + + /* Don't create restart jobs from manual stops. */ + s->forbid_restart = true; +@@ -2829,9 +2827,8 @@ static int service_stop(Unit *u) { + } + + static int service_reload(Unit *u) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + +- assert(s); + + assert(IN_SET(s->state, SERVICE_RUNNING, SERVICE_EXITED)); + +@@ -2840,9 +2837,8 @@ static int service_reload(Unit *u) { + } + + static bool service_can_reload(Unit *u) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + +- assert(s); + + return s->exec_command[SERVICE_EXEC_RELOAD] || + s->type == SERVICE_NOTIFY_RELOAD; +@@ -2870,14 +2866,13 @@ static unsigned service_exec_command_index(Unit *u, ServiceExecCommand id, const + } + + static int service_serialize_exec_command(Unit *u, FILE *f, const ExecCommand *command) { ++ Service *s = ASSERT_PTR(SERVICE(u)); + _cleanup_free_ char *args = NULL, *p = NULL; +- Service *s = SERVICE(u); + const char *type, *key; + ServiceExecCommand id; + size_t length = 0; + unsigned idx; + +- assert(s); + assert(f); + + if (!command) +@@ -2939,10 +2934,9 @@ static int service_serialize_exec_command(Unit *u, FILE *f, const ExecCommand *c + } + + static int service_serialize(Unit *u, FILE *f, FDSet *fds) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + int r; + +- assert(u); + assert(f); + assert(fds); + +@@ -3045,14 +3039,14 @@ int service_deserialize_exec_command( + const char *key, + const char *value) { + +- Service *s = SERVICE(u); +- int r; +- unsigned idx = 0, i; +- bool control, found = false, last = false; +- ServiceExecCommand id = _SERVICE_EXEC_COMMAND_INVALID; ++ Service *s = ASSERT_PTR(SERVICE(u)); + ExecCommand *command = NULL; ++ ServiceExecCommand id = _SERVICE_EXEC_COMMAND_INVALID; + _cleanup_free_ char *path = NULL; + _cleanup_strv_free_ char **argv = NULL; ++ unsigned idx = 0, i; ++ bool control, found = false, last = false; ++ int r; + + enum ExecCommandState { + STATE_EXEC_COMMAND_TYPE, +@@ -3063,7 +3057,6 @@ int service_deserialize_exec_command( + _STATE_EXEC_COMMAND_INVALID = -EINVAL, + } state; + +- assert(s); + assert(key); + assert(value); + +@@ -3151,10 +3144,9 @@ int service_deserialize_exec_command( + } + + static int service_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + int r; + +- assert(u); + assert(key); + assert(value); + assert(fds); +@@ -3395,13 +3387,13 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value, + } + + static UnitActiveState service_active_state(Unit *u) { ++ Service *s = ASSERT_PTR(SERVICE(u)); + const UnitActiveState *table; + +- assert(u); + +- table = SERVICE(u)->type == SERVICE_IDLE ? state_translation_table_idle : state_translation_table; ++ table = s->type == SERVICE_IDLE ? state_translation_table_idle : state_translation_table; + +- return table[SERVICE(u)->state]; ++ return table[s->state]; + } + + static const char *service_sub_state_to_string(Unit *u) { +@@ -3411,9 +3403,8 @@ static const char *service_sub_state_to_string(Unit *u) { + } + + static bool service_may_gc(Unit *u) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + +- assert(s); + + /* Never clean up services that still have a process around, even if the service is formally dead. Note that + * unit_may_gc() already checked our cgroup for us, we just check our two additional PIDs, too, in case they +@@ -3433,7 +3424,7 @@ static bool service_may_gc(Unit *u) { + + static int service_retry_pid_file(Service *s) { + int r; +- ++ assert(s); + assert(s->pid_file); + assert(IN_SET(s->state, SERVICE_START, SERVICE_START_POST)); + +@@ -3450,6 +3441,8 @@ static int service_retry_pid_file(Service *s) { + static int service_watch_pid_file(Service *s) { + int r; + ++ assert(s); ++ + log_unit_debug(UNIT(s), "Setting watch for PID file %s", s->pid_file_pathspec->path); + + r = path_spec_watch(s->pid_file_pathspec, service_dispatch_inotify_io); +@@ -3469,6 +3462,8 @@ static int service_watch_pid_file(Service *s) { + static int service_demand_pid_file(Service *s) { + _cleanup_free_ PathSpec *ps = NULL; + ++ assert(s); ++ + assert(s->pid_file); + assert(!s->pid_file_pathspec); + +@@ -3497,11 +3492,9 @@ static int service_demand_pid_file(Service *s) { + + static int service_dispatch_inotify_io(sd_event_source *source, int fd, uint32_t events, void *userdata) { + PathSpec *p = ASSERT_PTR(userdata); +- Service *s; ++ Service *s = ASSERT_PTR(SERVICE(p->unit)); + +- s = SERVICE(p->unit); + +- assert(s); + assert(fd >= 0); + assert(IN_SET(s->state, SERVICE_START, SERVICE_START_POST)); + assert(s->pid_file_pathspec); +@@ -3527,9 +3520,8 @@ fail: + } + + static int service_dispatch_exec_io(sd_event_source *source, int fd, uint32_t events, void *userdata) { +- Service *s = SERVICE(userdata); ++ Service *s = ASSERT_PTR(SERVICE(userdata)); + +- assert(s); + + log_unit_debug(UNIT(s), "got exec-fd event"); + +@@ -3580,9 +3572,8 @@ static int service_dispatch_exec_io(sd_event_source *source, int fd, uint32_t ev + } + + static void service_notify_cgroup_empty_event(Unit *u) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + +- assert(u); + + log_unit_debug(u, "Control group is empty."); + +@@ -3657,7 +3648,7 @@ static void service_notify_cgroup_empty_event(Unit *u) { + } + + static void service_notify_cgroup_oom_event(Unit *u, bool managed_oom) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + + if (managed_oom) + log_unit_debug(u, "Process(es) of control group were killed by systemd-oomd."); +@@ -3712,12 +3703,11 @@ static void service_notify_cgroup_oom_event(Unit *u, bool managed_oom) { + } + + static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { ++ Service *s = ASSERT_PTR(SERVICE(u)); + bool notify_dbus = true; +- Service *s = SERVICE(u); + ServiceResult f; + ExitClean clean_mode; + +- assert(s); + assert(pid >= 0); + + /* Oneshot services and non-SERVICE_EXEC_START commands should not be +@@ -4084,9 +4074,8 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { + } + + static int service_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) { +- Service *s = SERVICE(userdata); ++ Service *s = ASSERT_PTR(SERVICE(userdata)); + +- assert(s); + assert(source == s->timer_event_source); + + switch (s->state) { +@@ -4283,10 +4272,9 @@ static int service_dispatch_timer(sd_event_source *source, usec_t usec, void *us + } + + static int service_dispatch_watchdog(sd_event_source *source, usec_t usec, void *userdata) { +- Service *s = SERVICE(userdata); ++ Service *s = ASSERT_PTR(SERVICE(userdata)); + usec_t watchdog_usec; + +- assert(s); + assert(source == s->watchdog_event_source); + + watchdog_usec = service_get_watchdog_usec(s); +@@ -4340,6 +4328,7 @@ static bool service_notify_message_authorized(Service *s, pid_t pid, FDSet *fds) + } + + static void service_force_watchdog(Service *s) { ++ assert(s); + if (!UNIT(s)->manager->service_watchdogs) + return; + +@@ -4594,10 +4583,12 @@ static void service_notify_message( + } + + static int service_get_timeout(Unit *u, usec_t *timeout) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + uint64_t t; + int r; + ++ assert(timeout); ++ + if (!s->timer_event_source) + return 0; + +@@ -4612,7 +4603,7 @@ static int service_get_timeout(Unit *u, usec_t *timeout) { + } + + static usec_t service_get_timeout_start_usec(Unit *u) { +- Service *s = SERVICE(ASSERT_PTR(u)); ++ Service *s = ASSERT_PTR(SERVICE(u)); + return s->timeout_start_usec; + } + +@@ -4632,16 +4623,14 @@ static bool pick_up_pid_from_bus_name(Service *s) { + } + + static int bus_name_pid_lookup_callback(sd_bus_message *reply, void *userdata, sd_bus_error *ret_error) { ++ Unit *u = ASSERT_PTR(SERVICE(userdata)); + _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; + const sd_bus_error *e; +- Unit *u = ASSERT_PTR(userdata); + uint32_t pid; +- Service *s; + int r; + + assert(reply); + +- s = SERVICE(u); + s->bus_name_pid_lookup_slot = sd_bus_slot_unref(s->bus_name_pid_lookup_slot); + + if (!s->bus_name || !pick_up_pid_from_bus_name(s)) +@@ -4666,7 +4655,7 @@ static int bus_name_pid_lookup_callback(sd_bus_message *reply, void *userdata, s + return 1; + } + +- log_unit_debug(u, "D-Bus name %s is now owned by process " PID_FMT, s->bus_name, pidref.pid); ++ log_unit_debug(UNIT(s), "D-Bus name %s is now owned by process " PID_FMT, s->bus_name, pidref.pid); + + (void) service_set_main_pidref(s, &pidref); + (void) unit_watch_pidref(UNIT(s), &s->main_pid, /* exclusive= */ false); +@@ -4675,10 +4664,9 @@ static int bus_name_pid_lookup_callback(sd_bus_message *reply, void *userdata, s + + static void service_bus_name_owner_change(Unit *u, const char *new_owner) { + +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + int r; + +- assert(s); + + if (new_owner) + log_unit_debug(u, "D-Bus name %s now owned by %s", s->bus_name, new_owner); +@@ -4781,9 +4769,8 @@ int service_set_socket_fd( + } + + static void service_reset_failed(Unit *u) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + +- assert(s); + + if (s->state == SERVICE_FAILED) + service_set_state(s, service_determine_dead_state(s)); +@@ -4804,9 +4791,8 @@ static PidRef* service_control_pid(Unit *u) { + } + + static bool service_needs_console(Unit *u) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + +- assert(s); + + /* We provide our own implementation of this here, instead of relying of the generic implementation + * unit_needs_console() provides, since we want to return false if we are in SERVICE_EXITED state. */ +@@ -4849,20 +4835,17 @@ static int service_exit_status(Unit *u) { + } + + static const char* service_status_text(Unit *u) { +- Service *s = SERVICE(u); +- +- assert(s); ++ Service *s = ASSERT_PTR(SERVICE(u)); + + return s->status_text; + } + + static int service_clean(Unit *u, ExecCleanMask mask) { ++ Service *s = ASSERT_PTR(SERVICE(u)); + _cleanup_strv_free_ char **l = NULL; + bool may_clean_fdstore = false; +- Service *s = SERVICE(u); + int r; + +- assert(s); + assert(mask != 0); + + if (!IN_SET(s->state, SERVICE_DEAD, SERVICE_DEAD_RESOURCES_PINNED)) +@@ -4918,11 +4901,10 @@ fail: + } + + static int service_can_clean(Unit *u, ExecCleanMask *ret) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + ExecCleanMask mask = 0; + int r; + +- assert(s); + assert(ret); + + r = exec_context_get_clean_mask(&s->exec_context, &mask); +@@ -4937,9 +4919,11 @@ static int service_can_clean(Unit *u, ExecCleanMask *ret) { + } + + static const char *service_finished_job(Unit *u, JobType t, JobResult result) { ++ Service *s = ASSERT_PTR(SERVICE(u)); ++ + if (t == JOB_START && + result == JOB_DONE && +- SERVICE(u)->type == SERVICE_ONESHOT) ++ s->type == SERVICE_ONESHOT) + return "Finished %s."; + + /* Fall back to generic */ +@@ -4947,10 +4931,9 @@ static const char *service_finished_job(Unit *u, JobType t, JobResult result) { + } + + static int service_can_start(Unit *u) { +- Service *s = SERVICE(u); ++ Service *s = ASSERT_PTR(SERVICE(u)); + int r; + +- assert(s); + + /* Make sure we don't enter a busy loop of some kind. */ + r = unit_test_start_limit(u); +@@ -4963,7 +4946,7 @@ static int service_can_start(Unit *u) { + } + + static void service_release_resources(Unit *u) { +- Service *s = SERVICE(ASSERT_PTR(u)); ++ Service *s = ASSERT_PTR(SERVICE(u)); + + /* Invoked by the unit state engine, whenever it realizes that unit is dead and there's no job + * anymore for it, and it hence is a good idea to release resources */ +diff --git a/src/core/slice.c b/src/core/slice.c +index fb4f23c..c938caa 100644 +--- a/src/core/slice.c ++++ b/src/core/slice.c +@@ -47,11 +47,10 @@ static void slice_set_state(Slice *t, SliceState state) { + } + + static int slice_add_parent_slice(Slice *s) { +- Unit *u = UNIT(s); ++ Unit *u = UNIT(ASSERT_PTR(s)); + _cleanup_free_ char *a = NULL; + int r; + +- assert(s); + + if (UNIT_GET_SLICE(u)) + return 0; +@@ -151,10 +150,10 @@ static int slice_load_system_slice(Unit *u) { + } + + static int slice_load(Unit *u) { +- Slice *s = SLICE(u); ++ Slice *s = ASSERT_PTR(SLICE(u)); + int r; + +- assert(s); ++ + assert(u->load_state == UNIT_STUB); + + r = slice_load_root_slice(u); +@@ -196,36 +195,35 @@ static int slice_load(Unit *u) { + } + + static int slice_coldplug(Unit *u) { +- Slice *t = SLICE(u); ++ Slice *s = ASSERT_PTR(SLICE(u)); + +- assert(t); +- assert(t->state == SLICE_DEAD); ++ assert(s->state == SLICE_DEAD); + +- if (t->deserialized_state != t->state) +- slice_set_state(t, t->deserialized_state); ++ if (s->deserialized_state != s->state) ++ slice_set_state(s, s->deserialized_state); + + return 0; + } + + static void slice_dump(Unit *u, FILE *f, const char *prefix) { +- Slice *t = SLICE(u); ++ Slice *s = ASSERT_PTR(SLICE(u)); + +- assert(t); ++ + assert(f); ++ assert(prefix); + + fprintf(f, + "%sSlice State: %s\n", +- prefix, slice_state_to_string(t->state)); ++ prefix, slice_state_to_string(s->state)); + + cgroup_context_dump(UNIT(t), f, prefix); + } + + static int slice_start(Unit *u) { +- Slice *t = SLICE(u); ++ Slice *s = ASSERT_PTR(SLICE(u)); + int r; + +- assert(t); +- assert(t->state == SLICE_DEAD); ++ assert(s->state == SLICE_DEAD); + + r = unit_acquire_invocation_id(u); + if (r < 0) +@@ -234,27 +232,26 @@ static int slice_start(Unit *u) { + (void) unit_realize_cgroup(u); + (void) unit_reset_accounting(u); + +- slice_set_state(t, SLICE_ACTIVE); ++ slice_set_state(s, SLICE_ACTIVE); + return 1; + } + + static int slice_stop(Unit *u) { +- Slice *t = SLICE(u); ++ Slice *s = ASSERT_PTR(SLICE(u)); + +- assert(t); +- assert(t->state == SLICE_ACTIVE); ++ assert(s->state == SLICE_ACTIVE); + + /* We do not need to destroy the cgroup explicitly, + * unit_notify() will do that for us anyway. */ + +- slice_set_state(t, SLICE_DEAD); ++ slice_set_state(s, SLICE_DEAD); + return 1; + } + + static int slice_serialize(Unit *u, FILE *f, FDSet *fds) { +- Slice *s = SLICE(u); ++ Slice *s = ASSERT_PTR(SLICE(u)); + +- assert(s); ++ + assert(f); + assert(fds); + +@@ -264,9 +261,9 @@ static int slice_serialize(Unit *u, FILE *f, FDSet *fds) { + } + + static int slice_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Slice *s = SLICE(u); ++ Slice *s = ASSERT_PTR(SLICE(u)); + +- assert(u); ++ + assert(key); + assert(value); + assert(fds); +@@ -276,26 +273,26 @@ static int slice_deserialize_item(Unit *u, const char *key, const char *value, F + + state = slice_state_from_string(value); + if (state < 0) +- log_debug("Failed to parse state value %s", value); ++ log_unit_debug(u, "Failed to parse state: %s", value); + else + s->deserialized_state = state; + + } else +- log_debug("Unknown serialization key '%s'", key); ++ log_unit_debug(u, "Unknown serialization key: %s", key); + + return 0; + } + + static UnitActiveState slice_active_state(Unit *u) { +- assert(u); ++ Slice *s = ASSERT_PTR(SLICE(u)); + +- return state_translation_table[SLICE(u)->state]; ++ return state_translation_table[s->state]; + } + + static const char *slice_sub_state_to_string(Unit *u) { +- assert(u); ++ Slice *s = ASSERT_PTR(SLICE(u)); + +- return slice_state_to_string(SLICE(u)->state); ++ return slice_state_to_string(s->state); + } + + static int slice_make_perpetual(Manager *m, const char *name, Unit **ret) { +diff --git a/src/core/socket.c b/src/core/socket.c +index 388be62..4bb295c 100644 +--- a/src/core/socket.c ++++ b/src/core/socket.c +@@ -144,11 +144,10 @@ void socket_free_ports(Socket *s) { + } + + static void socket_done(Unit *u) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + SocketPeer *p; + +- assert(s); +- ++ + socket_free_ports(s); + + while ((p = set_steal_first(s->peers_by_address))) +@@ -273,10 +272,10 @@ static bool socket_has_exec(Socket *s) { + } + + static int socket_add_extras(Socket *s) { +- Unit *u = UNIT(s); ++ Unit *u = UNIT(ASSERT_PTR(s)); + int r; + +- assert(s); ++ + + /* Pick defaults for the trigger limit, if nothing was explicitly configured. We pick a relatively high limit + * in Accept=yes mode, and a lower limit for Accept=no. Reason: in Accept=yes mode we are invoking accept() +@@ -436,10 +435,10 @@ static int peer_address_compare_func(const SocketPeer *x, const SocketPeer *y) { + DEFINE_PRIVATE_HASH_OPS(peer_address_hash_ops, SocketPeer, peer_address_hash_func, peer_address_compare_func); + + static int socket_load(Unit *u) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + int r; + +- assert(u); ++ + assert(u->load_state == UNIT_STUB); + + r = unit_load_fragment_and_dropin(u, true); +@@ -488,8 +487,9 @@ int socket_acquire_peer(Socket *s, int fd, SocketPeer **ret) { + }, *i; + int r; + +- assert(fd >= 0); ++ + assert(s); ++ assert(fd >= 0); + assert(ret); + + if (getpeername(fd, &sa.peer.sa, &sa.peer_salen) < 0) +@@ -540,10 +540,10 @@ static const char* listen_lookup(int family, int type) { + } + + static void socket_dump(Unit *u, FILE *f, const char *prefix) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + const char *prefix2, *str; + +- assert(s); ++ + assert(f); + + prefix = strempty(prefix); +@@ -1274,6 +1274,9 @@ static int socket_symlink(Socket *s) { + static int usbffs_write_descs(int fd, Service *s) { + int r; + ++ assert(fd >= 0); ++ assert(s); ++ + if (!s->usb_function_descriptors || !s->usb_function_strings) + return -EINVAL; + +@@ -1345,6 +1348,9 @@ int socket_load_service_unit(Socket *s, int cfd, Unit **ret) { + * instance name. + */ + ++ assert(s); ++ assert(ret); ++ + if (UNIT_ISSET(s->service)) { + *ret = UNIT_DEREF(s->service); + return 0; +@@ -1841,10 +1847,10 @@ static void socket_set_state(Socket *s, SocketState state) { + } + + static int socket_coldplug(Unit *u) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + int r; + +- assert(s); ++ + assert(s->state == SOCKET_DEAD); + + if (s->deserialized_state == s->state) +@@ -2444,10 +2450,10 @@ static void socket_run_next(Socket *s) { + } + + static int socket_start(Unit *u) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + int r; + +- assert(s); ++ + + /* We cannot fulfill this request right now, try again later + * please! */ +@@ -2503,9 +2509,9 @@ static int socket_start(Unit *u) { + } + + static int socket_stop(Unit *u) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + +- assert(s); ++ + + /* Already on it */ + if (IN_SET(s->state, +@@ -2540,10 +2546,10 @@ static int socket_stop(Unit *u) { + } + + static int socket_serialize(Unit *u, FILE *f, FDSet *fds) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + int r; + +- assert(u); ++ + assert(f); + assert(fds); + +@@ -2595,10 +2601,10 @@ static int socket_serialize(Unit *u, FILE *f, FDSet *fds) { + } + + static int socket_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + int r; + +- assert(u); ++ + assert(key); + assert(value); + +@@ -2835,9 +2841,9 @@ 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); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + +- assert(u); ++ + + LIST_FOREACH(port, p, s->ports) { + int fd; +@@ -2859,15 +2865,15 @@ static void socket_distribute_fds(Unit *u, FDSet *fds) { + } + + static UnitActiveState socket_active_state(Unit *u) { +- assert(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + +- return state_translation_table[SOCKET(u)->state]; ++ return state_translation_table[s->state]; + } + + static const char *socket_sub_state_to_string(Unit *u) { +- assert(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + +- return socket_state_to_string(SOCKET(u)->state); ++ return socket_state_to_string(s->state); + } + + int socket_port_to_address(const SocketPort *p, char **ret) { +@@ -2967,9 +2973,9 @@ SocketType socket_port_type_from_string(const char *s) { + } + + static bool socket_may_gc(Unit *u) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + +- assert(u); ++ + + return s->n_connections == 0; + } +@@ -3107,10 +3113,10 @@ fail: + } + + static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + SocketResult f; + +- assert(s); ++ + assert(pid >= 0); + + if (pid != s->control_pid.pid) +@@ -3214,9 +3220,9 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) { + } + + static int socket_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) { +- Socket *s = SOCKET(userdata); ++ Socket *s = ASSERT_PTR(SOCKET(userdata)); + +- assert(s); ++ + assert(s->timer_event_source == source); + + switch (s->state) { +@@ -3352,9 +3358,9 @@ void socket_connection_unref(Socket *s) { + } + + static void socket_trigger_notify(Unit *u, Unit *other) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + +- assert(u); ++ + assert(other); + + /* Filter out invocations with bogus state */ +@@ -3390,7 +3396,7 @@ static void socket_trigger_notify(Unit *u, Unit *other) { + } + + static int socket_get_timeout(Unit *u, usec_t *timeout) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + usec_t t; + int r; + +@@ -3422,11 +3428,12 @@ static PidRef *socket_control_pid(Unit *u) { + } + + static int socket_clean(Unit *u, ExecCleanMask mask) { ++ Socket *s = ASSERT_PTR(SOCKET(u)); + _cleanup_strv_free_ char **l = NULL; +- Socket *s = SOCKET(u); ++ + int r; + +- assert(s); ++ + assert(mask != 0); + + if (s->state != SOCKET_DEAD) +@@ -3466,18 +3473,18 @@ fail: + } + + static int socket_can_clean(Unit *u, ExecCleanMask *ret) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + +- assert(s); ++ + + return exec_context_get_clean_mask(&s->exec_context, ret); + } + + static int socket_can_start(Unit *u) { +- Socket *s = SOCKET(u); ++ Socket *s = ASSERT_PTR(SOCKET(u)); + int r; + +- assert(s); ++ + + r = unit_test_start_limit(u); + if (r < 0) { +diff --git a/src/core/swap.c b/src/core/swap.c +index 488b171..dbe2dbb 100644 +--- a/src/core/swap.c ++++ b/src/core/swap.c +@@ -68,9 +68,9 @@ static const char *swap_sub_state_to_string(Unit *u) { + } + + static bool swap_may_gc(Unit *u) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + +- assert(s); ++ + + if (s->from_proc_swaps) + return false; +@@ -134,10 +134,9 @@ static int swap_set_devnode(Swap *s, const char *devnode) { + } + + static void swap_init(Unit *u) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + +- assert(s); +- assert(UNIT(s)->load_state == UNIT_STUB); ++ assert(u->load_state == UNIT_STUB); + + s->timeout_usec = u->manager->defaults.timeout_start_usec; + +@@ -161,9 +160,9 @@ static void swap_unwatch_control_pid(Swap *s) { + } + + static void swap_done(Unit *u) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + +- assert(s); ++ + + swap_unset_proc_swaps(s); + swap_set_devnode(s, NULL); +@@ -255,6 +254,8 @@ static int swap_verify(Swap *s) { + _cleanup_free_ char *e = NULL; + int r; + ++ assert(s); ++ + assert(UNIT(s)->load_state == UNIT_LOADED); + + r = unit_name_from_path(s->what, ".swap", &e); +@@ -353,10 +354,10 @@ static int swap_add_extras(Swap *s) { + } + + static int swap_load(Unit *u) { +- Swap *s = SWAP(u); +- int r, q = 0; ++ Swap *s = ASSERT_PTR(SWAP(u)); ++ int r; + +- assert(s); ++ + assert(u->load_state == UNIT_STUB); + + /* Load a .swap file */ +@@ -386,10 +387,11 @@ static int swap_setup_unit( + bool set_flags) { + + _cleanup_free_ char *e = NULL; +- bool delete = false; +- Unit *u = NULL; +- int r; ++ bool new; ++ Unit *u; ++ Swap *s; + SwapParameters *p; ++ int r; + + assert(m); + assert(what); +@@ -397,18 +399,21 @@ static int swap_setup_unit( + + r = unit_name_from_path(what, ".swap", &e); + if (r < 0) +- return log_unit_error_errno(u, r, "Failed to generate unit name from path: %m"); ++ return log_error_errno(r, "Failed to generate unit name from path: %m"); + + u = manager_get_unit(m, e); +- if (u && +- SWAP(u)->from_proc_swaps && +- !path_equal(SWAP(u)->parameters_proc_swaps.what, what_proc_swaps)) ++ if (u) { ++ s = ASSERT_PTR(SWAP(u)); ++ ++ if (s->from_proc_swaps && ++ !path_equal(s->parameters_proc_swaps.what, what_proc_swaps)) + return log_error_errno(SYNTHETIC_ERRNO(EEXIST), +- "Swap %s appeared twice with different device paths %s and %s", +- e, SWAP(u)->parameters_proc_swaps.what, what_proc_swaps); ++ "Swap %s appeared twice with different device paths %s and %s, refusing.", ++ e, s->parameters_proc_swaps.what, what_proc_swaps); + +- if (!u) { +- delete = true; ++ new = false; ++ } else { ++ new = true; + + r = unit_new_for_name(m, sizeof(Swap), e, &u); + if (r < 0) { +@@ -416,19 +421,20 @@ static int swap_setup_unit( + goto fail; + } + +- SWAP(u)->what = strdup(what); +- if (!SWAP(u)->what) { ++ s = ASSERT_PTR(SWAP(u)); ++ ++ s->what = strdup(what); ++ if (s->what) { + r = log_oom(); + goto fail; + } + + unit_add_to_load_queue(u); +- } else +- delete = false; ++ } + +- p = &SWAP(u)->parameters_proc_swaps; ++ p = &s->parameters_proc_swaps; + +- if (!p->what) { ++ if (!s->parameters_proc_swaps.what) { + p->what = strdup(what_proc_swaps); + if (!p->what) { + r = log_oom(); +@@ -444,11 +450,11 @@ static int swap_setup_unit( + } + + if (set_flags) { +- SWAP(u)->is_active = true; +- SWAP(u)->just_activated = !SWAP(u)->from_proc_swaps; ++ s->is_active = true; ++ s->just_activated = !SWAP(u)->from_proc_swaps; + } + +- SWAP(u)->from_proc_swaps = true; ++ s->from_proc_swaps = true; + + p->priority = priority; + p->priority_set = true; +@@ -457,7 +463,7 @@ static int swap_setup_unit( + return 0; + + fail: +- if (delete) ++ if (!new) + unit_free(u); + + return r; +@@ -541,11 +547,11 @@ static void swap_set_state(Swap *s, SwapState state) { + } + + static int swap_coldplug(Unit *u) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + SwapState new_state = SWAP_DEAD; + int r; + +- assert(s); ++ + assert(s->state == SWAP_DEAD); + + if (s->deserialized_state != s->state) +@@ -577,10 +583,10 @@ static int swap_coldplug(Unit *u) { + } + + static void swap_dump(Unit *u, FILE *f, const char *prefix) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + SwapParameters *p; + +- assert(s); ++ + assert(f); + + if (s->from_proc_swaps) +@@ -913,9 +919,9 @@ static int swap_start(Unit *u) { + } + + static int swap_stop(Unit *u) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + +- assert(s); ++ + + switch (s->state) { + +@@ -949,9 +955,9 @@ static int swap_stop(Unit *u) { + } + + static int swap_serialize(Unit *u, FILE *f, FDSet *fds) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + +- assert(s); ++ + assert(f); + assert(fds); + +@@ -966,9 +972,9 @@ static int swap_serialize(Unit *u, FILE *f, FDSet *fds) { + } + + static int swap_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + +- assert(s); ++ + assert(fds); + + if (streq(key, "state")) { +@@ -1009,10 +1015,10 @@ static int swap_deserialize_item(Unit *u, const char *key, const char *value, FD + } + + static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + SwapResult f; + +- assert(s); ++ + assert(pid >= 0); + + if (pid != s->control_pid.pid) +@@ -1086,9 +1092,9 @@ static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) { + } + + static int swap_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) { +- Swap *s = SWAP(userdata); ++ Swap *s = ASSERT_PTR(SWAP(userdata)); + +- assert(s); ++ + assert(s->timer_event_source == source); + + switch (s->state) { +@@ -1262,10 +1268,10 @@ 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 *s = ASSERT_PTR(SWAP(u)); + Swap *first = NULL; + +- assert(s); ++ + + /* If the user configured the swap through /etc/fstab or + * a device unit, follow that. */ +@@ -1298,16 +1304,16 @@ static Unit *swap_following(Unit *u) { + return UNIT(first); + } + +-static int swap_following_set(Unit *u, Set **_set) { +- Swap *s = SWAP(u); ++static int swap_following_set(Unit *u, Set **ret) { ++ Swap *s = ASSERT_PTR(SWAP(u)); + _cleanup_set_free_ Set *set = NULL; + int r; + +- assert(s); +- assert(_set); ++ assert(ret); ++ + + if (LIST_JUST_US(same_devnode, s)) { +- *_set = NULL; ++ *ret = NULL; + return 0; + } + +@@ -1321,7 +1327,7 @@ static int swap_following_set(Unit *u, Set **_set) { + return r; + } + +- *_set = TAKE_PTR(set); ++ *ret = TAKE_PTR(set); + return 1; + } + +@@ -1441,9 +1447,9 @@ int swap_process_device_remove(Manager *m, sd_device *dev) { + } + + static void swap_reset_failed(Unit *u) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + +- assert(s); ++ + + if (s->state == SWAP_FAILED) + swap_set_state(s, SWAP_DEAD); +@@ -1453,12 +1459,11 @@ static void swap_reset_failed(Unit *u) { + } + + static int swap_get_timeout(Unit *u, usec_t *timeout) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + usec_t t; + int r; + +- assert(s); +- assert(u); ++ + + if (!s->timer_event_source) + return 0; +@@ -1493,11 +1498,12 @@ static PidRef* swap_control_pid(Unit *u) { + } + + static int swap_clean(Unit *u, ExecCleanMask mask) { ++ Swap *s = ASSERT_PTR(SWAP(u)); + _cleanup_strv_free_ char **l = NULL; +- Swap *s = SWAP(u); ++ + int r; + +- assert(s); ++ + assert(mask != 0); + + if (s->state != SWAP_DEAD) +@@ -1537,18 +1543,18 @@ fail: + } + + static int swap_can_clean(Unit *u, ExecCleanMask *ret) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + +- assert(s); ++ + + return exec_context_get_clean_mask(&s->exec_context, ret); + } + + static int swap_can_start(Unit *u) { +- Swap *s = SWAP(u); ++ Swap *s = ASSERT_PTR(SWAP(u)); + int r; + +- assert(s); ++ + + r = unit_test_start_limit(u); + if (r < 0) { +diff --git a/src/core/target.c b/src/core/target.c +index 8f2a331..b6d9482 100644 +--- a/src/core/target.c ++++ b/src/core/target.c +@@ -70,10 +70,10 @@ static int target_add_default_dependencies(Target *t) { + } + + static int target_load(Unit *u) { +- Target *t = TARGET(u); ++ Target *t = ASSERT_PTR(TARGET(u)); + int r; + +- assert(t); ++ + + r = unit_load_fragment_and_dropin(u, true); + if (r < 0) +@@ -87,9 +87,9 @@ static int target_load(Unit *u) { + } + + static int target_coldplug(Unit *u) { +- Target *t = TARGET(u); ++ Target *t = ASSERT_PTR(TARGET(u)); + +- assert(t); ++ + assert(t->state == TARGET_DEAD); + + if (t->deserialized_state != t->state) +@@ -99,10 +99,11 @@ static int target_coldplug(Unit *u) { + } + + static void target_dump(Unit *u, FILE *f, const char *prefix) { +- Target *t = TARGET(u); ++ Target *t = ASSERT_PTR(TARGET(u)); + +- assert(t); ++ + assert(f); ++ assert(prefix); + + fprintf(f, + "%sTarget State: %s\n", +@@ -110,10 +111,10 @@ static void target_dump(Unit *u, FILE *f, const char *prefix) { + } + + static int target_start(Unit *u) { +- Target *t = TARGET(u); ++ Target *t = ASSERT_PTR(TARGET(u)); + int r; + +- assert(t); ++ + assert(t->state == TARGET_DEAD); + + r = unit_acquire_invocation_id(u); +@@ -125,9 +126,9 @@ static int target_start(Unit *u) { + } + + static int target_stop(Unit *u) { +- Target *t = TARGET(u); ++ Target *t = ASSERT_PTR(TARGET(u)); + +- assert(t); ++ + assert(t->state == TARGET_ACTIVE); + + target_set_state(t, TARGET_DEAD); +@@ -135,21 +136,20 @@ static int target_stop(Unit *u) { + } + + static int target_serialize(Unit *u, FILE *f, FDSet *fds) { +- Target *s = TARGET(u); ++ Target *t = ASSERT_PTR(TARGET(u)); + +- assert(s); ++ + assert(f); + assert(fds); + +- (void) serialize_item(f, "state", target_state_to_string(s->state)); ++ (void) serialize_item(f, "state", target_state_to_string(t->state)); + return 0; + } + + static int target_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Target *s = TARGET(u); ++ Target *t = ASSERT_PTR(TARGET(u)); + +- assert(s); +- assert(u); ++ + assert(key); + assert(value); + assert(fds); +@@ -159,26 +159,26 @@ static int target_deserialize_item(Unit *u, const char *key, const char *value, + + state = target_state_from_string(value); + if (state < 0) +- log_debug("Failed to parse state value %s", value); ++ log_unit_debug(u, "Failed to parse state: %s", value); + else +- s->deserialized_state = state; ++ t->deserialized_state = state; + + } else +- log_debug("Unknown serialization key '%s'", key); ++ log_unit_debug(u, "Unknown serialization key: %s", key); + + return 0; + } + + static UnitActiveState target_active_state(Unit *u) { +- assert(u); ++ Target *t = ASSERT_PTR(TARGET(u)); + +- return state_translation_table[TARGET(u)->state]; ++ return state_translation_table[t->state]; + } + + static const char *target_sub_state_to_string(Unit *u) { +- assert(u); ++ Target *t = ASSERT_PTR(TARGET(u)); + +- return target_state_to_string(TARGET(u)->state); ++ return target_state_to_string(t->state); + } + + const UnitVTable target_vtable = { +diff --git a/src/core/timer.c b/src/core/timer.c +index 3c41a25..0520a11 100644 +--- a/src/core/timer.c ++++ b/src/core/timer.c +@@ -35,9 +35,9 @@ static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = { + static int timer_dispatch(sd_event_source *s, uint64_t usec, void *userdata); + + static void timer_init(Unit *u) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- assert(u); ++ + assert(u->load_state == UNIT_STUB); + + t->next_elapse_monotonic_or_boottime = USEC_INFINITY; +@@ -58,9 +58,9 @@ void timer_free_values(Timer *t) { + } + + static void timer_done(Unit *u) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- assert(t); ++ + + timer_free_values(t); + +@@ -201,10 +201,10 @@ static uint64_t timer_get_fixed_delay_hash(Timer *t) { + } + + static int timer_load(Unit *u) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + int r; + +- assert(u); ++ + assert(u->load_state == UNIT_STUB); + + r = unit_load_fragment_and_dropin(u, true); +@@ -231,9 +231,12 @@ static int timer_load(Unit *u) { + } + + static void timer_dump(Unit *u, FILE *f, const char *prefix) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + Unit *trigger; + ++ assert(f); ++ assert(prefix); ++ + trigger = UNIT_TRIGGER(u); + + fprintf(f, +@@ -303,9 +306,9 @@ static void timer_set_state(Timer *t, TimerState state) { + static void timer_enter_waiting(Timer *t, bool time_change); + + static int timer_coldplug(Unit *u) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- assert(t); ++ + assert(t->state == TIMER_DEAD); + + if (t->deserialized_state == t->state) +@@ -634,10 +637,10 @@ fail: + } + + static int timer_start(Unit *u) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + int r; + +- assert(t); ++ + assert(IN_SET(t->state, TIMER_DEAD, TIMER_FAILED)); + + r = unit_test_trigger_loaded(u); +@@ -682,9 +685,9 @@ static int timer_start(Unit *u) { + } + + static int timer_stop(Unit *u) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- assert(t); ++ + assert(IN_SET(t->state, TIMER_WAITING, TIMER_RUNNING, TIMER_ELAPSED)); + + timer_enter_dead(t, TIMER_SUCCESS); +@@ -692,9 +695,9 @@ static int timer_stop(Unit *u) { + } + + static int timer_serialize(Unit *u, FILE *f, FDSet *fds) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- assert(u); ++ + assert(f); + assert(fds); + +@@ -711,9 +714,9 @@ static int timer_serialize(Unit *u, FILE *f, FDSet *fds) { + } + + static int timer_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- assert(u); ++ + assert(key); + assert(value); + assert(fds); +@@ -747,21 +750,21 @@ static int timer_deserialize_item(Unit *u, const char *key, const char *value, F + } + + static UnitActiveState timer_active_state(Unit *u) { +- assert(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- return state_translation_table[TIMER(u)->state]; ++ return state_translation_table[t->state]; + } + + static const char *timer_sub_state_to_string(Unit *u) { +- assert(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- return timer_state_to_string(TIMER(u)->state); ++ return timer_state_to_string(t->state); + } + + static int timer_dispatch(sd_event_source *s, uint64_t usec, void *userdata) { +- Timer *t = TIMER(userdata); ++ Timer *t = ASSERT_PTR(TIMER(userdata)); + +- assert(t); ++ + + if (t->state != TIMER_WAITING) + return 0; +@@ -772,9 +775,9 @@ 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); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- assert(u); ++ + assert(other); + + /* Filter out invocations with bogus state */ +@@ -812,9 +815,9 @@ static void timer_trigger_notify(Unit *u, Unit *other) { + } + + static void timer_reset_failed(Unit *u) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- assert(t); ++ + + if (t->state == TIMER_FAILED) + timer_set_state(t, TIMER_DEAD); +@@ -823,10 +826,10 @@ static void timer_reset_failed(Unit *u) { + } + + static void timer_time_change(Unit *u) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + usec_t ts; + +- assert(u); ++ + + if (t->state != TIMER_WAITING) + return; +@@ -849,9 +852,9 @@ static void timer_time_change(Unit *u) { + } + + static void timer_timezone_change(Unit *u) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- assert(u); ++ + + if (t->state != TIMER_WAITING) + return; +@@ -866,10 +869,10 @@ static void timer_timezone_change(Unit *u) { + } + + static int timer_clean(Unit *u, ExecCleanMask mask) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + int r; + +- assert(t); ++ + assert(mask != 0); + + if (t->state != TIMER_DEAD) +@@ -892,9 +895,9 @@ static int timer_clean(Unit *u, ExecCleanMask mask) { + } + + static int timer_can_clean(Unit *u, ExecCleanMask *ret) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + +- assert(t); ++ + assert(ret); + + *ret = t->persistent ? EXEC_CLEAN_STATE : 0; +@@ -902,10 +905,10 @@ static int timer_can_clean(Unit *u, ExecCleanMask *ret) { + } + + static int timer_can_start(Unit *u) { +- Timer *t = TIMER(u); ++ Timer *t = ASSERT_PTR(TIMER(u)); + int r; + +- assert(t); ++ + + r = unit_test_start_limit(u); + if (r < 0) { +@@ -917,9 +920,9 @@ static int timer_can_start(Unit *u) { + } + + static void activation_details_timer_serialize(ActivationDetails *details, FILE *f) { +- ActivationDetailsTimer *t = ACTIVATION_DETAILS_TIMER(details); ++ ActivationDetailsTimer *t = ASSERT_PTR(ACTIVATION_DETAILS_TIMER(details)); + +- assert(details); ++ + assert(f); + assert(t); + +@@ -950,10 +953,10 @@ static int activation_details_timer_deserialize(const char *key, const char *val + } + + static int activation_details_timer_append_env(ActivationDetails *details, char ***strv) { +- ActivationDetailsTimer *t = ACTIVATION_DETAILS_TIMER(details); ++ ActivationDetailsTimer *t = ASSERT_PTR(ACTIVATION_DETAILS_TIMER(details)); + int r; + +- assert(details); ++ + assert(strv); + assert(t); + +@@ -972,10 +975,10 @@ static int activation_details_timer_append_env(ActivationDetails *details, char + } + + static int activation_details_timer_append_pair(ActivationDetails *details, char ***strv) { +- ActivationDetailsTimer *t = ACTIVATION_DETAILS_TIMER(details); ++ ActivationDetailsTimer *t = ASSERT_PTR(ACTIVATION_DETAILS_TIMER(details)); + int r; + +- assert(details); ++ + assert(strv); + assert(t); + +-- +2.27.0 + diff --git a/systemd.spec b/systemd.spec index 31d4038d7c0dedf1f87603851b8b4a3d82ac844c..754c8fc9bbe1922ec545669fd7f7054153055825 100644 --- a/systemd.spec +++ b/systemd.spec @@ -25,7 +25,7 @@ Name: systemd Url: https://systemd.io/ Version: 255 -Release: 17 +Release: 18 License: MIT and LGPLv2+ and GPLv2+ Summary: System and Service Manager @@ -121,6 +121,7 @@ Patch9057: add-a-new-switch-to-control-whether-udev-complies-wi.patch Patch9058: journal-don-t-enable-systemd-journald-audit.socket.patch Patch9801: Systemd-Add-sw64-architecture.patch +Patch9802: backport-core-use-ASSERT_PTR-CAST-u-everywhere.patch BuildRequires: gcc, gcc-c++ BuildRequires: libcap-devel, libmount-devel, pam-devel, libselinux-devel @@ -1646,6 +1647,9 @@ fi %{_libdir}/security/pam_systemd_loadkey.so %changelog +* Fri May 24 2024 dufuhang - 255-18 +- core: use ASSERT_PTR(CAST(u)) everywhere + * Tue May 21 2024 dufuhang - 255-17 - main: pass the right error variable