Commit a1c90cac authored by Simon McVittie's avatar Simon McVittie

Merge branch 'dbus-1.4'

Conflicts:
	bus/main.c
parents d6ad37c3 6c6ae1ef
......@@ -49,10 +49,15 @@ static int reload_pipe[2];
static void close_reload_pipe (DBusWatch **);
#ifdef DBUS_UNIX
typedef enum
{
ACTION_RELOAD = 'r',
ACTION_QUIT = 'q'
} SignalAction;
static void
signal_handler (int sig)
{
switch (sig)
{
#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX
......@@ -63,7 +68,9 @@ signal_handler (int sig)
case SIGHUP:
{
DBusString str;
_dbus_string_init_const (&str, "foo");
char action[2] = { ACTION_RELOAD, '\0' };
_dbus_string_init_const (&str, action);
if ((reload_pipe[RELOAD_WRITE_END] > 0) &&
!_dbus_write_socket (reload_pipe[RELOAD_WRITE_END], &str, 0, 1))
{
......@@ -88,6 +95,28 @@ signal_handler (int sig)
}
break;
#endif
case SIGTERM:
{
DBusString str;
char action[2] = { ACTION_QUIT, '\0' };
_dbus_string_init_const (&str, action);
if ((reload_pipe[RELOAD_WRITE_END] < 0) ||
!_dbus_write_socket (reload_pipe[RELOAD_WRITE_END], &str, 0, 1))
{
/* If we can't write to the socket, dying seems a more
* important response to SIGTERM than cleaning up sockets,
* so we exit. We'd use exit(), but that's not async-signal-safe,
* so we'll have to resort to _exit(). */
static const char message[] =
"Unable to write termination signal to pipe - buffer full?\n"
"Will exit instead.\n";
write (STDERR_FILENO, message, strlen (message));
_exit (1);
}
}
break;
}
}
#endif /* DBUS_UNIX */
......@@ -190,6 +219,8 @@ handle_reload_watch (DBusWatch *watch,
{
DBusError error;
DBusString str;
char *action_str;
char action = '\0';
while (!_dbus_string_init (&str))
_dbus_wait_for_memory ();
......@@ -201,6 +232,12 @@ handle_reload_watch (DBusWatch *watch,
close_reload_pipe (&watch);
return TRUE;
}
action_str = _dbus_string_get_data (&str);
if (action_str != NULL)
{
action = action_str[0];
}
_dbus_string_free (&str);
/* this can only fail if we don't understand the config file
......@@ -208,15 +245,42 @@ handle_reload_watch (DBusWatch *watch,
* loaded config.
*/
dbus_error_init (&error);
if (! bus_context_reload_config (context, &error))
switch (action)
{
_DBUS_ASSERT_ERROR_IS_SET (&error);
_dbus_assert (dbus_error_has_name (&error, DBUS_ERROR_FAILED) ||
dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY));
_dbus_warn ("Unable to reload configuration: %s\n",
error.message);
dbus_error_free (&error);
case ACTION_RELOAD:
if (! bus_context_reload_config (context, &error))
{
_DBUS_ASSERT_ERROR_IS_SET (&error);
_dbus_assert (dbus_error_has_name (&error, DBUS_ERROR_FAILED) ||
dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY));
_dbus_warn ("Unable to reload configuration: %s\n",
error.message);
dbus_error_free (&error);
}
break;
case ACTION_QUIT:
{
DBusLoop *loop;
/*
* On OSs without abstract sockets, we want to quit
* gracefully rather than being killed by SIGTERM,
* so that DBusServer gets a chance to clean up the
* sockets from the filesystem. fd.o #38656
*/
loop = bus_context_get_loop (context);
if (loop != NULL)
{
_dbus_loop_quit (loop);
}
}
break;
default:
break;
}
return TRUE;
}
......@@ -527,6 +591,8 @@ main (int argc, char **argv)
/* POSIX signals are Unix-specific, and _dbus_set_signal_handler is
* unimplemented (and probably unimplementable) on Windows, so there's
* no point in trying to make the handler portable to non-Unix. */
_dbus_set_signal_handler (SIGTERM, signal_handler);
#ifdef SIGHUP
_dbus_set_signal_handler (SIGHUP, signal_handler);
#endif
......
......@@ -251,11 +251,18 @@ _dbus_server_new_for_domain_socket (const char *path,
goto failed_0;
}
path_copy = _dbus_strdup (path);
if (path_copy == NULL)
if (abstract)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto failed_0;
path_copy = NULL;
}
else
{
path_copy = _dbus_strdup (path);
if (path_copy == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto failed_0;
}
}
listen_fd = _dbus_listen_unix_socket (path, abstract, error);
......@@ -273,7 +280,8 @@ _dbus_server_new_for_domain_socket (const char *path,
goto failed_2;
}
_dbus_server_socket_own_filename(server, path_copy);
if (path_copy != NULL)
_dbus_server_socket_own_filename(server, path_copy);
_dbus_string_free (&address);
......
......@@ -83,6 +83,10 @@ shell_test_LDADD = libdbus-testutils.la
spawn_test_CPPFLAGS = $(static_cppflags)
spawn_test_LDADD = $(top_builddir)/dbus/libdbus-internal.la
test_refs_SOURCES = internals/refs.c
test_refs_CPPFLAGS = $(static_cppflags)
test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS)
EXTRA_DIST = dbus-test-runner
testexecdir = $(libdir)/dbus-1.0/test
......@@ -95,6 +99,7 @@ installable_tests = \
test-dbus-daemon-eavesdrop \
test-loopback \
test-marshal \
test-refs \
test-relay \
$(NULL)
......
This diff is collapsed.
......@@ -137,12 +137,15 @@ test_connect (Fixture *f,
gconstpointer data G_GNUC_UNUSED)
{
dbus_bool_t have_mem;
char *address;
g_assert (f->left_server_conn == NULL);
g_assert (f->right_server_conn == NULL);
f->left_client_conn = dbus_connection_open_private (
dbus_server_get_address (f->server), &f->e);
address = dbus_server_get_address (f->server);
g_assert (address != NULL);
f->left_client_conn = dbus_connection_open_private (address, &f->e);
assert_no_error (&f->e);
g_assert (f->left_client_conn != NULL);
dbus_connection_setup_with_g_main (f->left_client_conn, NULL);
......@@ -153,12 +156,13 @@ test_connect (Fixture *f,
g_main_context_iteration (NULL, TRUE);
}
f->right_client_conn = dbus_connection_open_private (
dbus_server_get_address (f->server), &f->e);
f->right_client_conn = dbus_connection_open_private (address, &f->e);
assert_no_error (&f->e);
g_assert (f->right_client_conn != NULL);
dbus_connection_setup_with_g_main (f->right_client_conn, NULL);
dbus_free (address);
while (f->right_server_conn == NULL)
{
g_print (".");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment