From cbd37330bcd039587121a767280fc9fee597af6e Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Sun, 18 Dec 2011 14:58:10 +0100 Subject: dbus: register to DBus asynchronously Chen Jie observed and analyzed a deadlock. Assuming systemd-kmsg-syslogd is already stopped, but rsyslogd is not started yet: 1. systemd makes a synchronous call to dbus-daemon. 2. dbus-daemon wants to write something to syslog. 3. syslog needs to be started by systemd. ... but cannot be, because systemd is waiting in 1. Solve this by avoiding synchronous D-Bus calls. I had to write an async bus registration call. Interestingly, D-Bus authors anticipated this, in documentation to dbus_bus_set_unique_name(): > The only reason to use this function is to re-implement the equivalent > of dbus_bus_register() yourself. One (probably unusual) reason to do > that might be to do the bus registration call asynchronously instead > of synchronously. Lennart's comments from IRC: > though I think this doesn't fix the problem in its entirety > simply because dbus_connection_open_private() itself is still synchronous > i.e. the connect() call behind it is not async > I think I listed that issue actually on some D-Bus todo list > i.e. to make dbus_connection_get() fully async > but that's going to be hard > so your patch looks good So it may not be perfect, but it's clearly an improvement. I did not manage to reproduce the original deadlock with the patch. --- src/manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/manager.c') diff --git a/src/manager.c b/src/manager.c index 111167a8c2..6acc821e9c 100644 --- a/src/manager.c +++ b/src/manager.c @@ -231,7 +231,7 @@ int manager_new(ManagerRunningAs running_as, Manager **_m) { dual_timestamp_get(&m->startup_timestamp); m->running_as = running_as; - m->name_data_slot = m->subscribed_data_slot = -1; + m->name_data_slot = m->conn_data_slot = m->subscribed_data_slot = -1; m->exit_code = _MANAGER_EXIT_CODE_INVALID; m->pin_cgroupfs_fd = -1; -- cgit v1.2.3-54-g00ecf