mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
bus-util: Log more information when connecting to a bus socket fails
Let's log about which bus we're trying to connect to and what transport we're using to do it.
This commit is contained in:
parent
a407aaa6ff
commit
d8a77d55e6
@ -14,7 +14,7 @@ int verb_blame(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = acquire_bus(&bus, NULL);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
n = acquire_time_data(bus, /* require_finished = */ false, ×);
|
||||
if (n <= 0)
|
||||
|
@ -200,7 +200,7 @@ int verb_critical_chain(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = acquire_bus(&bus, NULL);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
n = acquire_time_data(bus, /* require_finished = */ true, ×);
|
||||
if (n <= 0)
|
||||
|
@ -149,7 +149,7 @@ int verb_dot(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = acquire_bus(&bus, NULL);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
r = expand_patterns(bus, strv_skip(argv, 1), &expanded_patterns);
|
||||
if (r < 0)
|
||||
|
@ -123,7 +123,7 @@ int verb_dump(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = acquire_bus(&bus, NULL);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
pager_open(arg_pager_flags);
|
||||
|
||||
|
@ -98,7 +98,7 @@ int verb_fdstore(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = acquire_bus(&bus, NULL);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
STRV_FOREACH(arg, strv_skip(argv, 1)) {
|
||||
r = dump_fdstore(bus, *arg);
|
||||
|
@ -12,7 +12,7 @@ int verb_log_control(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = acquire_bus(&bus, NULL);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
r = verb_log_control_common(bus, "org.freedesktop.systemd1", argv[0], argc == 2 ? argv[1] : NULL);
|
||||
if (r < 0)
|
||||
|
@ -43,7 +43,7 @@ int verb_malloc(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = acquire_bus(&bus, NULL);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
r = sd_bus_can_send(bus, SD_BUS_TYPE_UNIX_FD);
|
||||
if (r < 0)
|
||||
|
@ -473,7 +473,7 @@ int verb_plot(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = acquire_bus(&bus, &use_full_bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
n = acquire_boot_times(bus, /* require_finished = */ true, &boot);
|
||||
if (n < 0)
|
||||
|
@ -2904,7 +2904,7 @@ int verb_security(int argc, char *argv[], void *userdata) {
|
||||
if (!arg_offline) {
|
||||
r = acquire_bus(&bus, NULL);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
}
|
||||
|
||||
pager_open(arg_pager_flags);
|
||||
|
@ -16,7 +16,7 @@ int verb_service_watchdogs(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = acquire_bus(&bus, NULL);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
if (argc == 1) {
|
||||
/* get ServiceWatchdogs */
|
||||
|
@ -11,7 +11,7 @@ int verb_time(int argc, char *argv[], void *userdata) {
|
||||
|
||||
r = acquire_bus(&bus, NULL);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
r = pretty_boot_time(bus, &buf);
|
||||
if (r < 0)
|
||||
|
@ -153,7 +153,7 @@ static int acquire_bus(bool set_monitor, sd_bus **ret) {
|
||||
|
||||
r = sd_bus_start(bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
*ret = TAKE_PTR(bus);
|
||||
|
||||
|
@ -221,13 +221,12 @@ static int run(int argc, char *argv[]) {
|
||||
return log_error_errno(r, "Failed to mangle unit name: %m");
|
||||
|
||||
if (!bus) {
|
||||
RuntimeScope scope = arg_show_unit == SHOW_UNIT_USER ? RUNTIME_SCOPE_USER : RUNTIME_SCOPE_SYSTEM;
|
||||
|
||||
/* Connect to the bus only if necessary */
|
||||
r = bus_connect_transport_systemd(
|
||||
BUS_TRANSPORT_LOCAL, NULL,
|
||||
arg_show_unit == SHOW_UNIT_USER ? RUNTIME_SCOPE_USER : RUNTIME_SCOPE_SYSTEM,
|
||||
&bus);
|
||||
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, scope, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, scope);
|
||||
}
|
||||
|
||||
q = show_cgroup_get_unit_path_and_warn(bus, unit_name, &cgroup);
|
||||
|
@ -1558,7 +1558,7 @@ static int reload_system_manager(sd_bus **bus) {
|
||||
if (!*bus) {
|
||||
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, RUNTIME_SCOPE_SYSTEM, bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, RUNTIME_SCOPE_SYSTEM);
|
||||
}
|
||||
|
||||
r = bus_service_manager_reload(*bus);
|
||||
@ -1581,7 +1581,7 @@ static int reload_vconsole(sd_bus **bus) {
|
||||
if (!*bus) {
|
||||
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, RUNTIME_SCOPE_SYSTEM, bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, RUNTIME_SCOPE_SYSTEM);
|
||||
}
|
||||
|
||||
r = bus_wait_for_jobs_new(*bus, &w);
|
||||
|
@ -135,7 +135,7 @@ static int acquire_bus(sd_bus **bus) {
|
||||
|
||||
r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
(void) sd_bus_set_allow_interactive_authorization(*bus, arg_ask_password);
|
||||
|
||||
|
@ -813,7 +813,7 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
return hostnamectl_main(bus, argc, argv);
|
||||
}
|
||||
|
@ -1240,7 +1240,7 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
(void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
|
||||
|
||||
|
@ -536,7 +536,7 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
return localectl_main(bus, argc, argv);
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
r = sd_bus_default_system(&bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
(void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
|
||||
|
||||
|
@ -1723,7 +1723,7 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
(void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
|
||||
|
||||
|
@ -2445,7 +2445,7 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
(void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
|
||||
|
||||
|
@ -1513,7 +1513,7 @@ static int run(int argc, char* argv[]) {
|
||||
|
||||
r = bus_connect_transport_systemd(arg_transport, arg_host, arg_runtime_scope, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
(void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
|
||||
|
||||
|
@ -229,7 +229,7 @@ static int acquire_bus(sd_bus **bus) {
|
||||
|
||||
r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
(void) sd_bus_set_allow_interactive_authorization(*bus, arg_ask_password);
|
||||
|
||||
|
@ -2439,7 +2439,7 @@ static int run(int argc, char* argv[]) {
|
||||
else
|
||||
r = bus_connect_transport_systemd(arg_transport, arg_host, arg_runtime_scope, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
(void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "path-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "stdio-util.h"
|
||||
#include "string-table.h"
|
||||
#include "uid-classification.h"
|
||||
|
||||
static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
|
||||
@ -50,14 +51,14 @@ int bus_log_address_error(int r, BusTransport transport) {
|
||||
"Failed to set bus address: %m");
|
||||
}
|
||||
|
||||
int bus_log_connect_error(int r, BusTransport transport) {
|
||||
int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope) {
|
||||
bool hint_vars = transport == BUS_TRANSPORT_LOCAL && r == -ENOMEDIUM,
|
||||
hint_addr = transport == BUS_TRANSPORT_LOCAL && ERRNO_IS_PRIVILEGE(r);
|
||||
|
||||
return log_error_errno(r,
|
||||
r == hint_vars ? "Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user)" :
|
||||
r == hint_addr ? "Failed to connect to bus: Operation not permitted (consider using --machine=<user>@.host --user to connect to bus of other user)" :
|
||||
"Failed to connect to bus: %m");
|
||||
r == hint_vars ? "Failed to connect to %s scope bus via %s transport: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user)" :
|
||||
r == hint_addr ? "Failed to connect to %s scope bus via %s transport: Operation not permitted (consider using --machine=<user>@.host --user to connect to bus of other user)" :
|
||||
"Failed to connect to %s scope bus via %s transport: %m", runtime_scope_to_string(scope), bus_transport_to_string(transport));
|
||||
}
|
||||
|
||||
int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) {
|
||||
@ -944,3 +945,12 @@ int bus_message_read_id128(sd_bus_message *m, sd_id128_t *ret) {
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
static const char* const bus_transport_table[] = {
|
||||
[BUS_TRANSPORT_LOCAL] = "local",
|
||||
[BUS_TRANSPORT_REMOTE] = "remote",
|
||||
[BUS_TRANSPORT_MACHINE] = "machine",
|
||||
[BUS_TRANSPORT_CAPSULE] = "capsule",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_TO_STRING(bus_transport, BusTransport);
|
||||
|
@ -48,7 +48,7 @@ int bus_connect_transport(BusTransport transport, const char *host, RuntimeScope
|
||||
int bus_connect_transport_systemd(BusTransport transport, const char *host, RuntimeScope runtime_scope, sd_bus **bus);
|
||||
|
||||
int bus_log_address_error(int r, BusTransport transport);
|
||||
int bus_log_connect_error(int r, BusTransport transport);
|
||||
int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope);
|
||||
|
||||
#define bus_log_parse_error(r) \
|
||||
log_error_errno(r, "Failed to parse bus message: %m")
|
||||
@ -84,3 +84,5 @@ int bus_creds_get_pidref(sd_bus_creds *c, PidRef *ret);
|
||||
int bus_query_sender_pidref(sd_bus_message *m, PidRef *ret);
|
||||
|
||||
int bus_message_read_id128(sd_bus_message *m, sd_id128_t *ret);
|
||||
|
||||
const char* bus_transport_to_string(BusTransport transport) _const_;
|
||||
|
@ -434,7 +434,7 @@ int show_cgroup_get_path_and_warn(
|
||||
|
||||
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, RUNTIME_SCOPE_SYSTEM, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
r = show_cgroup_get_unit_path_and_warn(bus, unit, &root);
|
||||
if (r < 0)
|
||||
|
@ -54,7 +54,7 @@ int acquire_bus(BusFocus focus, sd_bus **ret) {
|
||||
else
|
||||
r = bus_connect_transport(arg_transport, arg_host, arg_runtime_scope, &buses[focus]);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, arg_runtime_scope);
|
||||
|
||||
(void) sd_bus_set_allow_interactive_authorization(buses[focus], arg_ask_password);
|
||||
}
|
||||
|
@ -1299,7 +1299,7 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
if (arg_transport == BUS_TRANSPORT_LOCAL)
|
||||
polkit_agent_open();
|
||||
|
@ -1063,7 +1063,7 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
return bus_log_connect_error(r, arg_transport, RUNTIME_SCOPE_SYSTEM);
|
||||
|
||||
(void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user