--- dbus-1.2.28/bus/main.c-orig 2011-06-24 11:27:11.494336463 -0500 +++ dbus-1.2.28/bus/main.c 2011-06-24 15:23:01.929249553 -0500 @@ -41,9 +41,17 @@ static int reload_pipe[2]; static void close_reload_pipe (void); +typedef enum + { + ACTION_UNSET = 'u', + ACTION_RELOAD = 'r', + ACTION_QUIT = 'q' + } SignalAction; + static void signal_handler (int sig) { + char action[2]; switch (sig) { @@ -55,7 +63,9 @@ signal_handler (int sig) case SIGHUP: { DBusString str; - _dbus_string_init_const (&str, "foo"); + action[0] = ACTION_RELOAD; + action[1] = '\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)) { @@ -65,6 +75,20 @@ signal_handler (int sig) } break; #endif + case SIGTERM: + { + DBusString str; + action[0] = ACTION_QUIT; + action[1] = '\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)) + { + _dbus_warn ("Unable to write to reload pipe.\n"); + close_reload_pipe (); + } + } + break; } } @@ -153,6 +177,8 @@ handle_reload_watch (DBusWatch *watch { DBusError error; DBusString str; + char *action_str; + SignalAction action; while (!_dbus_string_init (&str)) _dbus_wait_for_memory (); @@ -164,6 +190,17 @@ handle_reload_watch (DBusWatch *watch close_reload_pipe (); return TRUE; } + + action = ACTION_UNSET; + action_str = _dbus_string_get_data (&str); + if (action_str != NULL && action_str[0] == ACTION_RELOAD) + { + action = ACTION_RELOAD; + } + else if (action_str != NULL && action_str[0] == ACTION_QUIT) + { + action = ACTION_QUIT; + } _dbus_string_free (&str); /* this can only fail if we don't understand the config file @@ -171,15 +208,23 @@ handle_reload_watch (DBusWatch *watch * loaded config. */ dbus_error_init (&error); - if (! bus_context_reload_config (context, &error)) + if (action == ACTION_RELOAD) { - _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); + 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); + } } + else if (action == ACTION_QUIT) + { + _dbus_loop_quit (bus_context_get_loop (context)); + } + return TRUE; } @@ -461,6 +506,7 @@ main (int argc, char **argv) setup_reload_pipe (bus_context_get_loop (context)); + _dbus_set_signal_handler (SIGTERM, signal_handler); #ifdef SIGHUP _dbus_set_signal_handler (SIGHUP, signal_handler); #endif