]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/dbus-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2010 Lennart Poettering
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 #define BUS_DEFINE_SET_TRANSIENT(function, bus_type, type, cast_type, fmt) \
27 int bus_set_transient_##function( \
31 sd_bus_message *message, \
32 UnitWriteFlags flags, \
33 sd_bus_error *error) { \
40 r = sd_bus_message_read(message, bus_type, &v); \
44 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
46 unit_write_settingf(u, flags, name, \
47 "%s=" fmt, name, v); \
53 #define BUS_DEFINE_SET_TRANSIENT_IS_VALID(function, bus_type, type, cast_type, fmt, check) \
54 int bus_set_transient_##function( \
58 sd_bus_message *message, \
59 UnitWriteFlags flags, \
60 sd_bus_error *error) { \
67 r = sd_bus_message_read(message, bus_type, &v); \
72 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
73 "Invalid %s setting: " fmt, name, v); \
75 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
77 unit_write_settingf(u, flags, name, \
78 "%s=" fmt, name, v); \
84 #define BUS_DEFINE_SET_TRANSIENT_TO_STRING(function, bus_type, type, cast_type, fmt, to_string) \
85 int bus_set_transient_##function( \
89 sd_bus_message *message, \
90 UnitWriteFlags flags, \
91 sd_bus_error *error) { \
99 r = sd_bus_message_read(message, bus_type, &v); \
105 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
106 "Invalid %s setting: " fmt, name, v); \
108 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
109 *p = (cast_type) v; \
110 unit_write_settingf(u, flags, name, \
117 #define BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(function, bus_type, type, cast_type, fmt, to_string) \
118 int bus_set_transient_##function( \
122 sd_bus_message *message, \
123 UnitWriteFlags flags, \
124 sd_bus_error *error) { \
126 _cleanup_free_ char *s = NULL; \
132 r = sd_bus_message_read(message, bus_type, &v); \
136 r = to_string(v, &s); \
138 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
139 "Invalid %s setting: " fmt, name, v); \
143 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
144 *p = (cast_type) v; \
145 unit_write_settingf(u, flags, name, \
152 #define BUS_DEFINE_SET_TRANSIENT_PARSE(function, type, parse) \
153 int bus_set_transient_##function( \
157 sd_bus_message *message, \
158 UnitWriteFlags flags, \
159 sd_bus_error *error) { \
167 r = sd_bus_message_read(message, "s", &s); \
173 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
174 "Invalid %s setting: %s", name, s); \
176 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
178 unit_write_settingf(u, flags, name, \
185 #define BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(function, type, parse) \
186 int bus_set_transient_##function( \
190 sd_bus_message *message, \
191 UnitWriteFlags flags, \
192 sd_bus_error *error) { \
200 r = sd_bus_message_read(message, "s", &s); \
206 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
207 "Invalid %s setting: %s", name, s); \
209 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
211 unit_write_settingf(u, flags, name, \
212 "%s=%s", name, strempty(s)); \
218 #define BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(function, check) \
219 int bus_set_transient_##function( \
223 sd_bus_message *message, \
224 UnitWriteFlags flags, \
225 sd_bus_error *error) { \
232 r = sd_bus_message_read(message, "s", &v); \
236 if (!isempty(v) && !check(v)) \
237 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
238 "Invalid %s setting: %s", name, v); \
240 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
241 r = free_and_strdup(p, empty_to_null(v)); \
245 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, \
246 "%s=%s", name, strempty(v)); \
252 int bus_set_transient_mode_t(Unit
*u
, const char *name
, mode_t
*p
, sd_bus_message
*message
, UnitWriteFlags flags
, sd_bus_error
*error
);
253 int bus_set_transient_unsigned(Unit
*u
, const char *name
, unsigned *p
, sd_bus_message
*message
, UnitWriteFlags flags
, sd_bus_error
*error
);
254 int bus_set_transient_user(Unit
*u
, const char *name
, char **p
, sd_bus_message
*message
, UnitWriteFlags flags
, sd_bus_error
*error
);
255 int bus_set_transient_path(Unit
*u
, const char *name
, char **p
, sd_bus_message
*message
, UnitWriteFlags flags
, sd_bus_error
*error
);
256 int bus_set_transient_string(Unit
*u
, const char *name
, char **p
, sd_bus_message
*message
, UnitWriteFlags flags
, sd_bus_error
*error
);
257 int bus_set_transient_bool(Unit
*u
, const char *name
, bool *p
, sd_bus_message
*message
, UnitWriteFlags flags
, sd_bus_error
*error
);
258 int bus_set_transient_usec_internal(Unit
*u
, const char *name
, usec_t
*p
, bool fix_0
, sd_bus_message
*message
, UnitWriteFlags flags
, sd_bus_error
*error
);
259 static inline int bus_set_transient_usec(Unit
*u
, const char *name
, usec_t
*p
, sd_bus_message
*message
, UnitWriteFlags flags
, sd_bus_error
*error
) {
260 return bus_set_transient_usec_internal(u
, name
, p
, false, message
, flags
, error
);
262 static inline int bus_set_transient_usec_fix_0(Unit
*u
, const char *name
, usec_t
*p
, sd_bus_message
*message
, UnitWriteFlags flags
, sd_bus_error
*error
) {
263 return bus_set_transient_usec_internal(u
, name
, p
, true, message
, flags
, error
);