]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: split out property get helpers 16303/head
authorLennart Poettering <lennart@poettering.net>
Sun, 28 Jun 2020 14:43:29 +0000 (16:43 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 30 Jun 2020 13:10:17 +0000 (15:10 +0200)
No code changes, just some refactoring.

34 files changed:
src/core/dbus-automount.c
src/core/dbus-cgroup.c
src/core/dbus-execute.c
src/core/dbus-job.c
src/core/dbus-kill.c
src/core/dbus-manager.c
src/core/dbus-mount.c
src/core/dbus-path.c
src/core/dbus-scope.c
src/core/dbus-service.c
src/core/dbus-socket.c
src/core/dbus-swap.c
src/core/dbus-timer.c
src/core/dbus-unit.c
src/import/importd.c
src/login/logind-dbus.c
src/login/logind-seat-dbus.c
src/login/logind-session-dbus.c
src/login/logind-user-dbus.c
src/machine/image-dbus.c
src/machine/machine-dbus.c
src/machine/machined-dbus.c
src/network/networkd-link-bus.c
src/portable/portabled-image-bus.c
src/resolve/resolved-bus.c
src/resolve/resolved-link-bus.c
src/shared/bus-get-properties.c [new file with mode: 0644]
src/shared/bus-get-properties.h [new file with mode: 0644]
src/shared/bus-log-control-api.c
src/shared/bus-util.c
src/shared/bus-util.h
src/shared/meson.build
src/timedate/timedated.c
src/timesync/timesyncd-bus.c

index bd6e6a9dde15ea73625272f6fe2988f2ac7a9f16..70b85d8023ff0bf0593b7908693d8be8ee3a3d77 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include "automount.h"
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "dbus-automount.h"
 #include "dbus-util.h"
 #include "string-util.h"
index 080f6fb1aed0225f450f750f1bad96a6fa25d47f..b7d2e32639a51699b5df2404c3260e73bb672a9c 100644 (file)
@@ -5,7 +5,7 @@
 #include "af-list.h"
 #include "alloc-util.h"
 #include "bpf-firewall.h"
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "cgroup-util.h"
 #include "cgroup.h"
 #include "dbus-cgroup.h"
index 41d64e8004789c6a358da53d937ec995b07bb2f3..50f7ada8cefb2f32efe790c5698bdcbbc44ff578 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "af-list.h"
 #include "alloc-util.h"
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "cap-list.h"
 #include "capability-util.h"
 #include "cpu-set-util.h"
index 404984f664881d06574dfb4460005b7d9d8cb542..33e4128909bbe2e7721e1808106b8488a44cf90a 100644 (file)
@@ -3,6 +3,7 @@
 #include "sd-bus.h"
 
 #include "alloc-util.h"
+#include "bus-get-properties.h"
 #include "bus-util.h"
 #include "dbus-job.h"
 #include "dbus-unit.h"
index 30597e86f0d1dabb6c2087fb2dfa29deafd8463d..eda3410375a30362a98a83632627a4c0e5b0b791 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "dbus-kill.h"
 #include "dbus-util.h"
 #include "kill.h"
index 5cb06867cb31b75cfb10e05a5cb5267afc2df509..07e139c5ad265680de5bf1a9b1b849b97637e816 100644 (file)
@@ -9,8 +9,8 @@
 #include "architecture.h"
 #include "build.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-log-control-api.h"
-#include "bus-util.h"
 #include "dbus-cgroup.h"
 #include "dbus-execute.h"
 #include "dbus-job.h"
index 3ab5ecc425c1e023cebbea51e82d326c88e44259..bab12cc4ff15fa12242fc144501eab506dd5753c 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "dbus-cgroup.h"
 #include "dbus-execute.h"
 #include "dbus-kill.h"
index 1a97d62486f45f538202a41b3e883a67c5ee4c14..76cd9d32603d4f86db9e61e3d0e454e69078d882 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include "alloc-util.h"
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "dbus-path.h"
 #include "dbus-util.h"
 #include "list.h"
index 2d877a8c55fc630e7312d0917ca3944bb76cdd61..aecfda65356caa2e5f370b308371270bd3d4b156 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "dbus-cgroup.h"
 #include "dbus-kill.h"
 #include "dbus-scope.h"
index 5d4f4ef50684b00b65535f0df5b88123107ae685..3cc453dff5bbc7bb5a69a1b0742b682f95277e56 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "alloc-util.h"
 #include "async.h"
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "dbus-cgroup.h"
 #include "dbus-execute.h"
 #include "dbus-kill.h"
index 73e6a7491470f32a697d5d07377e9310ac8aa288..f01489e29a16258610c5420906b5e13961ac3ddf 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include "alloc-util.h"
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "dbus-cgroup.h"
 #include "dbus-execute.h"
 #include "dbus-kill.h"
index 57c8c42091fd95750df6684acf8c3e473d3f89c3..cb4824b6bd943aa77f77a8655d23f3f2a3008e8d 100644 (file)
@@ -3,7 +3,7 @@
   Copyright © 2010 Maarten Lankhorst
 ***/
 
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "dbus-cgroup.h"
 #include "dbus-execute.h"
 #include "dbus-swap.h"
index 439c276fac90a31bb0132ff5a51330579e3abdf7..da35fa867862ea64d5fc65e61fbda42aa3e8800a 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include "alloc-util.h"
-#include "bus-util.h"
+#include "bus-get-properties.h"
 #include "dbus-timer.h"
 #include "dbus-util.h"
 #include "strv.h"
index 320e830728e1f2acefc4b629381c82bf6ad47bbf..9e9d3b101e50df456991068d4e4ef12db71d29f1 100644 (file)
@@ -5,8 +5,8 @@
 #include "alloc-util.h"
 #include "bpf-firewall.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-polkit.h"
-#include "bus-util.h"
 #include "cgroup-util.h"
 #include "condition.h"
 #include "dbus-job.h"
index d799a10f94b24d3f931ab7ae19ed9e1b0fe7332e..038dd3a6c6187b15c2d5f3337e8ac8bbc9009c2e 100644 (file)
@@ -7,8 +7,8 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-log-control-api.h"
-#include "bus-util.h"
 #include "bus-polkit.h"
 #include "def.h"
 #include "fd-util.h"
@@ -22,8 +22,8 @@
 #include "parse-util.h"
 #include "path-util.h"
 #include "process-util.h"
-#include "signal-util.h"
 #include "service-util.h"
+#include "signal-util.h"
 #include "socket-util.h"
 #include "stat-util.h"
 #include "string-table.h"
index 98e0a6cff7b1df1e495b022004d47e1ca9e295da..1b6304b57f54ef93bb48d7b59327ec34dde65415 100644 (file)
@@ -12,6 +12,7 @@
 #include "bootspec.h"
 #include "bus-common-errors.h"
 #include "bus-error.h"
+#include "bus-get-properties.h"
 #include "bus-locator.h"
 #include "bus-polkit.h"
 #include "bus-unit-util.h"
index e72f265185b03d60f47a07040bf9d05d1a02b953..a91765205c83ab47a6ba41e2f9db10939df18205 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-label.h"
 #include "bus-polkit.h"
 #include "bus-util.h"
index 3857f4ab7d45120c0815235c32803f199be9680b..5ed20ebd26cd14f675fd371ed585f5fa22496215 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-label.h"
 #include "bus-polkit.h"
 #include "bus-util.h"
index 63c77cab396f426fe1a5d5b01c34afa77e902246..237723729e38c17bd0c240ec1027f6765f537c2d 100644 (file)
@@ -3,6 +3,7 @@
 #include <errno.h>
 
 #include "alloc-util.h"
+#include "bus-get-properties.h"
 #include "bus-polkit.h"
 #include "bus-util.h"
 #include "format-util.h"
index 4305f4915224ac4f4910bcf6bbad4dfc1c571f83..7a15bcc49a44942fa38e73eda43ddba887376f52 100644 (file)
@@ -4,9 +4,9 @@
 #include <sys/mount.h>
 
 #include "alloc-util.h"
+#include "bus-get-properties.h"
 #include "bus-label.h"
 #include "bus-polkit.h"
-#include "bus-util.h"
 #include "copy.h"
 #include "dissect-image.h"
 #include "fd-util.h"
index a8f9d28a8708fc08a31e9b2b311f1717a3e2af6f..73ef5949bf366f6e5ad4ed10120ac4afb251f809 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-internal.h"
 #include "bus-label.h"
 #include "bus-locator.h"
index 9fb843359234a3b3eb0c7b434502fc9e7975791d..2d9c180aa433c353b8a85f55459bf95d5f1517aa 100644 (file)
@@ -8,6 +8,7 @@
 #include "alloc-util.h"
 #include "btrfs-util.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-locator.h"
 #include "bus-polkit.h"
 #include "cgroup-util.h"
index 76daee69e84c98f7da511d3c713a88cea6948334..38b005fb63c9a9f80ba912bd75fa0f8fd3b02aec 100644 (file)
@@ -6,8 +6,8 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-polkit.h"
-#include "bus-util.h"
 #include "dns-domain.h"
 #include "networkd-link-bus.h"
 #include "networkd-link.h"
index 5988a21037468c4e106e7fc1a977f7cabdc883a8..9646601491ed43026d4968b5361babb30d6c9564 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-label.h"
 #include "bus-polkit.h"
 #include "bus-util.h"
index 38d2483c24f54ea3726d97296c6a6ff0abca6e5c..2ecfcf498b07ac3e6ca7c8295e99928d597e3ec3 100644 (file)
@@ -2,9 +2,9 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-log-control-api.h"
 #include "bus-polkit.h"
-#include "bus-util.h"
 #include "dns-domain.h"
 #include "memory-util.h"
 #include "missing_capability.h"
index a2ca5cb8f608dd881a0db5f5ece40e7f3b1fab18..0fa62208c30a2e2c71f556e6244ff337ece21b2e 100644 (file)
@@ -6,8 +6,8 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-polkit.h"
-#include "bus-util.h"
 #include "parse-util.h"
 #include "resolve-util.h"
 #include "resolved-bus.h"
diff --git a/src/shared/bus-get-properties.c b/src/shared/bus-get-properties.c
new file mode 100644 (file)
index 0000000..8ad4694
--- /dev/null
@@ -0,0 +1,149 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "bus-get-properties.h"
+#include "rlimit-util.h"
+#include "string-util.h"
+
+int bus_property_get_bool(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        int b = *(bool*) userdata;
+
+        return sd_bus_message_append_basic(reply, 'b', &b);
+}
+
+int bus_property_set_bool(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *value,
+                void *userdata,
+                sd_bus_error *error) {
+
+        int b, r;
+
+        r = sd_bus_message_read(value, "b", &b);
+        if (r < 0)
+                return r;
+
+        *(bool*) userdata = b;
+        return 0;
+}
+
+int bus_property_get_id128(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        sd_id128_t *id = userdata;
+
+        if (sd_id128_is_null(*id)) /* Add an empty array if the ID is zero */
+                return sd_bus_message_append(reply, "ay", 0);
+        else
+                return sd_bus_message_append_array(reply, 'y', id->bytes, 16);
+}
+
+#if __SIZEOF_SIZE_T__ != 8
+int bus_property_get_size(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        uint64_t sz = *(size_t*) userdata;
+
+        return sd_bus_message_append_basic(reply, 't', &sz);
+}
+#endif
+
+#if __SIZEOF_LONG__ != 8
+int bus_property_get_long(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        int64_t l = *(long*) userdata;
+
+        return sd_bus_message_append_basic(reply, 'x', &l);
+}
+
+int bus_property_get_ulong(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        uint64_t ul = *(unsigned long*) userdata;
+
+        return sd_bus_message_append_basic(reply, 't', &ul);
+}
+#endif
+
+int bus_property_get_rlimit(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        const char *is_soft;
+        struct rlimit *rl;
+        uint64_t u;
+        rlim_t x;
+
+        assert(bus);
+        assert(reply);
+        assert(userdata);
+
+        is_soft = endswith(property, "Soft");
+
+        rl = *(struct rlimit**) userdata;
+        if (rl)
+                x = is_soft ? rl->rlim_cur : rl->rlim_max;
+        else {
+                struct rlimit buf = {};
+                const char *s, *p;
+                int z;
+
+                /* Chop off "Soft" suffix */
+                s = is_soft ? strndupa(property, is_soft - property) : property;
+
+                /* Skip over any prefix, such as "Default" */
+                assert_se(p = strstr(s, "Limit"));
+
+                z = rlimit_from_string(p + 5);
+                assert(z >= 0);
+
+                (void) getrlimit(z, &buf);
+                x = is_soft ? buf.rlim_cur : buf.rlim_max;
+        }
+
+        /* rlim_t might have different sizes, let's map RLIMIT_INFINITY to (uint64_t) -1, so that it is the same on all
+         * archs */
+        u = x == RLIM_INFINITY ? (uint64_t) -1 : (uint64_t) x;
+
+        return sd_bus_message_append(reply, "t", u);
+}
diff --git a/src/shared/bus-get-properties.h b/src/shared/bus-get-properties.h
new file mode 100644 (file)
index 0000000..d853b79
--- /dev/null
@@ -0,0 +1,103 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+#include "sd-bus.h"
+
+#include "sd-bus.h"
+
+#include "macro.h"
+
+int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
+int bus_property_set_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *error);
+int bus_property_get_id128(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
+
+#define bus_property_get_usec ((sd_bus_property_get_t) NULL)
+#define bus_property_set_usec ((sd_bus_property_set_t) NULL)
+
+assert_cc(sizeof(int) == sizeof(int32_t));
+#define bus_property_get_int ((sd_bus_property_get_t) NULL)
+
+assert_cc(sizeof(unsigned) == sizeof(uint32_t));
+#define bus_property_get_unsigned ((sd_bus_property_get_t) NULL)
+
+/* On 64bit machines we can use the default serializer for size_t and
+ * friends, otherwise we need to cast this manually */
+#if __SIZEOF_SIZE_T__ == 8
+#define bus_property_get_size ((sd_bus_property_get_t) NULL)
+#else
+int bus_property_get_size(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
+#endif
+
+#if __SIZEOF_LONG__ == 8
+#define bus_property_get_long ((sd_bus_property_get_t) NULL)
+#define bus_property_get_ulong ((sd_bus_property_get_t) NULL)
+#else
+int bus_property_get_long(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
+int bus_property_get_ulong(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
+#endif
+
+/* uid_t and friends on Linux 32 bit. This means we can just use the
+ * default serializer for 32bit unsigned, for serializing it, and map
+ * it to NULL here */
+assert_cc(sizeof(uid_t) == sizeof(uint32_t));
+#define bus_property_get_uid ((sd_bus_property_get_t) NULL)
+
+assert_cc(sizeof(gid_t) == sizeof(uint32_t));
+#define bus_property_get_gid ((sd_bus_property_get_t) NULL)
+
+assert_cc(sizeof(pid_t) == sizeof(uint32_t));
+#define bus_property_get_pid ((sd_bus_property_get_t) NULL)
+
+assert_cc(sizeof(mode_t) == sizeof(uint32_t));
+#define bus_property_get_mode ((sd_bus_property_get_t) NULL)
+
+int bus_property_get_rlimit(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
+
+#define BUS_DEFINE_PROPERTY_GET_GLOBAL(function, bus_type, val)         \
+        int function(sd_bus *bus,                                       \
+                     const char *path,                                  \
+                     const char *interface,                             \
+                     const char *property,                              \
+                     sd_bus_message *reply,                             \
+                     void *userdata,                                    \
+                     sd_bus_error *error) {                             \
+                                                                        \
+                assert(bus);                                            \
+                assert(reply);                                          \
+                                                                        \
+                return sd_bus_message_append(reply, bus_type, val);     \
+        }
+
+#define BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, get2) \
+        int function(sd_bus *bus,                                       \
+                     const char *path,                                  \
+                     const char *interface,                             \
+                     const char *property,                              \
+                     sd_bus_message *reply,                             \
+                     void *userdata,                                    \
+                     sd_bus_error *error) {                             \
+                                                                        \
+                data_type *data = userdata;                             \
+                                                                        \
+                assert(bus);                                            \
+                assert(reply);                                          \
+                assert(data);                                           \
+                                                                        \
+                return sd_bus_message_append(reply, bus_type,           \
+                                             get2(get1(data)));         \
+        }
+
+#define ident(x) (x)
+#define BUS_DEFINE_PROPERTY_GET(function, bus_type, data_type, get1) \
+        BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, ident)
+
+#define ref(x) (*(x))
+#define BUS_DEFINE_PROPERTY_GET_REF(function, bus_type, data_type, get) \
+        BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, ref, get)
+
+#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type)              \
+        BUS_DEFINE_PROPERTY_GET_REF(function, "s", type, name##_to_string)
+
+#define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \
+        SD_BUS_PROPERTY(name, "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, realtime), (flags)), \
+        SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, monotonic), (flags))
index a1d0d1729151d8a9ef72330dc8d049014f0c93c4..7c487ada9fadb1d5f7513f87de9a379e54444d74 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include "alloc-util.h"
+#include "bus-get-properties.h"
 #include "bus-log-control-api.h"
 #include "bus-util.h"
 #include "log.h"
index 85b5bedbc09d69e20aca9a1c383f5de5fa4af602..77c1c6218272bbfb89b45364822d1bb90fff83b5 100644 (file)
 #include "sd-event.h"
 #include "sd-id128.h"
 
-#include "alloc-util.h"
+/* #include "alloc-util.h" */
 #include "bus-internal.h"
 #include "bus-label.h"
 #include "bus-util.h"
 #include "path-util.h"
-#include "rlimit-util.h"
 #include "socket-util.h"
 #include "stdio-util.h"
-#include "string-util.h"
+/* #include "string-util.h" */
 
 static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
         sd_event *e = userdata;
@@ -333,102 +332,6 @@ int bus_connect_transport_systemd(BusTransport transport, const char *host, bool
         return r;
 }
 
-int bus_property_get_bool(
-                sd_bus *bus,
-                const char *path,
-                const char *interface,
-                const char *property,
-                sd_bus_message *reply,
-                void *userdata,
-                sd_bus_error *error) {
-
-        int b = *(bool*) userdata;
-
-        return sd_bus_message_append_basic(reply, 'b', &b);
-}
-
-int bus_property_set_bool(
-                sd_bus *bus,
-                const char *path,
-                const char *interface,
-                const char *property,
-                sd_bus_message *value,
-                void *userdata,
-                sd_bus_error *error) {
-
-        int b, r;
-
-        r = sd_bus_message_read(value, "b", &b);
-        if (r < 0)
-                return r;
-
-        *(bool*) userdata = b;
-        return 0;
-}
-
-int bus_property_get_id128(
-                sd_bus *bus,
-                const char *path,
-                const char *interface,
-                const char *property,
-                sd_bus_message *reply,
-                void *userdata,
-                sd_bus_error *error) {
-
-        sd_id128_t *id = userdata;
-
-        if (sd_id128_is_null(*id)) /* Add an empty array if the ID is zero */
-                return sd_bus_message_append(reply, "ay", 0);
-        else
-                return sd_bus_message_append_array(reply, 'y', id->bytes, 16);
-}
-
-#if __SIZEOF_SIZE_T__ != 8
-int bus_property_get_size(
-                sd_bus *bus,
-                const char *path,
-                const char *interface,
-                const char *property,
-                sd_bus_message *reply,
-                void *userdata,
-                sd_bus_error *error) {
-
-        uint64_t sz = *(size_t*) userdata;
-
-        return sd_bus_message_append_basic(reply, 't', &sz);
-}
-#endif
-
-#if __SIZEOF_LONG__ != 8
-int bus_property_get_long(
-                sd_bus *bus,
-                const char *path,
-                const char *interface,
-                const char *property,
-                sd_bus_message *reply,
-                void *userdata,
-                sd_bus_error *error) {
-
-        int64_t l = *(long*) userdata;
-
-        return sd_bus_message_append_basic(reply, 'x', &l);
-}
-
-int bus_property_get_ulong(
-                sd_bus *bus,
-                const char *path,
-                const char *interface,
-                const char *property,
-                sd_bus_message *reply,
-                void *userdata,
-                sd_bus_error *error) {
-
-        uint64_t ul = *(unsigned long*) userdata;
-
-        return sd_bus_message_append_basic(reply, 't', &ul);
-}
-#endif
-
 /**
  * bus_path_encode_unique() - encode unique object path
  * @b: bus connection or NULL
@@ -556,54 +459,6 @@ int bus_path_decode_unique(const char *path, const char *prefix, char **ret_send
         return 1;
 }
 
-int bus_property_get_rlimit(
-                sd_bus *bus,
-                const char *path,
-                const char *interface,
-                const char *property,
-                sd_bus_message *reply,
-                void *userdata,
-                sd_bus_error *error) {
-
-        const char *is_soft;
-        struct rlimit *rl;
-        uint64_t u;
-        rlim_t x;
-
-        assert(bus);
-        assert(reply);
-        assert(userdata);
-
-        is_soft = endswith(property, "Soft");
-
-        rl = *(struct rlimit**) userdata;
-        if (rl)
-                x = is_soft ? rl->rlim_cur : rl->rlim_max;
-        else {
-                struct rlimit buf = {};
-                const char *s, *p;
-                int z;
-
-                /* Chop off "Soft" suffix */
-                s = is_soft ? strndupa(property, is_soft - property) : property;
-
-                /* Skip over any prefix, such as "Default" */
-                assert_se(p = strstr(s, "Limit"));
-
-                z = rlimit_from_string(p + 5);
-                assert(z >= 0);
-
-                (void) getrlimit(z, &buf);
-                x = is_soft ? buf.rlim_cur : buf.rlim_max;
-        }
-
-        /* rlim_t might have different sizes, let's map RLIMIT_INFINITY to (uint64_t) -1, so that it is the same on all
-         * archs */
-        u = x == RLIM_INFINITY ? (uint64_t) -1 : (uint64_t) x;
-
-        return sd_bus_message_append(reply, "t", u);
-}
-
 int bus_track_add_name_many(sd_bus_track *t, char **l) {
         int r = 0;
         char **i;
index 4dbf74fdf751deda55850d19e8a113b589883caf..fd88314c1f44634b4398d51866e4710cb87b4684 100644 (file)
@@ -37,110 +37,15 @@ int bus_connect_user_systemd(sd_bus **_bus);
 int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
 int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
 
-int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
-int bus_property_set_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *error);
-int bus_property_get_id128(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
-
-#define bus_property_get_usec ((sd_bus_property_get_t) NULL)
-#define bus_property_set_usec ((sd_bus_property_set_t) NULL)
-
-assert_cc(sizeof(int) == sizeof(int32_t));
-#define bus_property_get_int ((sd_bus_property_get_t) NULL)
-
-assert_cc(sizeof(unsigned) == sizeof(uint32_t));
-#define bus_property_get_unsigned ((sd_bus_property_get_t) NULL)
-
-/* On 64bit machines we can use the default serializer for size_t and
- * friends, otherwise we need to cast this manually */
-#if __SIZEOF_SIZE_T__ == 8
-#define bus_property_get_size ((sd_bus_property_get_t) NULL)
-#else
-int bus_property_get_size(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
-#endif
-
-#if __SIZEOF_LONG__ == 8
-#define bus_property_get_long ((sd_bus_property_get_t) NULL)
-#define bus_property_get_ulong ((sd_bus_property_get_t) NULL)
-#else
-int bus_property_get_long(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
-int bus_property_get_ulong(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
-#endif
-
-/* uid_t and friends on Linux 32 bit. This means we can just use the
- * default serializer for 32bit unsigned, for serializing it, and map
- * it to NULL here */
-assert_cc(sizeof(uid_t) == sizeof(uint32_t));
-#define bus_property_get_uid ((sd_bus_property_get_t) NULL)
-
-assert_cc(sizeof(gid_t) == sizeof(uint32_t));
-#define bus_property_get_gid ((sd_bus_property_get_t) NULL)
-
-assert_cc(sizeof(pid_t) == sizeof(uint32_t));
-#define bus_property_get_pid ((sd_bus_property_get_t) NULL)
-
-assert_cc(sizeof(mode_t) == sizeof(uint32_t));
-#define bus_property_get_mode ((sd_bus_property_get_t) NULL)
-
 #define bus_log_parse_error(r) \
         log_error_errno(r, "Failed to parse bus message: %m")
 
 #define bus_log_create_error(r) \
         log_error_errno(r, "Failed to create bus message: %m")
 
-#define BUS_DEFINE_PROPERTY_GET_GLOBAL(function, bus_type, val)         \
-        int function(sd_bus *bus,                                       \
-                     const char *path,                                  \
-                     const char *interface,                             \
-                     const char *property,                              \
-                     sd_bus_message *reply,                             \
-                     void *userdata,                                    \
-                     sd_bus_error *error) {                             \
-                                                                        \
-                assert(bus);                                            \
-                assert(reply);                                          \
-                                                                        \
-                return sd_bus_message_append(reply, bus_type, val);     \
-        }
-
-#define BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, get2) \
-        int function(sd_bus *bus,                                       \
-                     const char *path,                                  \
-                     const char *interface,                             \
-                     const char *property,                              \
-                     sd_bus_message *reply,                             \
-                     void *userdata,                                    \
-                     sd_bus_error *error) {                             \
-                                                                        \
-                data_type *data = userdata;                             \
-                                                                        \
-                assert(bus);                                            \
-                assert(reply);                                          \
-                assert(data);                                           \
-                                                                        \
-                return sd_bus_message_append(reply, bus_type,           \
-                                             get2(get1(data)));         \
-        }
-
-#define ident(x) (x)
-#define BUS_DEFINE_PROPERTY_GET(function, bus_type, data_type, get1) \
-        BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, ident)
-
-#define ref(x) (*(x))
-#define BUS_DEFINE_PROPERTY_GET_REF(function, bus_type, data_type, get) \
-        BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, ref, get)
-
-#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type)              \
-        BUS_DEFINE_PROPERTY_GET_REF(function, "s", type, name##_to_string)
-
-#define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \
-        SD_BUS_PROPERTY(name, "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, realtime), (flags)), \
-        SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, monotonic), (flags))
-
 int bus_path_encode_unique(sd_bus *b, const char *prefix, const char *sender_id, const char *external_id, char **ret_path);
 int bus_path_decode_unique(const char *path, const char *prefix, char **ret_sender, char **ret_external);
 
-int bus_property_get_rlimit(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
-
 int bus_track_add_name_many(sd_bus_track *t, char **l);
 
 int bus_open_system_watch_bind_with_description(sd_bus **ret, const char *description);
index 3bd680295cb8dc71643eef04f0fef9e447c920bf..1868e8aede9bd6656d02c1fc50db7844f02ecfe3 100644 (file)
@@ -27,6 +27,8 @@ shared_sources = files('''
         bpf-program.h
         bridge-util.c
         bridge-util.h
+        bus-get-properties.c
+        bus-get-properties.h
         bus-locator.c
         bus-locator.h
         bus-log-control-api.c
index d7d930571105c3920410742c66fcdb0c6aef874a..c467b854775aa9be022c00aeb0ef13ffc456aac5 100644 (file)
@@ -12,6 +12,7 @@
 #include "alloc-util.h"
 #include "bus-common-errors.h"
 #include "bus-error.h"
+#include "bus-get-properties.h"
 #include "bus-locator.h"
 #include "bus-log-control-api.h"
 #include "bus-map-properties.h"
index 006800709db9ba10ea8c229c0f91b7f8bf9613ce..6effdfc3250fb76aaeae50b525b370643970e236 100644 (file)
@@ -3,6 +3,7 @@
 #include "sd-bus.h"
 
 #include "alloc-util.h"
+#include "bus-get-properties.h"
 #include "bus-internal.h"
 #include "bus-log-control-api.h"
 #include "bus-protocol.h"