1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "dbus-util.h"
23 #include "parse-util.h"
24 #include "path-util.h"
25 #include "unit-printf.h"
26 #include "user-util.h"
29 BUS_DEFINE_SET_TRANSIENT(mode_t
, "u", uint32_t, mode_t
, "%040o");
30 BUS_DEFINE_SET_TRANSIENT(unsigned, "u", uint32_t, unsigned, "%" PRIu32
);
31 BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(user
, valid_user_group_name_or_id
);
32 BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(path
, path_is_absolute
);
34 int bus_set_transient_string(
38 sd_bus_message
*message
,
40 sd_bus_error
*error
) {
47 r
= sd_bus_message_read(message
, "s", &v
);
51 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
52 r
= free_and_strdup(p
, empty_to_null(v
));
56 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
57 "%s=%s", name
, strempty(v
));
63 int bus_set_transient_bool(
67 sd_bus_message
*message
,
69 sd_bus_error
*error
) {
75 r
= sd_bus_message_read(message
, "b", &v
);
79 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
81 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, yes_no(v
));
87 int bus_set_transient_usec_internal(
92 sd_bus_message
*message
,
94 sd_bus_error
*error
) {
101 r
= sd_bus_message_read(message
, "t", &v
);
105 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
106 char *n
, ts
[FORMAT_TIMESPAN_MAX
];
109 *p
= v
!= 0 ? v
: USEC_INFINITY
;
113 n
= strndupa(name
, strlen(name
) - 4);
114 unit_write_settingf(u
, flags
, name
, "%sSec=%s", n
,
115 format_timespan(ts
, sizeof(ts
), v
, USEC_PER_MSEC
));