]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/bus-get-properties.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include "bus-get-properties.h"
4 #include "rlimit-util.h"
5 #include "string-util.h"
7 int bus_property_get_bool(
10 const char *interface
,
12 sd_bus_message
*reply
,
14 sd_bus_error
*error
) {
16 int b
= *(bool*) userdata
;
18 return sd_bus_message_append_basic(reply
, 'b', &b
);
21 int bus_property_set_bool(
24 const char *interface
,
26 sd_bus_message
*value
,
28 sd_bus_error
*error
) {
32 r
= sd_bus_message_read(value
, "b", &b
);
36 *(bool*) userdata
= b
;
40 int bus_property_get_id128(
43 const char *interface
,
45 sd_bus_message
*reply
,
47 sd_bus_error
*error
) {
49 sd_id128_t
*id
= userdata
;
51 if (sd_id128_is_null(*id
)) /* Add an empty array if the ID is zero */
52 return sd_bus_message_append(reply
, "ay", 0);
54 return sd_bus_message_append_array(reply
, 'y', id
->bytes
, 16);
57 #if __SIZEOF_SIZE_T__ != 8
58 int bus_property_get_size(
61 const char *interface
,
63 sd_bus_message
*reply
,
65 sd_bus_error
*error
) {
67 uint64_t sz
= *(size_t*) userdata
;
69 return sd_bus_message_append_basic(reply
, 't', &sz
);
73 #if __SIZEOF_LONG__ != 8
74 int bus_property_get_long(
77 const char *interface
,
79 sd_bus_message
*reply
,
81 sd_bus_error
*error
) {
83 int64_t l
= *(long*) userdata
;
85 return sd_bus_message_append_basic(reply
, 'x', &l
);
88 int bus_property_get_ulong(
91 const char *interface
,
93 sd_bus_message
*reply
,
95 sd_bus_error
*error
) {
97 uint64_t ul
= *(unsigned long*) userdata
;
99 return sd_bus_message_append_basic(reply
, 't', &ul
);
103 int bus_property_get_rlimit(
106 const char *interface
,
107 const char *property
,
108 sd_bus_message
*reply
,
110 sd_bus_error
*error
) {
121 is_soft
= endswith(property
, "Soft");
123 rl
= *(struct rlimit
**) userdata
;
125 x
= is_soft
? rl
->rlim_cur
: rl
->rlim_max
;
127 struct rlimit buf
= {};
131 /* Chop off "Soft" suffix */
132 s
= is_soft
? strndupa(property
, is_soft
- property
) : property
;
134 /* Skip over any prefix, such as "Default" */
135 assert_se(p
= strstr(s
, "Limit"));
137 z
= rlimit_from_string(p
+ 5);
140 (void) getrlimit(z
, &buf
);
141 x
= is_soft
? buf
.rlim_cur
: buf
.rlim_max
;
144 /* rlim_t might have different sizes, let's map RLIMIT_INFINITY to (uint64_t) -1, so that it is the same on all
146 u
= x
== RLIM_INFINITY
? (uint64_t) -1 : (uint64_t) x
;
148 return sd_bus_message_append(reply
, "t", u
);