Skip to contentSkip to conversation

Enable DBus activation on non-systemd systems.

PATCH In review Mark Hindley 3 participants 5 messages Nov 12, 2021 – Nov 13, 2021

lore
Share & tools
lore

Mark Hindley

author
#0 lore raw

PATCH 1/1 Enable DBus activation on non-systemd systems.

I have been investigating why legacy DBus activation does not work for iwd on non-systemd systems. In Debian and Devuan (at least) this has required alternative means of starting the daemon by initscript be implemented.

However, DBus activation without systemd is possible, without any impact on systems running systemd.

For this to be supported there are 3 aspects that need to be addressed:

- net.connman.iwd.service: set Exec to iwd path.

- client/dbus-proxy.c: always call get_managed_objects() on init.

- src/main/c: register Object Manager before acquiring name otherwise the call to get_managed_objects() which triggers activation fails with 'No matching method found'.

Signed-off-by Mark Hindley <mark(a)hindley.org.uk>
---
 client/dbus-proxy.c                                         | 3 +--
 src/main.c                                                  | 6 +++---
 src/{net.connman.iwd.service => net.connman.iwd.service.in} | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)
 rename src/{net.connman.iwd.service => net.connman.iwd.service.in} (77%)
client/dbus-proxy.c +1 -2
index ab9fb5a5..15bb4128 100644
@@ -855,13 +855,12 @@ bool dbus_proxy_init(void)
 	l_dbus_set_disconnect_handler(dbus, dbus_disconnect_callback, NULL,
 									NULL);
 
+	get_managed_objects();
 	if (command_is_interactive_mode())
 		l_dbus_add_service_watch(dbus, IWD_SERVICE,
 						service_appeared_callback,
 						service_disappeared_callback,
 						NULL, NULL);
-	else
-		get_managed_objects();
 
 	return true;
 }
src/main.c +3 -3
index 989665e4..8e3a5ca7 100644
@@ -191,9 +191,6 @@ static void request_name_callback(struct l_dbus *dbus, bool success,
 		goto fail_exit;
 	}
 
-	if (!l_dbus_object_manager_enable(dbus, "/"))
-		l_warn("Unable to register the ObjectManager");
-
 	if (!l_dbus_object_add_interface(dbus, IWD_BASE_PATH,
 						IWD_DAEMON_INTERFACE,
 						NULL) ||
@@ -240,6 +237,9 @@ static void dbus_ready(void *user_data)
 {
 	struct l_dbus *dbus = user_data;
 
+	if (!l_dbus_object_manager_enable(dbus, "/"))
+		l_warn("Unable to register the ObjectManager");
+
 	l_dbus_name_acquire(dbus, "net.connman.iwd", false, false, false,
 				request_name_callback, NULL);
 
src/net.connman.iwd.service.in renamed from src/net.connman.iwd.service +1 -1
similarity index 77%
rename from src/net.connman.iwd.service
rename to src/net.connman.iwd.service.in
index d8ece4c3..a7cb7edd 100644
@@ -1,5 +1,5 @@
 [D-BUS Service]
 Name=net.connman.iwd
-Exec=/bin/false
+Exec=@libexecdir@/iwd
 User=root
 SystemdService=iwd.service
Signature · 1 line
2.20.1
#1 lore raw

Hi Mark,

Quoted 31 lines

I have been investigating why legacy DBus activation does not work for iwd on non-systemd systems. In Debian and Devuan (at least) this has required alternative means of starting the daemon by initscript be implemented.

However, DBus activation without systemd is possible, without any impact on systems running systemd.

For this to be supported there are 3 aspects that need to be addressed:

- net.connman.iwd.service: set Exec to iwd path.

- client/dbus-proxy.c: always call get_managed_objects() on init.

- src/main/c: register Object Manager before acquiring name otherwise the call to get_managed_objects() which triggers activation fails with 'No matching method found'.

Signed-off-by Mark Hindley <mark(a)hindley.org.uk>

---

client/dbus-proxy.c                                         | 3 +--
src/main.c                                                  | 6 +++---
src/{net.connman.iwd.service => net.connman.iwd.service.in} | 2 +-
3 files changed, 5 insertions(+), 6 deletions(-)

rename src/{net.connman.iwd.service => net.connman.iwd.service.in} (77%)

client/dbus-proxy.c +0 -0
index ab9fb5a5..15bb4128 100644
@@ -855,13 +855,12 @@ bool dbus_proxy_init(void)
 	l_dbus_set_disconnect_handler(dbus, dbus_disconnect_callback, NULL,

client/dbus-proxy.c bool dbus_proxy_init(void) · line 864

Quoted 10 lines
client/dbus-proxy.c +1 -2
 									NULL);
 
+	get_managed_objects();
 	if (command_is_interactive_mode())
 		l_dbus_add_service_watch(dbus, IWD_SERVICE,
 						service_appeared_callback,
 						service_disappeared_callback,
 						NULL, NULL);
-	else
-		get_managed_objects();

I don’t understand this change. The whole point is to actually wait for the service to appear.

Quoted 18 lines
client/dbus-proxy.c +0 -0
 	return true;
 }
src/main.c +0 -3
index 989665e4..8e3a5ca7 100644
@@ -191,9 +191,6 @@ static void request_name_callback(struct l_dbus *dbus, bool success,
 		goto fail_exit;
 	}
 
-	if (!l_dbus_object_manager_enable(dbus, "/"))
-		l_warn("Unable to register the ObjectManager");
-
 	if (!l_dbus_object_add_interface(dbus, IWD_BASE_PATH,
 						IWD_DAEMON_INTERFACE,
 						NULL) ||

src/main.c static void dbus_ready(void *user_data) · line 242

Quoted 6 lines
src/main.c +3 -0
@@ -240,6 +237,9 @@ static void dbus_ready(void *user_data)
 {
 	struct l_dbus *dbus = user_data;
 
+	if (!l_dbus_object_manager_enable(dbus, "/"))
+		l_warn("Unable to register the ObjectManager");
+

This change is unclear to me. Why would I register the ObjectManager if I can’t acquire the name. I don’t get how this is suppose to work. This is actually the right thing to do.

Quoted 15 lines
src/main.c +0 -0
 	l_dbus_name_acquire(dbus, "net.connman.iwd", false, false, false,
 				request_name_callback, NULL);
 
src/net.connman.iwd.service.in renamed from src/net.connman.iwd.service +0 -0
similarity index 77%
rename from src/net.connman.iwd.service
rename to src/net.connman.iwd.service.in
index d8ece4c3..a7cb7edd 100644
@@ -1,5 +1,5 @@

[D-BUS Service]
Name=net.connman.iwd

src/net.connman.iwd.service.in renamed from src/net.connman.iwd.service +1 -1
-Exec=/bin/false
+Exec=@libexecdir@/iwd
Quoted 2 lines

User=root
SystemdService=iwd.service

This change is not for upstream git tree. Use --disable-systemd-service and then provide your own files in the distro packaging. Long time ago we made the decision to only provide systemd integration. All other things like init scripts or custom distro specific files are left to the distro packages.

Regards

Marcel

author
#2 lore raw

Marcel,

Thanks

Quoted 6 lines · Marcel Holtmann
Quoted 6 lines
client/dbus-proxy.c +0 -0
@@ -855,13 +855,12 @@ bool dbus_proxy_init(void)
 	l_dbus_set_disconnect_handler(dbus, dbus_disconnect_callback, NULL,
 									NULL);
 
Quoted 11 lines

client/dbus-proxy.c bool dbus_proxy_init(void) · line 864

Quoted 8 lines
client/dbus-proxy.c +1 -2
+	get_managed_objects();
 	if (command_is_interactive_mode())
 		l_dbus_add_service_watch(dbus, IWD_SERVICE,
 						service_appeared_callback,
 						service_disappeared_callback,
 						NULL, NULL);
-	else
-		get_managed_objects();

I don’t understand this change. The whole point is to actually wait for the service to appear.

Yes, but it is a chicken and egg situation: plain DBus activation relies on the first call on the bus to trigger the activation[1]. The call at the end of service_appeared_callback() is never going to be reached as interactive iwct is just waiting having called service_disappeared_callback().

Quoted 22 lines
Quoted 22 lines
client/dbus-proxy.c +0 -0
 	return true;
 }
src/main.c +0 -3
index 989665e4..8e3a5ca7 100644
@@ -191,9 +191,6 @@ static void request_name_callback(struct l_dbus *dbus, bool success,
 		goto fail_exit;
 	}
 
-	if (!l_dbus_object_manager_enable(dbus, "/"))
-		l_warn("Unable to register the ObjectManager");
-
 	if (!l_dbus_object_add_interface(dbus, IWD_BASE_PATH,
 						IWD_DAEMON_INTERFACE,
 						NULL) ||
@@ -240,6 +237,9 @@ static void dbus_ready(void *user_data)
 {
 	struct l_dbus *dbus = user_data;
 
Quoted 6 lines

src/main.c static void dbus_ready(void *user_data) · line 242

Quoted 3 lines
src/main.c +3 -0
+	if (!l_dbus_object_manager_enable(dbus, "/"))
+		l_warn("Unable to register the ObjectManager");
+

This change is unclear to me. Why would I register the ObjectManager if I can’t acquire the name. I don’t get how this is suppose to work.

Without this change, once the name is acquired, dbus still fails to find the ObjectManager path as it hasn't (yet) been enabled. So the first call to get_managed_objects() fails if it was also the one that caused the service activation.

Quoted 1 line

This is the right thing to do.

I wondered about the order here too. I know that they are different bindings and that it is deprecated, so it may well not be the most convincing argument, but GDBus docs specify this requirement[2] and use it in their examples[3] where object paths are registered on bus acquisition rather than name acquisition.

Quoted 13 lines
Quoted 13 lines
src/main.c +0 -0
 	l_dbus_name_acquire(dbus, "net.connman.iwd", false, false, false,
 				request_name_callback, NULL);
 
src/net.connman.iwd.service.in renamed from src/net.connman.iwd.service +0 -0
similarity index 77%
rename from src/net.connman.iwd.service
rename to src/net.connman.iwd.service.in
index d8ece4c3..a7cb7edd 100644
@@ -1,5 +1,5 @@

[D-BUS Service]

Quoted 8 lines
Quoted 5 lines

Name=net.connman.iwd

src/net.connman.iwd.service.in renamed from src/net.connman.iwd.service +1 -1
-Exec=/bin/false
+Exec=@libexecdir@/iwd

User=root
SystemdService=iwd.service

This change is not for upstream git tree. Use --disable-systemd-service and then provide your own files in the distro packaging.

But this isn't about distro specific packaging, I think it is a setup that works both with systemd or without it. Debian has both systemd and several other inits available so building with --disabled-systemd-service is not an option.

Thanks

Mark

[1] https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-starting-services

[2] https://www.freedesktop.org/software/gstreamer-sdk/data/docs/latest/gio/ch30s03.html

[3] https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gdbus-example-server.c

#3 lore raw
Quoted 100 lines · Mark Hindley

Marcel,

Thanks

Quoted 6 lines · Marcel Holtmann
Quoted 6 lines
client/dbus-proxy.c +0 -0
@@ -855,13 +855,12 @@ bool dbus_proxy_init(void)
 	l_dbus_set_disconnect_handler(dbus, dbus_disconnect_callback, NULL,
 									NULL);
 
Quoted 11 lines

client/dbus-proxy.c bool dbus_proxy_init(void) · line 864

Quoted 8 lines
client/dbus-proxy.c +1 -2
+	get_managed_objects();
 	if (command_is_interactive_mode())
 		l_dbus_add_service_watch(dbus, IWD_SERVICE,
 						service_appeared_callback,
 						service_disappeared_callback,
 						NULL, NULL);
-	else
-		get_managed_objects();

I don’t understand this change. The whole point is to actually wait for the service to appear.

Yes, but it is a chicken and egg situation: plain DBus activation relies on the
first call on the bus to trigger the activation[1]. The call at the end of
service_appeared_callback() is never going to be reached as interactive iwct is
just waiting having called service_disappeared_callback().

Quoted 22 lines
Quoted 22 lines
client/dbus-proxy.c +0 -0
 	return true;
 }
src/main.c +0 -3
index 989665e4..8e3a5ca7 100644
@@ -191,9 +191,6 @@ static void request_name_callback(struct l_dbus *dbus, bool success,
 		goto fail_exit;
 	}
 
-	if (!l_dbus_object_manager_enable(dbus, "/"))
-		l_warn("Unable to register the ObjectManager");
-
 	if (!l_dbus_object_add_interface(dbus, IWD_BASE_PATH,
 						IWD_DAEMON_INTERFACE,
 						NULL) ||
@@ -240,6 +237,9 @@ static void dbus_ready(void *user_data)
 {
 	struct l_dbus *dbus = user_data;
 
Quoted 6 lines

src/main.c static void dbus_ready(void *user_data) · line 242

Quoted 3 lines
src/main.c +3 -0
+	if (!l_dbus_object_manager_enable(dbus, "/"))
+		l_warn("Unable to register the ObjectManager");
+

This change is unclear to me. Why would I register the ObjectManager if I can’t acquire the name. I don’t get how this is suppose to work.

Without this change, once the name is acquired, dbus still fails to find the
ObjectManager path as it hasn't (yet) been enabled. So the first call to get_managed_objects() fails if it was also the one that caused the service
activation.

Quoted 1 line

This is the right thing to do.

I wondered about the order here too. I know that they are different bindings and
that it is deprecated, so it may well not be the most convincing argument, but
GDBus docs specify this requirement[2] and use it in their examples[3] where
object paths are registered on bus acquisition rather than name acquisition.

Quoted 13 lines
Quoted 13 lines
src/main.c +0 -0
 	l_dbus_name_acquire(dbus, "net.connman.iwd", false, false, false,
 				request_name_callback, NULL);
 
src/net.connman.iwd.service.in renamed from src/net.connman.iwd.service +0 -0
similarity index 77%
rename from src/net.connman.iwd.service
rename to src/net.connman.iwd.service.in
index d8ece4c3..a7cb7edd 100644
@@ -1,5 +1,5 @@

[D-BUS Service]

Quoted 8 lines
Quoted 5 lines

Name=net.connman.iwd

src/net.connman.iwd.service.in renamed from src/net.connman.iwd.service +1 -1
-Exec=/bin/false
+Exec=@libexecdir@/iwd

User=root
SystemdService=iwd.service

This change is not for upstream git tree. Use --disable-systemd-service and then provide your own files in the distro packaging.

Quoted 5 lines

But this isn't about distro specific packaging, I think it is a setup that works
both with systemd or without it. Debian has both systemd and several other inits
available so building with --disabled-systemd-service is not an option.

For things like IWD, I feel DBus activation is definitely the wrong path. It should be a system service of some sort, so it can connect to a network without first being queried by a user manually, and it shouldn't be activated automatically. For example, in case a user accidentally launches iwctl when wpa_supplicant was in use instead, for whatever reason.

You can find the service file we use in Void Linux for IWD in [1]; it should be compatible with any daemontools-like service manager.

[1] https://github.com/void-linux/void-packages/blob/7ba71aeed459e57f2c12cd6e4d1779297ee17550/srcpkgs/iwd/files/iwd/run

Quoted 16 lines

Thanks

Mark

[1]
https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-starting-services

[2]
https://www.freedesktop.org/software/gstreamer-sdk/data/docs/latest/gio/ch30s03.html

[3]
https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gdbus-example-server.c
_______________________________________________
iwd mailing list -- iwd(a)lists.01.org
To unsubscribe send an email to iwd-leave(a)lists.01.org

author
#4 lore raw

Érico,

Quoted 4 lines · Érico Nogueira

For things like IWD, I feel DBus activation is definitely the wrong path. It should be a system service of some sort, so it can connect to a network without first being queried by a user manually, and it shouldn't be activated automatically.

Thanks, but I find this a confusing statement.

AFAIU iwd does use DBus activation currently. The Debian changelog contains this entry:

* Recommend dbus (system bus)
Interaction with iwd happens via dbus, i.e. as used by the iwctl command (or NetworkManager iwd backend).
Packages using D-Bus usually doesn't describe this in their package relationships and implicitly rely on everyone having a bus available. People using iwd however seems to be confused about the lack of a startup script and fails to realize that "dbus activation" is the intended way to start iwd so hopefully making the dbus relationship more explicit will give a hint and help people figure this out.

So, given that DBus activation doesn't require systemd (but can make use of it), I was trying to understand and suggest a fix for why iwd DBus activation doesn't work in the non-systemd case.

Mark