]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/serialization: drop misleadingly-named unit_can_serialize()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 8 Jun 2021 14:30:44 +0000 (16:30 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Jun 2021 12:17:58 +0000 (14:17 +0200)
All unit types can be serialized. This function was really checking whether the
unit type has custom serialization/deserialization code. But we don't need a
function for this.

Also, the check that both .serialize() and .deserialize_item() are defined is
better written as an assert. Not we have a function which would skip
serialization/deserializaton for the unit if we forgot to set either of the
fields.

src/core/unit-serialize.c
src/core/unit.c
src/core/unit.h

index f6305d879a36a6fe07109a68f777b5f7acb94e2d..de71201fdb276158d61f74d21e17113426e0c206 100644 (file)
@@ -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;
@@ -506,7 +508,7 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
                         /* Returns positive if key was handled by the call */
                         continue;
 
-                if (unit_can_serialize(u)) {
+                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);
index de407d20a8825deacd87a6b47d679dc8321688fc..5f4739b32a3beb317e063abd3521b12f1e1669f8 100644 (file)
@@ -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;
index 52feb3693b0c85a1bba287ee85264485c0966710..3b302e7e206e83a4e940b5d9edd4ff8c4e7af326 100644 (file)
@@ -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);