Skip to content

Commit

Permalink
Merge pull request systemd#19864 from keszybz/serialization-cleanup
Browse files Browse the repository at this point in the history
Serialization cleanup
  • Loading branch information
bluca committed Jun 10, 2021
2 parents 9dfb429 + ab18976 commit 390a22f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 60 deletions.
49 changes: 7 additions & 42 deletions src/core/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
20 changes: 10 additions & 10 deletions src/core/unit-serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions src/core/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/core/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 390a22f

Please sign in to comment.