tree-wide: convert more system1.Manager calls to BusLocator

This commit is contained in:
David Tardon
2023-05-23 20:09:37 +02:00
parent 5dc0c21b31
commit b71471684a
6 changed files with 13 additions and 50 deletions

View File

@@ -11,6 +11,7 @@
#include "blockdev-util.h"
#include "btrfs-util.h"
#include "bus-common-errors.h"
#include "bus-locator.h"
#include "data-fd-util.h"
#include "env-util.h"
#include "errno-list.h"
@@ -2117,15 +2118,7 @@ int home_killall(Home *h) {
if (asprintf(&unit, "user-" UID_FMT ".slice", h->uid) < 0)
return log_oom();
r = sd_bus_call_method(
h->manager->bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"KillUnit",
&error,
NULL,
"ssi", unit, "all", SIGKILL);
r = bus_call_method(h->manager->bus, bus_systemd_mgr, "KillUnit", &error, NULL, "ssi", unit, "all", SIGKILL);
if (r < 0)
log_full_errno(sd_bus_error_has_name(&error, BUS_ERROR_NO_SUCH_UNIT) ? LOG_DEBUG : LOG_WARNING,
r, "Failed to kill login processes of user, ignoring: %s", bus_error_message(&error, r));

View File

@@ -15,6 +15,7 @@
#include "alloc-util.h"
#include "build.h"
#include "bus-locator.h"
#include "bus-util.h"
#include "errno-util.h"
#include "fd-util.h"
@@ -704,14 +705,7 @@ static int get_virtualization(char **v) {
if (r < 0)
return r;
r = sd_bus_get_property_string(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"Virtualization",
NULL,
&b);
r = bus_get_property_string(bus, bus_systemd_mgr, "Virtualization", NULL, &b);
if (r < 0)
return r;

View File

@@ -6,6 +6,7 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-util.h"
#include "cgroup-util.h"
#include "clean-ipc.h"
@@ -388,13 +389,7 @@ static int user_update_slice(User *u) {
u->user_record->io_weight == UINT64_MAX)
return 0;
r = sd_bus_message_new_method_call(
u->manager->bus,
&m,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"SetUnitProperties");
r = bus_message_new_method_call(u->manager->bus, &m, bus_systemd_mgr, "SetUnitProperties");
if (r < 0)
return bus_log_create_error(r);

View File

@@ -4,6 +4,7 @@
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "chase.h"
#include "conf-files.h"
#include "copy.h"
@@ -780,13 +781,7 @@ static int unit_file_is_active(
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
const char *at, *prefix, *joined;
r = sd_bus_message_new_method_call(
bus,
&m,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"ListUnitsByPatterns");
r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, "ListUnitsByPatterns");
if (r < 0)
return r;

View File

@@ -242,13 +242,7 @@ static int maybe_reload(sd_bus **bus) {
if (r < 0)
return r;
r = sd_bus_message_new_method_call(
*bus,
&m,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"Reload");
r = bus_message_new_method_call(*bus, &m, bus_systemd_mgr, "Reload");
if (r < 0)
return bus_log_create_error(r);
@@ -566,12 +560,10 @@ static int maybe_enable_disable(sd_bus *bus, const char *path, bool enable) {
if (!names)
return log_oom();
r = sd_bus_message_new_method_call(
r = bus_message_new_method_call(
bus,
&m,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
bus_systemd_mgr,
enable ? "EnableUnitFilesWithFlags" : "DisableUnitFilesWithFlags");
if (r < 0)
return bus_log_create_error(r);

View File

@@ -13,6 +13,7 @@
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-util.h"
#include "format-util.h"
#include "log.h"
@@ -50,14 +51,7 @@ static usec_t get_startup_monotonic_time(Context *c) {
assert(c);
r = sd_bus_get_property_trivial(
c->bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"UserspaceTimestampMonotonic",
&error,
't', &t);
r = bus_get_property_trivial(c->bus, bus_systemd_mgr, "UserspaceTimestampMonotonic", &error, 't', &t);
if (r < 0) {
log_error_errno(r, "Failed to get timestamp: %s", bus_error_message(&error, r));
return 0;