udevadm-control: use varlink to send commands
This commit is contained in:
@@ -163,3 +163,23 @@ int manager_start_varlink_server(Manager *manager) {
|
||||
manager->varlink_server = TAKE_PTR(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int udev_varlink_connect(sd_varlink **ret, usec_t timeout) {
|
||||
_cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *link = NULL;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
r = sd_varlink_connect_address(&link, UDEV_VARLINK_ADDRESS);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) sd_varlink_set_description(link, "udev");
|
||||
|
||||
r = sd_varlink_set_relative_timeout(link, timeout);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*ret = TAKE_PTR(link);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "sd-varlink.h"
|
||||
|
||||
#include "time-util.h"
|
||||
|
||||
typedef struct Manager Manager;
|
||||
|
||||
int manager_start_varlink_server(Manager *manager);
|
||||
int udev_varlink_connect(sd_varlink **ret, usec_t timeout);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "creds-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "process-util.h"
|
||||
#include "static-destruct.h"
|
||||
@@ -17,6 +18,8 @@
|
||||
#include "time-util.h"
|
||||
#include "udevadm.h"
|
||||
#include "udev-ctrl.h"
|
||||
#include "udev-varlink.h"
|
||||
#include "varlink-util.h"
|
||||
#include "virt.h"
|
||||
|
||||
static char **arg_env = NULL;
|
||||
@@ -174,7 +177,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int send_control_commands(void) {
|
||||
static int send_control_commands_via_ctrl(void) {
|
||||
_cleanup_(udev_ctrl_unrefp) UdevCtrl *uctrl = NULL;
|
||||
int r;
|
||||
|
||||
@@ -238,6 +241,64 @@ static int send_control_commands(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int send_control_commands(void) {
|
||||
_cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *link = NULL;
|
||||
int r;
|
||||
|
||||
r = udev_varlink_connect(&link, arg_timeout);
|
||||
if (ERRNO_IS_NEG_DISCONNECT(r) || r == -ENOENT) {
|
||||
log_debug_errno(r, "Failed to connect to udev via varlink, falling back to use legacy control socket, ignoring: %m");
|
||||
return send_control_commands_via_ctrl();
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to connect to udev via varlink: %m");
|
||||
|
||||
if (arg_exit)
|
||||
return varlink_call_and_log(link, "io.systemd.Udev.Exit", /* parameters = */ NULL, /* reply = */ NULL);
|
||||
|
||||
if (arg_log_level >= 0) {
|
||||
r = varlink_callbo_and_log(link, "io.systemd.service.SetLogLevel", /* reply = */ NULL,
|
||||
SD_JSON_BUILD_PAIR_INTEGER("level", arg_log_level));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (arg_start_exec_queue >= 0) {
|
||||
r = varlink_call_and_log(link, arg_start_exec_queue ? "io.systemd.Udev.StartExecQueue" : "io.systemd.Udev.StopExecQueue",
|
||||
/* parameters = */ NULL, /* reply = */ NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (arg_reload) {
|
||||
r = varlink_call_and_log(link, "io.systemd.service.Reload", /* parameters = */ NULL, /* reply = */ NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!strv_isempty(arg_env)) {
|
||||
r = varlink_callbo_and_log(link, "io.systemd.Udev.SetEnvironment", /* reply = */ NULL,
|
||||
SD_JSON_BUILD_PAIR_STRV("assignments", arg_env));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (arg_max_children >= 0) {
|
||||
r = varlink_callbo_and_log(link, "io.systemd.Udev.SetChildrenMax", /* reply = */ NULL,
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("number", arg_max_children));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (arg_ping) {
|
||||
r = varlink_call_and_log(link, "io.systemd.service.Ping", /* parameters = */ NULL, /* reply = */ NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int control_main(int argc, char *argv[], void *userdata) {
|
||||
int r;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user