]>
Commit | Line | Data |
---|---|---|
a87b151a DDM |
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | ||
3 | #include "alloc-util.h" | |
4 | #include "bus-error.h" | |
5 | #include "log.h" | |
6 | #include "strv.h" | |
7 | #include "syslog-util.h" | |
8 | #include "verb-log-control.h" | |
9 | ||
10 | int verb_log_control_common(sd_bus *bus, const char *destination, const char *verb, const char *value) { | |
11 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; | |
12 | bool level = endswith(verb, "log-level"); | |
13 | const BusLocator bloc = { | |
14 | .destination = destination, | |
15 | .path = "/org/freedesktop/LogControl1", | |
16 | .interface = "org.freedesktop.LogControl1", | |
17 | }; | |
18 | int r; | |
19 | ||
20 | assert(bus); | |
21 | assert(endswith(verb, "log-level") || endswith(verb, "log-target")); | |
22 | ||
23 | if (value) { | |
24 | if (level) { | |
25 | r = log_level_from_string(value); | |
26 | if (r < 0) | |
27 | return log_error_errno(r, "\"%s\" is not a valid log level.", value); | |
28 | } | |
29 | ||
30 | r = bus_set_property(bus, &bloc, | |
31 | level ? "LogLevel" : "LogTarget", | |
32 | &error, "s", value); | |
fddad5f4 ZJS |
33 | if (r < 0) |
34 | return log_error_errno(r, "Failed to set log %s of %s to %s: %s", | |
35 | level ? "level" : "target", | |
36 | bloc.destination, value, bus_error_message(&error, r)); | |
a87b151a DDM |
37 | } else { |
38 | _cleanup_free_ char *t = NULL; | |
39 | ||
40 | r = bus_get_property_string(bus, &bloc, | |
41 | level ? "LogLevel" : "LogTarget", | |
42 | &error, &t); | |
fddad5f4 ZJS |
43 | if (r < 0) |
44 | return log_error_errno(r, "Failed to get log %s of %s: %s", | |
45 | level ? "level" : "target", | |
46 | bloc.destination, bus_error_message(&error, r)); | |
47 | puts(t); | |
a87b151a DDM |
48 | } |
49 | ||
fddad5f4 | 50 | return 0; |
a87b151a | 51 | } |