diff --git a/src/core/execute.c b/src/core/execute.c index 5c30d0bcbe..5c958b327b 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -6371,38 +6371,24 @@ int exec_runtime_deserialize_compat(Unit *u, const char *key, const char *value, return 0; } - r = hashmap_ensure_allocated(&u->manager->exec_runtime_by_id, &string_hash_ops); - if (r < 0) { - log_unit_debug_errno(u, r, "Failed to allocate storage for runtime parameter: %m"); - return 0; - } + if (hashmap_ensure_allocated(&u->manager->exec_runtime_by_id, &string_hash_ops) < 0) + return log_oom(); rt = hashmap_get(u->manager->exec_runtime_by_id, u->id); if (!rt) { - r = exec_runtime_allocate(&rt_create, u->id); - if (r < 0) + if (exec_runtime_allocate(&rt_create, u->id) < 0) return log_oom(); rt = rt_create; } if (streq(key, "tmp-dir")) { - char *copy; - - copy = strdup(value); - if (!copy) - return log_oom(); - - free_and_replace(rt->tmp_dir, copy); + if (free_and_strdup_warn(&rt->tmp_dir, value) < 0) + return -ENOMEM; } else if (streq(key, "var-tmp-dir")) { - char *copy; - - copy = strdup(value); - if (!copy) - return log_oom(); - - free_and_replace(rt->var_tmp_dir, copy); + if (free_and_strdup_warn(&rt->var_tmp_dir, value) < 0) + return -ENOMEM; } else if (streq(key, "netns-socket-0")) { int fd; @@ -6426,27 +6412,6 @@ int exec_runtime_deserialize_compat(Unit *u, const char *key, const char *value, safe_close(rt->netns_storage_socket[1]); rt->netns_storage_socket[1] = fdset_remove(fds, fd); - } else if (streq(key, "ipcns-socket-0")) { - int fd; - - if (safe_atoi(value, &fd) < 0 || !fdset_contains(fds, fd)) { - log_unit_debug(u, "Failed to parse ipcns socket value: %s", value); - return 0; - } - - safe_close(rt->ipcns_storage_socket[0]); - rt->ipcns_storage_socket[0] = fdset_remove(fds, fd); - - } else if (streq(key, "ipcns-socket-1")) { - int fd; - - if (safe_atoi(value, &fd) < 0 || !fdset_contains(fds, fd)) { - log_unit_debug(u, "Failed to parse ipcns socket value: %s", value); - return 0; - } - - safe_close(rt->ipcns_storage_socket[1]); - rt->ipcns_storage_socket[1] = fdset_remove(fds, fd); } else return 0; diff --git a/src/core/unit-serialize.c b/src/core/unit-serialize.c index daf7c59cc1..de71201fdb 100644 --- a/src/core/unit-serialize.c +++ b/src/core/unit-serialize.c @@ -108,7 +108,9 @@ int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool switching_root) { fputs(u->id, f); fputc('\n', f); - if (unit_can_serialize(u)) { + assert(!!UNIT_VTABLE(u)->serialize == !!UNIT_VTABLE(u)->deserialize_item); + + if (UNIT_VTABLE(u)->serialize) { r = UNIT_VTABLE(u)->serialize(u, f, fds); if (r < 0) return r; @@ -498,17 +500,15 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) { continue; } - if (unit_can_serialize(u)) { - r = exec_runtime_deserialize_compat(u, l, v, fds); - if (r < 0) { - log_unit_warning(u, "Failed to deserialize runtime parameter '%s', ignoring.", l); - continue; - } - + r = exec_runtime_deserialize_compat(u, l, v, fds); + if (r < 0) { + log_unit_warning(u, "Failed to deserialize runtime parameter '%s', ignoring.", l); + continue; + } else if (r > 0) /* Returns positive if key was handled by the call */ - if (r > 0) - continue; + continue; + if (UNIT_VTABLE(u)->deserialize_item) { r = UNIT_VTABLE(u)->deserialize_item(u, l, v, fds); if (r < 0) log_unit_warning(u, "Failed to deserialize unit parameter '%s', ignoring.", l); diff --git a/src/core/unit.c b/src/core/unit.c index de407d20a8..5f4739b32a 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -3488,12 +3488,6 @@ void unit_unwatch_bus_name(Unit *u, const char *name) { u->get_name_owner_slot = sd_bus_slot_unref(u->get_name_owner_slot); } -bool unit_can_serialize(Unit *u) { - assert(u); - - return UNIT_VTABLE(u)->serialize && UNIT_VTABLE(u)->deserialize_item; -} - int unit_add_node_dependency(Unit *u, const char *what, UnitDependency dep, UnitDependencyMask mask) { _cleanup_free_ char *e = NULL; Unit *device; diff --git a/src/core/unit.h b/src/core/unit.h index 52feb3693b..3b302e7e20 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -814,8 +814,6 @@ char *unit_dbus_path_invocation_id(Unit *u); int unit_load_related_unit(Unit *u, const char *type, Unit **_found); -bool unit_can_serialize(Unit *u) _pure_; - int unit_add_node_dependency(Unit *u, const char *what, UnitDependency d, UnitDependencyMask mask); int unit_add_blockdev_dependency(Unit *u, const char *what, UnitDependencyMask mask);