summaryrefslogtreecommitdiffstats
path: root/bus
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-04-06 18:03:03 +0000
committerHavoc Pennington <hp@redhat.com>2003-04-06 18:03:03 +0000
commite45e4382274149ca60c11f068ccca719f3598074 (patch)
tree5fda8d67759828cd7b8e2f1c9a8f4d66f63b737f /bus
parent2618e1a973b816ab59422035046111360ab5aa74 (diff)
2003-04-06 Havoc Pennington <hp@pobox.com>
* bus/bus.c (bus_context_new): fix wrong handling of server_data_slot_unref() in the error case. * dbus/dbus-internals.h (_dbus_assert): change so it passes "(condition) != 0" to _dbus_real_assert so that "_dbus_assert (pointer)" doesn't cause a warning * bus/main.c (main): accept --print-address option to print out the message bus address * dbus/dbus-sysdeps.c (_dbus_generate_random_ascii): export this * dbus/dbus-transport.c (_dbus_transport_open): special error for "tmpdir" option to unix: address on client side * dbus/dbus-server.c (dbus_server_listen): handle "tmpdir" option to unix: address * configure.in (TEST_SOCKET_DIR): locate a temporary directory we can use to create sockets in the test suite. * bus/main.c (signal_handler): on SIGTERM, exit the daemon cleanly. To be used for testing. * dbus/dbus-spawn.c (babysit): use _dbus_set_signal_handler() * dbus/dbus-sysdeps.c (_dbus_set_signal_handler): new * dbus/dbus-server-debug-pipe.c (_dbus_transport_debug_pipe_new): handle trying to call this when there's no servers active
Diffstat (limited to 'bus')
-rw-r--r--bus/bus.c20
-rw-r--r--bus/bus.h1
-rw-r--r--bus/main.c134
-rw-r--r--bus/session.conf.in14
4 files changed, 150 insertions, 19 deletions
diff --git a/bus/bus.c b/bus/bus.c
index 6c5a3f28..e426706a 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -107,7 +107,10 @@ server_get_context (DBusServer *server)
bd = BUS_SERVER_DATA (server);
if (bd == NULL)
- return NULL;
+ {
+ server_data_slot_unref ();
+ return NULL;
+ }
context = bd->context;
@@ -314,7 +317,7 @@ bus_context_new (const DBusString *config_file,
BUS_SET_OOM (error);
return NULL;
}
-
+
if (!server_data_slot_ref ())
{
BUS_SET_OOM (error);
@@ -339,6 +342,12 @@ bus_context_new (const DBusString *config_file,
context->refcount = 1;
+ /* we need another ref of the server data slot for the context
+ * to own
+ */
+ if (!server_data_slot_ref ())
+ _dbus_assert_not_reached ("second ref of server data slot failed");
+
#ifdef DBUS_BUILD_TESTS
context->activation_timeout = 6000; /* 6 seconds */
#else
@@ -542,6 +551,7 @@ bus_context_new (const DBusString *config_file,
bus_config_parser_unref (parser);
_dbus_string_free (&full_address);
dbus_free_string_array (auth_mechanisms);
+ server_data_slot_unref ();
return context;
@@ -678,6 +688,12 @@ bus_context_get_type (BusContext *context)
return context->type;
}
+const char*
+bus_context_get_address (BusContext *context)
+{
+ return context->address;
+}
+
BusRegistry*
bus_context_get_registry (BusContext *context)
{
diff --git a/bus/bus.h b/bus/bus.h
index 8b26cffc..aa9f848d 100644
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -46,6 +46,7 @@ void bus_context_shutdown (BusContext *context)
void bus_context_ref (BusContext *context);
void bus_context_unref (BusContext *context);
const char* bus_context_get_type (BusContext *context);
+const char* bus_context_get_address (BusContext *context);
BusRegistry* bus_context_get_registry (BusContext *context);
BusConnections* bus_context_get_connections (BusContext *context);
BusActivation* bus_context_get_activation (BusContext *context);
diff --git a/bus/main.c b/bus/main.c
index 099219c3..119520ff 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -26,11 +26,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <signal.h>
+#include <errno.h>
+
+static BusContext *context;
+static dbus_bool_t got_sighup = FALSE;
+
+static void
+signal_handler (int sig)
+{
+ switch (sig)
+ {
+ case SIGHUP:
+ got_sighup = TRUE;
+ case SIGTERM:
+ bus_loop_quit (bus_context_get_loop (context));
+ break;
+ }
+}
static void
usage (void)
{
- fprintf (stderr, "dbus-daemon-1 [--session] [--system] [--config-file=FILE] [--version]\n");
+ fprintf (stderr, "dbus-daemon-1 [--version] [--session] [--system] [--config-file=FILE] [--print-address[=descriptor]]\n");
exit (1);
}
@@ -57,17 +75,36 @@ check_two_config_files (const DBusString *config_file,
}
}
+static void
+check_two_addr_descriptors (const DBusString *addr_fd,
+ const char *extra_arg)
+{
+ if (_dbus_string_get_length (addr_fd) > 0)
+ {
+ fprintf (stderr, "--%s specified but printing address to %s already requested\n",
+ extra_arg, _dbus_string_get_const_data (addr_fd));
+ exit (1);
+ }
+}
+
int
main (int argc, char **argv)
{
- BusContext *context;
DBusError error;
DBusString config_file;
+ DBusString addr_fd;
const char *prev_arg;
+ int print_addr_fd;
int i;
-
+ dbus_bool_t print_address;
+
if (!_dbus_string_init (&config_file))
return 1;
+
+ if (!_dbus_string_init (&addr_fd))
+ return 1;
+
+ print_address = FALSE;
prev_arg = NULL;
i = 1;
@@ -117,6 +154,32 @@ main (int argc, char **argv)
}
else if (strcmp (arg, "--config-file") == 0)
; /* wait for next arg */
+ else if (strstr (arg, "--print-address=") == arg)
+ {
+ const char *desc;
+
+ check_two_addr_descriptors (&addr_fd, "print-address");
+
+ desc = strchr (arg, '=');
+ ++desc;
+
+ if (!_dbus_string_append (&addr_fd, desc))
+ exit (1);
+
+ print_address = TRUE;
+ }
+ else if (prev_arg &&
+ strcmp (prev_arg, "--print-address") == 0)
+ {
+ check_two_addr_descriptors (&addr_fd, "print-address");
+
+ if (!_dbus_string_append (&addr_fd, arg))
+ exit (1);
+
+ print_address = TRUE;
+ }
+ else if (strcmp (arg, "--print-address") == 0)
+ print_address = TRUE; /* and we'll get the next arg if appropriate */
else
usage ();
@@ -130,6 +193,27 @@ main (int argc, char **argv)
fprintf (stderr, "No configuration file specified.\n");
usage ();
}
+
+ print_addr_fd = -1;
+ if (print_address)
+ {
+ print_addr_fd = 1; /* stdout */
+ if (_dbus_string_get_length (&addr_fd) > 0)
+ {
+ long val;
+ int end;
+ if (!_dbus_string_parse_int (&addr_fd, 0, &val, &end) ||
+ end != _dbus_string_get_length (&addr_fd) ||
+ val < 0 || val > _DBUS_INT_MAX)
+ {
+ fprintf (stderr, "Invalid file descriptor: \"%s\"\n",
+ _dbus_string_get_const_data (&addr_fd));
+ exit (1);
+ }
+
+ print_addr_fd = val;
+ }
+ }
dbus_error_init (&error);
context = bus_context_new (&config_file, &error);
@@ -139,14 +223,56 @@ main (int argc, char **argv)
_dbus_warn ("Failed to start message bus: %s\n",
error.message);
dbus_error_free (&error);
- return 1;
+ exit (1);
}
+
+ /* Note that we don't know whether the print_addr_fd is
+ * one of the sockets we're using to listen on, or some
+ * other random thing. But I think the answer is "don't do
+ * that then"
+ */
+ if (print_addr_fd >= 0)
+ {
+ DBusString addr;
+ const char *a = bus_context_get_address (context);
+ int bytes;
+
+ _dbus_assert (a != NULL);
+ if (!_dbus_string_init (&addr) ||
+ !_dbus_string_append (&addr, a) ||
+ !_dbus_string_append (&addr, "\n"))
+ exit (1);
+
+ bytes = _dbus_string_get_length (&addr);
+ if (_dbus_write (print_addr_fd, &addr, 0, bytes) != bytes)
+ {
+ _dbus_warn ("Failed to print message bus address: %s\n",
+ _dbus_strerror (errno));
+ exit (1);
+ }
+
+ if (print_addr_fd > 2)
+ _dbus_close (print_addr_fd, NULL);
+
+ _dbus_string_free (&addr);
+ }
+
+ /* FIXME we have to handle this properly below _dbus_set_signal_handler (SIGHUP, signal_handler); */
+ _dbus_set_signal_handler (SIGTERM, signal_handler);
_dbus_verbose ("We are on D-Bus...\n");
bus_loop_run (bus_context_get_loop (context));
bus_context_shutdown (context);
bus_context_unref (context);
+
+ /* If we exited on TERM we just exit, if we exited on
+ * HUP we restart the daemon.
+ */
+ if (got_sighup)
+ {
+ /* FIXME execv (argv) basically */
+ }
return 0;
}
diff --git a/bus/session.conf.in b/bus/session.conf.in
index 28478955..d430d990 100644
--- a/bus/session.conf.in
+++ b/bus/session.conf.in
@@ -8,19 +8,7 @@
<!-- Our well-known bus type, don't change this -->
<type>session</type>
- <!-- FIXME - this is fairly complicated to fix.
- Propose the following:
- - add "unix:tmpdir=/tmp" which means unix domain transport
- creates a socket with a random secure name
- - add dbus_server_get_address() that gets the actual
- server address
- - add command line option or env variable to the daemon
- causing it to print its list of addresses to a given
- file descriptor
- - session manager or whatever launches the session bus
- reads the address from there and sets the env variable
- -->
- <listen>unix:path=/tmp/foobar</listen>
+ <listen>unix:tmpdir=@DBUS_SESSION_SOCKET_DIR@</listen>
<policy context="default">
<!-- Allow everything -->