summaryrefslogtreecommitdiff
path: root/bus
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2021-11-11 10:01:29 +0100
committerRalf Habacker <ralf.habacker@freenet.de>2021-11-23 08:38:14 +0100
commit79df3d2811343eadcf2f95bacb372729fde1fddd (patch)
tree3c6c3a97b474e79db7903071fb1553a343eb075d /bus
parent3f7c36f4b1d290eeb115921820ba945fc467cad3 (diff)
downloaddbus-79df3d2811343eadcf2f95bacb372729fde1fddd.tar.gz
tools/dbus-run-session: fix race between manual and automatically started dbus-daemon on Windows
dbus-run-session starts a dbus-daemon before the client application. We must avoid letting the application try to connect before the dbus-daemon's DBusServer is listening for connections. In the Unix implementation, we already achieved this via the --print-address option. If the client tried to connect too soon, the server would not yet be listening and the client would fail. In the Windows implementation, we communicate the bus address to the client application as an autolaunch: address, so if the client tried to connect too soon, it would autolaunch a new dbus-daemon instead of using the one that it was intended to use. We can avoid this by using a new option to pass in a Windows event object, which will be set when the server has started and is ready to process connections. Fixes #297
Diffstat (limited to 'bus')
-rw-r--r--bus/bus.c13
-rw-r--r--bus/bus.h1
-rw-r--r--bus/main.c26
-rw-r--r--bus/test.c2
4 files changed, 40 insertions, 2 deletions
diff --git a/bus/bus.c b/bus/bus.c
index db20bbbc..ea508d72 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -764,11 +764,13 @@ process_config_postinit (BusContext *context,
return TRUE;
}
+/* Takes ownership of print_addr_pipe fds, print_pid_pipe fds and ready_event_handle */
BusContext*
bus_context_new (const DBusString *config_file,
BusContextFlags flags,
DBusPipe *print_addr_pipe,
DBusPipe *print_pid_pipe,
+ void *ready_event_handle,
const DBusString *address,
DBusError *error)
{
@@ -891,6 +893,17 @@ bus_context_new (const DBusString *config_file,
_dbus_string_free (&addr);
}
+#ifdef DBUS_WIN
+ if (ready_event_handle != NULL)
+ {
+ _dbus_verbose ("Notifying that we are ready to receive connections (event handle=%p)\n", ready_event_handle);
+ if (!_dbus_win_event_set (ready_event_handle, error))
+ goto failed;
+ if (!_dbus_win_event_free (ready_event_handle, error))
+ goto failed;
+ }
+#endif
+
context->connections = bus_connections_new (context);
if (context->connections == NULL)
{
diff --git a/bus/bus.h b/bus/bus.h
index 99625ca3..b4411180 100644
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -88,6 +88,7 @@ BusContext* bus_context_new (const DBusStri
BusContextFlags flags,
DBusPipe *print_addr_pipe,
DBusPipe *print_pid_pipe,
+ void *ready_event_handle,
const DBusString *address,
DBusError *error);
dbus_bool_t bus_context_reload_config (BusContext *context,
diff --git a/bus/main.c b/bus/main.c
index 84f601b3..5f756d5c 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -48,6 +48,10 @@
static BusContext *context;
+#ifdef DBUS_WIN
+#include <dbus/dbus-sysdeps-win.h>
+#endif
+
#ifdef DBUS_UNIX
/* Despite its name and its unidirectional nature, this is actually
@@ -163,6 +167,9 @@ usage (void)
" [--syslog]"
" [--syslog-only]"
" [--nofork]"
+#ifdef DBUS_WIN
+ " [--ready-event-handle=value]"
+#endif
#ifdef DBUS_UNIX
" [--fork]"
" [--systemd-activation]"
@@ -403,6 +410,8 @@ main (int argc, char **argv)
dbus_bool_t print_address;
dbus_bool_t print_pid;
BusContextFlags flags;
+ void *ready_event_handle;
+
#ifdef DBUS_UNIX
const char *error_str;
@@ -428,6 +437,7 @@ main (int argc, char **argv)
* to inherit fds we might have inherited from our caller. */
_dbus_fd_set_all_close_on_exec ();
#endif
+ ready_event_handle = NULL;
if (!_dbus_string_init (&config_file))
return 1;
@@ -619,6 +629,20 @@ main (int argc, char **argv)
{
print_pid = TRUE; /* and we'll get the next arg if appropriate */
}
+#ifdef DBUS_WIN
+ else if (strstr (arg, "--ready-event-handle=") == arg)
+ {
+ const char *desc;
+ desc = strchr (arg, '=');
+ _dbus_assert (desc != NULL);
+ ++desc;
+ if (sscanf (desc, "%p", &ready_event_handle) != 1)
+ {
+ fprintf (stderr, "%s specified, but invalid handle provided\n", arg);
+ exit (1);
+ }
+ }
+#endif
else
{
usage ();
@@ -693,7 +717,7 @@ main (int argc, char **argv)
dbus_error_init (&error);
context = bus_context_new (&config_file, flags,
- &print_addr_pipe, &print_pid_pipe,
+ &print_addr_pipe, &print_pid_pipe, ready_event_handle,
_dbus_string_get_length(&address) > 0 ? &address : NULL,
&error);
_dbus_string_free (&config_file);
diff --git a/bus/test.c b/bus/test.c
index 42651e77..8d413fb5 100644
--- a/bus/test.c
+++ b/bus/test.c
@@ -296,7 +296,7 @@ bus_context_new_test (const DBusString *test_data_dir,
}
dbus_error_init (&error);
- context = bus_context_new (&config_file, BUS_CONTEXT_FLAG_NONE, NULL, NULL, NULL, &error);
+ context = bus_context_new (&config_file, BUS_CONTEXT_FLAG_NONE, NULL, NULL, NULL, NULL, &error);
if (context == NULL)
{
_DBUS_ASSERT_ERROR_IS_SET (&error);