mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
Revert "sd-bus: do not connect to dbus-1 socket when kdbus is available"
This reverts commit d4d00020d6ad855d65d31020fefa5003e1bb477f. The idea of the commit is broken and needs to be reworked. We really cannot reduce the bus-addresses to a single address. We always will have systemd with native clients and legacy clients at the same time, so we also need both addresses at the same time.
This commit is contained in:
parent
8faae625dc
commit
057171efc1
@ -63,6 +63,7 @@
|
||||
|
||||
#define UNIX_SYSTEM_BUS_ADDRESS "unix:path=/var/run/dbus/system_bus_socket"
|
||||
#define KERNEL_SYSTEM_BUS_ADDRESS "kernel:path=/sys/fs/kdbus/0-system/bus"
|
||||
#define DEFAULT_SYSTEM_BUS_ADDRESS KERNEL_SYSTEM_BUS_ADDRESS ";" UNIX_SYSTEM_BUS_ADDRESS
|
||||
#define UNIX_USER_BUS_ADDRESS_FMT "unix:path=%s/bus"
|
||||
#define KERNEL_USER_BUS_ADDRESS_FMT "kernel:path=/sys/fs/kdbus/"UID_FMT"-user/bus"
|
||||
|
||||
|
@ -177,9 +177,8 @@ static int help(void) {
|
||||
" --configuration=PATH Configuration file or directory\n"
|
||||
" --machine=MACHINE Connect to specified machine\n"
|
||||
" --address=ADDRESS Connect to the bus specified by ADDRESS\n"
|
||||
" (default: %s)\n",
|
||||
program_invocation_short_name,
|
||||
is_kdbus_available() ? KERNEL_SYSTEM_BUS_ADDRESS : UNIX_SYSTEM_BUS_ADDRESS);
|
||||
" (default: " DEFAULT_SYSTEM_BUS_ADDRESS ")\n",
|
||||
program_invocation_short_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -263,7 +262,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (!arg_address) {
|
||||
arg_address = strdup(is_kdbus_available() ? KERNEL_SYSTEM_BUS_ADDRESS : UNIX_SYSTEM_BUS_ADDRESS);
|
||||
arg_address = strdup(DEFAULT_SYSTEM_BUS_ADDRESS);
|
||||
if (!arg_address)
|
||||
return log_oom();
|
||||
}
|
||||
|
@ -50,9 +50,8 @@ static int help(void) {
|
||||
" --version Show package version\n"
|
||||
" --machine=MACHINE Connect to specified machine\n"
|
||||
" --address=ADDRESS Connect to the bus specified by ADDRESS\n"
|
||||
" (default: %s)\n",
|
||||
program_invocation_short_name,
|
||||
is_kdbus_available() ? KERNEL_SYSTEM_BUS_ADDRESS : UNIX_SYSTEM_BUS_ADDRESS);
|
||||
" (default: " DEFAULT_SYSTEM_BUS_ADDRESS ")\n",
|
||||
program_invocation_short_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -138,7 +137,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (!arg_address) {
|
||||
arg_address = strdup(is_kdbus_available() ? KERNEL_SYSTEM_BUS_ADDRESS : UNIX_SYSTEM_BUS_ADDRESS);
|
||||
arg_address = strdup(DEFAULT_SYSTEM_BUS_ADDRESS);
|
||||
if (!arg_address)
|
||||
return log_oom();
|
||||
}
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "path-util.h"
|
||||
#include "dbus-automount.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-error.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "async.h"
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "utf8.h"
|
||||
#include "env-util.h"
|
||||
#include "fileio.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-kernel.h"
|
||||
#include "formats-util.h"
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "def.h"
|
||||
#include "smack-util.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-error.h"
|
||||
#include "selinux-util.h"
|
||||
#include "dbus-socket.h"
|
||||
#include "unit.h"
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "dbus-timer.h"
|
||||
#include "special.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-error.h"
|
||||
|
||||
static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = {
|
||||
[TIMER_DEAD] = UNIT_INACTIVE,
|
||||
|
@ -84,8 +84,7 @@ static int create_dbus_files(
|
||||
fprintf(f, "Environment=DBUS_STARTER_BUS_TYPE=%s\n", type);
|
||||
|
||||
if (streq(type, "system"))
|
||||
fprintf(f, "Environment=DBUS_STARTER_ADDRESS=%s\n",
|
||||
is_kdbus_available() ? KERNEL_SYSTEM_BUS_ADDRESS : UNIX_SYSTEM_BUS_ADDRESS);
|
||||
fprintf(f, "Environment=DBUS_STARTER_ADDRESS=" DEFAULT_SYSTEM_BUS_ADDRESS "\n");
|
||||
else if (streq(type, "session")) {
|
||||
char *run;
|
||||
|
||||
@ -95,10 +94,8 @@ static int create_dbus_files(
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (is_kdbus_available())
|
||||
fprintf(f, "Environment=DBUS_STARTER_ADDRESS="KERNEL_USER_BUS_ADDRESS_FMT "\n", getuid());
|
||||
else
|
||||
fprintf(f, "Environment=DBUS_STARTER_ADDRESS="UNIX_USER_BUS_ADDRESS_FMT "\n", run);
|
||||
fprintf(f, "Environment=DBUS_STARTER_ADDRESS="KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT "\n",
|
||||
getuid(), run);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "bus-message.h"
|
||||
#include "bus-control.h"
|
||||
#include "bus-bloom.h"
|
||||
#include "bus-util.h"
|
||||
#include "capability.h"
|
||||
|
||||
_public_ int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "bus-internal.h"
|
||||
#include "bus-message.h"
|
||||
#include "bus-signature.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-type.h"
|
||||
|
||||
_public_ int sd_bus_emit_signal(
|
||||
|
@ -31,10 +31,10 @@
|
||||
#include "fileio.h"
|
||||
#include "audit.h"
|
||||
#include "bus-message.h"
|
||||
#include "bus-util.h"
|
||||
#include "strv.h"
|
||||
#include "bus-creds.h"
|
||||
#include "bus-label.h"
|
||||
#include "bus-internal.h"
|
||||
|
||||
enum {
|
||||
CAP_OFFSET_INHERITABLE = 0,
|
||||
|
@ -371,45 +371,3 @@ int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool is_kdbus_wanted(void) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
#ifdef ENABLE_KDBUS
|
||||
const bool configured = true;
|
||||
#else
|
||||
const bool configured = false;
|
||||
#endif
|
||||
int r;
|
||||
|
||||
if (get_proc_cmdline_key("kdbus", NULL) > 0)
|
||||
return true;
|
||||
|
||||
r = get_proc_cmdline_key("kdbus=", &value);
|
||||
if (r <= 0)
|
||||
return configured;
|
||||
|
||||
return parse_boolean(value) == 1;
|
||||
}
|
||||
|
||||
bool is_kdbus_available(void) {
|
||||
static int cached = -1;
|
||||
_cleanup_close_ int fd = -1;
|
||||
struct kdbus_cmd cmd = { .size = sizeof(cmd), .flags = KDBUS_FLAG_NEGOTIATE };
|
||||
|
||||
if (cached >= 0)
|
||||
return (bool) cached;
|
||||
|
||||
if (!is_kdbus_wanted()) {
|
||||
cached = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
fd = open("/sys/fs/kdbus/control", O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
|
||||
if (fd < 0) {
|
||||
cached = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
cached = ioctl(fd, KDBUS_CMD_BUS_MAKE, &cmd) >= 0;
|
||||
return cached;
|
||||
}
|
||||
|
@ -37,29 +37,6 @@
|
||||
#include "bus-kernel.h"
|
||||
#include "kdbus.h"
|
||||
|
||||
typedef enum BusTransport {
|
||||
BUS_TRANSPORT_LOCAL,
|
||||
BUS_TRANSPORT_REMOTE,
|
||||
BUS_TRANSPORT_MACHINE,
|
||||
_BUS_TRANSPORT_MAX,
|
||||
_BUS_TRANSPORT_INVALID = -1
|
||||
} BusTransport;
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_flush_close_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_slot*, sd_bus_slot_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, sd_bus_message_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_creds*, sd_bus_creds_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_track*, sd_bus_track_unref);
|
||||
|
||||
#define _cleanup_bus_unref_ _cleanup_(sd_bus_unrefp)
|
||||
#define _cleanup_bus_flush_close_unref_ _cleanup_(sd_bus_flush_close_unrefp)
|
||||
#define _cleanup_bus_slot_unref_ _cleanup_(sd_bus_slot_unrefp)
|
||||
#define _cleanup_bus_message_unref_ _cleanup_(sd_bus_message_unrefp)
|
||||
#define _cleanup_bus_creds_unref_ _cleanup_(sd_bus_creds_unrefp)
|
||||
#define _cleanup_bus_track_unref_ _cleanup_(sd_bus_slot_unrefp)
|
||||
#define _cleanup_bus_error_free_ _cleanup_(sd_bus_error_free)
|
||||
|
||||
struct reply_callback {
|
||||
sd_bus_message_handler_t callback;
|
||||
usec_t timeout;
|
||||
@ -417,9 +394,6 @@ int bus_get_root_path(sd_bus *bus);
|
||||
|
||||
int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error);
|
||||
|
||||
bool is_kdbus_wanted(void);
|
||||
bool is_kdbus_available(void);
|
||||
|
||||
#define bus_assert_return(expr, r, error) \
|
||||
do { \
|
||||
if (!assert_log(expr)) \
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "bus-message.h"
|
||||
#include "bus-kernel.h"
|
||||
#include "bus-bloom.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-label.h"
|
||||
|
||||
#define UNIQUE_NAME_MAX (3+DECIMAL_STR_MAX(uint64_t))
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "bus-internal.h"
|
||||
#include "bus-message.h"
|
||||
#include "bus-match.h"
|
||||
#include "bus-util.h"
|
||||
#include "strv.h"
|
||||
|
||||
/* Example:
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "bus-type.h"
|
||||
#include "bus-signature.h"
|
||||
#include "bus-gvariant.h"
|
||||
#include "bus-util.h"
|
||||
|
||||
static int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored);
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "bus-type.h"
|
||||
#include "bus-signature.h"
|
||||
#include "bus-introspect.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-slot.h"
|
||||
#include "bus-objects.h"
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-track.h"
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "set.h"
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-dump.h"
|
||||
#include "bus-signature.h"
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "bus-kernel.h"
|
||||
#include "bus-control.h"
|
||||
#include "bus-objects.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-container.h"
|
||||
#include "bus-protocol.h"
|
||||
#include "bus-track.h"
|
||||
@ -1173,10 +1174,7 @@ int bus_set_address_system(sd_bus *b) {
|
||||
if (e)
|
||||
return sd_bus_set_address(b, e);
|
||||
|
||||
if (is_kdbus_available())
|
||||
return sd_bus_set_address(b, KERNEL_SYSTEM_BUS_ADDRESS);
|
||||
|
||||
return sd_bus_set_address(b, UNIX_SYSTEM_BUS_ADDRESS);
|
||||
return sd_bus_set_address(b, DEFAULT_SYSTEM_BUS_ADDRESS);
|
||||
}
|
||||
|
||||
_public_ int sd_bus_open_system(sd_bus **ret) {
|
||||
@ -1224,17 +1222,16 @@ int bus_set_address_user(sd_bus *b) {
|
||||
return sd_bus_set_address(b, e);
|
||||
|
||||
e = secure_getenv("XDG_RUNTIME_DIR");
|
||||
if (is_kdbus_available())
|
||||
(void) asprintf(&b->address, KERNEL_USER_BUS_ADDRESS_FMT, getuid());
|
||||
else if (e) {
|
||||
if (e) {
|
||||
_cleanup_free_ char *ee = NULL;
|
||||
|
||||
ee = bus_address_escape(e);
|
||||
if (!ee)
|
||||
return -ENOMEM;
|
||||
|
||||
(void) asprintf(&b->address, UNIX_USER_BUS_ADDRESS_FMT, ee);
|
||||
}
|
||||
(void) asprintf(&b->address, KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT, getuid(), ee);
|
||||
} else
|
||||
(void) asprintf(&b->address, KERNEL_USER_BUS_ADDRESS_FMT, getuid());
|
||||
|
||||
if (!b->address)
|
||||
return -ENOMEM;
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "sd-bus.h"
|
||||
#include "bus-kernel.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-util.h"
|
||||
|
||||
#define MAX_SIZE (2*1024*1024)
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "bus-error.h"
|
||||
#include "bus-match.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-util.h"
|
||||
|
||||
static int match_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
|
||||
log_info("Match triggered! interface=%s member=%s", strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member(m)));
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-message.h"
|
||||
#include "refcnt.h"
|
||||
|
@ -20,6 +20,7 @@
|
||||
***/
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-util.h"
|
||||
#include "errno-list.h"
|
||||
#include "bus-common-errors.h"
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "macro.h"
|
||||
#include "sd-bus.h"
|
||||
#include "bus-gvariant.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-message.h"
|
||||
#include "bus-dump.h"
|
||||
|
@ -25,8 +25,8 @@
|
||||
#include "log.h"
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-kernel.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-dump.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "bus-match.h"
|
||||
#include "bus-message.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-slot.h"
|
||||
|
||||
static bool mask[32];
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "sd-bus.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-message.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-dump.h"
|
||||
|
||||
struct context {
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-util.h"
|
||||
|
||||
struct context {
|
||||
int fds[2];
|
||||
|
@ -2032,3 +2032,37 @@ int bus_path_decode_unique(const char *path, const char *prefix, char **ret_send
|
||||
*ret_external = external;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool is_kdbus_wanted(void) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
#ifdef ENABLE_KDBUS
|
||||
const bool configured = true;
|
||||
#else
|
||||
const bool configured = false;
|
||||
#endif
|
||||
|
||||
int r;
|
||||
|
||||
if (get_proc_cmdline_key("kdbus", NULL) > 0)
|
||||
return true;
|
||||
|
||||
r = get_proc_cmdline_key("kdbus=", &value);
|
||||
if (r <= 0)
|
||||
return configured;
|
||||
|
||||
return parse_boolean(value) == 1;
|
||||
}
|
||||
|
||||
bool is_kdbus_available(void) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
struct kdbus_cmd cmd = { .size = sizeof(cmd), .flags = KDBUS_FLAG_NEGOTIATE };
|
||||
|
||||
if (!is_kdbus_wanted())
|
||||
return false;
|
||||
|
||||
fd = open("/sys/fs/kdbus/control", O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
|
||||
if (fd < 0)
|
||||
return false;
|
||||
|
||||
return ioctl(fd, KDBUS_CMD_BUS_MAKE, &cmd) >= 0;
|
||||
}
|
||||
|
@ -23,12 +23,18 @@
|
||||
|
||||
#include "sd-event.h"
|
||||
#include "sd-bus.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-internal.h"
|
||||
#include "hashmap.h"
|
||||
#include "install.h"
|
||||
#include "time-util.h"
|
||||
|
||||
typedef enum BusTransport {
|
||||
BUS_TRANSPORT_LOCAL,
|
||||
BUS_TRANSPORT_REMOTE,
|
||||
BUS_TRANSPORT_MACHINE,
|
||||
_BUS_TRANSPORT_MAX,
|
||||
_BUS_TRANSPORT_INVALID = -1
|
||||
} BusTransport;
|
||||
|
||||
typedef int (*bus_property_set_t) (sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
|
||||
|
||||
struct bus_properties_map {
|
||||
@ -129,6 +135,21 @@ typedef struct UnitInfo {
|
||||
|
||||
int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u);
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_flush_close_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_slot*, sd_bus_slot_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, sd_bus_message_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_creds*, sd_bus_creds_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_track*, sd_bus_track_unref);
|
||||
|
||||
#define _cleanup_bus_unref_ _cleanup_(sd_bus_unrefp)
|
||||
#define _cleanup_bus_flush_close_unref_ _cleanup_(sd_bus_flush_close_unrefp)
|
||||
#define _cleanup_bus_slot_unref_ _cleanup_(sd_bus_slot_unrefp)
|
||||
#define _cleanup_bus_message_unref_ _cleanup_(sd_bus_message_unrefp)
|
||||
#define _cleanup_bus_creds_unref_ _cleanup_(sd_bus_creds_unrefp)
|
||||
#define _cleanup_bus_track_unref_ _cleanup_(sd_bus_slot_unrefp)
|
||||
#define _cleanup_bus_error_free_ _cleanup_(sd_bus_error_free)
|
||||
|
||||
#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type) \
|
||||
int function(sd_bus *bus, \
|
||||
const char *path, \
|
||||
@ -176,3 +197,6 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, Un
|
||||
|
||||
int bus_path_encode_unique(sd_bus *b, const char *prefix, const char *sender_id, const char *external_id, char **ret_path);
|
||||
int bus_path_decode_unique(const char *path, const char *prefix, char **ret_sender, char **ret_external);
|
||||
|
||||
bool is_kdbus_wanted(void);
|
||||
bool is_kdbus_available(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user