]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/bus-get-properties.c
a5ce7ef17f0185b3803b6f3ebed30b702a72608c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "bus-get-properties.h"
4 #include "rlimit-util.h"
5 #include "stdio-util.h"
6 #include "string-util.h"
8 int bus_property_get_bool(
11 const char *interface
,
13 sd_bus_message
*reply
,
15 sd_bus_error
*error
) {
17 int b
= *(bool*) userdata
;
19 return sd_bus_message_append_basic(reply
, 'b', &b
);
22 int bus_property_set_bool(
25 const char *interface
,
27 sd_bus_message
*value
,
29 sd_bus_error
*error
) {
33 r
= sd_bus_message_read(value
, "b", &b
);
37 *(bool*) userdata
= b
;
41 int bus_property_get_id128(
44 const char *interface
,
46 sd_bus_message
*reply
,
48 sd_bus_error
*error
) {
50 sd_id128_t
*id
= userdata
;
52 if (sd_id128_is_null(*id
)) /* Add an empty array if the ID is zero */
53 return sd_bus_message_append(reply
, "ay", 0);
55 return sd_bus_message_append_array(reply
, 'y', id
->bytes
, 16);
58 #if __SIZEOF_SIZE_T__ != 8
59 int bus_property_get_size(
62 const char *interface
,
64 sd_bus_message
*reply
,
66 sd_bus_error
*error
) {
68 uint64_t sz
= *(size_t*) userdata
;
70 return sd_bus_message_append_basic(reply
, 't', &sz
);
74 #if __SIZEOF_LONG__ != 8
75 int bus_property_get_long(
78 const char *interface
,
80 sd_bus_message
*reply
,
82 sd_bus_error
*error
) {
84 int64_t l
= *(long*) userdata
;
86 return sd_bus_message_append_basic(reply
, 'x', &l
);
89 int bus_property_get_ulong(
92 const char *interface
,
94 sd_bus_message
*reply
,
96 sd_bus_error
*error
) {
98 uint64_t ul
= *(unsigned long*) userdata
;
100 return sd_bus_message_append_basic(reply
, 't', &ul
);
104 int bus_property_get_rlimit(
107 const char *interface
,
108 const char *property
,
109 sd_bus_message
*reply
,
111 sd_bus_error
*error
) {
122 is_soft
= endswith(property
, "Soft");
124 rl
= *(struct rlimit
**) userdata
;
126 x
= is_soft
? rl
->rlim_cur
: rl
->rlim_max
;
128 struct rlimit buf
= {};
132 /* Chop off "Soft" suffix */
133 s
= is_soft
? strndupa(property
, is_soft
- property
) : property
;
135 /* Skip over any prefix, such as "Default" */
136 assert_se(p
= strstr(s
, "Limit"));
138 z
= rlimit_from_string(p
+ 5);
141 (void) getrlimit(z
, &buf
);
142 x
= is_soft
? buf
.rlim_cur
: buf
.rlim_max
;
145 /* rlim_t might have different sizes, let's map RLIMIT_INFINITY to (uint64_t) -1, so that it is the same on all
147 u
= x
== RLIM_INFINITY
? (uint64_t) -1 : (uint64_t) x
;
149 return sd_bus_message_append(reply
, "t", u
);