]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/verb-log-control.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "alloc-util.h"
7 #include "syslog-util.h"
8 #include "verb-log-control.h"
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",
21 assert(endswith(verb
, "log-level") || endswith(verb
, "log-target"));
25 r
= log_level_from_string(value
);
27 return log_error_errno(r
, "\"%s\" is not a valid log level.", value
);
30 r
= bus_set_property(bus
, &bloc
,
31 level
? "LogLevel" : "LogTarget",
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
));
38 _cleanup_free_
char *t
= NULL
;
40 r
= bus_get_property_string(bus
, &bloc
,
41 level
? "LogLevel" : "LogTarget",
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
));