diff options
| author | Kristian Høgsberg <krh@redhat.com> | 2004-05-20 18:45:16 +0000 | 
|---|---|---|
| committer | Kristian Høgsberg <krh@redhat.com> | 2004-05-20 18:45:16 +0000 | 
| commit | 1919d92d850f247d70cb6821724c4908bf70eeda (patch) | |
| tree | 34386861a6674be7204038867a2028083e0dcb9a | |
| parent | ce11c651a07e75c5a78fa66d8294003a65291c89 (diff) | |
	Patch from Jon Trowbridge <trow@ximian.com>:
 	* bus/main.c (setup_reload_pipe): Added.  Creates a pipe and sets
 	up a watch that triggers a config reload when one end of the pipe
 	becomes readable.
 	(signal_handler): Instead of doing the config reload in our SIGHUP
 	handler, just write to the reload pipe and let the associated
 	watch handle the reload when control returns to the main loop.
 	* bus/driver.c (bus_driver_handle_reload_config): Added.
 	Implements a ReloadConfig method for requesting a configuration
 	file reload via the bus driver.
| -rw-r--r-- | ChangeLog | 15 | ||||
| -rw-r--r-- | bus/driver.c | 29 | ||||
| -rw-r--r-- | bus/main.c | 97 | 
3 files changed, 130 insertions, 11 deletions
| @@ -1,3 +1,18 @@ +2004-05-20  Kristian Høgsberg  <krh@redhat.com> + +	Patch from Jon Trowbridge <trow@ximian.com>: +  + 	* bus/main.c (setup_reload_pipe): Added.  Creates a pipe and sets + 	up a watch that triggers a config reload when one end of the pipe + 	becomes readable. + 	(signal_handler): Instead of doing the config reload in our SIGHUP + 	handler, just write to the reload pipe and let the associated + 	watch handle the reload when control returns to the main loop. +  + 	* bus/driver.c (bus_driver_handle_reload_config): Added. + 	Implements a ReloadConfig method for requesting a configuration + 	file reload via the bus driver. +   2004-05-19  Owen Fraser-Green  <owen@discobabe.net>  	* HACKING: Updated release instructions concerning the wiki page. diff --git a/bus/driver.c b/bus/driver.c index a9dddd19..9b444486 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -829,6 +829,32 @@ bus_driver_handle_get_service_owner (DBusConnection *connection,    return FALSE;  } +static dbus_bool_t +bus_driver_handle_reload_config (DBusConnection *connection, +				 BusTransaction *transaction, +				 DBusMessage    *message, +				 DBusError      *error) +{ +  BusContext *context; +  dbus_bool_t retval; + +  _DBUS_ASSERT_ERROR_IS_CLEAR (error); + +  retval = FALSE; + +  context = bus_connection_get_context (connection); +  if (!bus_context_reload_config (context, error)) +    { +      _DBUS_ASSERT_ERROR_IS_SET (error); +      goto out; +    } + +  retval = TRUE; +   + out: +  return retval; +} +  /* For speed it might be useful to sort this in order of   * frequency of use (but doesn't matter with only a few items   * anyhow) @@ -848,7 +874,8 @@ struct    { "ListServices", bus_driver_handle_list_services },    { "AddMatch", bus_driver_handle_add_match },    { "RemoveMatch", bus_driver_handle_remove_match }, -  { "GetServiceOwner", bus_driver_handle_get_service_owner } +  { "GetServiceOwner", bus_driver_handle_get_service_owner }, +  { "ReloadConfig", bus_driver_handle_reload_config }  };  dbus_bool_t @@ -22,6 +22,7 @@   */  #include "bus.h"  #include <dbus/dbus-internals.h> +#include <dbus/dbus-watch.h>  #include <stdio.h>  #include <stdlib.h>  #include <string.h> @@ -30,23 +31,23 @@  static BusContext *context; +static int reload_pipe[2]; +#define RELOAD_READ_END 0 +#define RELOAD_WRITE_END 1 + +  static void  signal_handler (int sig)  { -  DBusError error; +  DBusString str;    switch (sig)      {      case SIGHUP: -      /* FIXME: We shouldn't be reloading the config in the -	 signal handler.  We should use a pipe or something to -	 make the reload happen in the main loop. */ -      dbus_error_init (&error); -      if (!bus_context_reload_config (context, &error)) +      _dbus_string_init_const (&str, "foo"); +      if (!_dbus_write (reload_pipe[RELOAD_WRITE_END], &str, 0, 1))  	{ -	  _dbus_warn ("Unable to reload configuration: %s\n", -		      error.message); -	  dbus_error_free (&error); +	  _dbus_warn ("Unable to write to reload pipe.\n");  	  exit (1);  	}        break; @@ -111,6 +112,80 @@ check_two_pid_descriptors (const DBusString *pid_fd,      }  } +static dbus_bool_t +handle_reload_watch (DBusWatch    *watch, +		     unsigned int  flags, +		     void         *data) +{ +  DBusError error; +  DBusString str; +  _dbus_string_init (&str); +  if (_dbus_read (reload_pipe[RELOAD_READ_END], &str, 1) != 1) +    { +      _dbus_warn ("Couldn't read from reload pipe.\n"); +      exit (1); +    } +  _dbus_string_free (&str); + +  dbus_error_init (&error); +  if (! bus_context_reload_config (context, &error)) +    { +      _dbus_warn ("Unable to reload configuration: %s\n", +		  error.message); +      dbus_error_free (&error); +      exit (1); +    } +  return TRUE; +} + +static dbus_bool_t +reload_watch_callback (DBusWatch    *watch, +		       unsigned int  condition, +		       void         *data) +{ +  return dbus_watch_handle (watch, condition); +} + +static void +setup_reload_pipe (DBusLoop *loop) +{ +  DBusError error; +  DBusWatch *watch; + +  dbus_error_init (&error); + +  if (!_dbus_full_duplex_pipe (&reload_pipe[0], &reload_pipe[1], +			       TRUE, &error)) +    { +      _dbus_warn ("Unable to create reload pipe: %s\n", +		  error.message); +      dbus_error_free (&error); +      exit (1); +    } + +  watch = _dbus_watch_new (reload_pipe[RELOAD_READ_END], +			   DBUS_WATCH_READABLE, TRUE, +			   handle_reload_watch, NULL, NULL); + +  if (watch == NULL) +    { +      _dbus_warn ("Unable to create reload watch: %s\n", +		  error.message); +      dbus_error_free (&error); +      exit (1); +    } + +  if (!_dbus_loop_add_watch (loop, watch, reload_watch_callback, +			     NULL, NULL)) +    { +      _dbus_warn ("Unable to add reload watch to main loop: %s\n", +		  error.message); +      dbus_error_free (&error); +      exit (1); +    } + +} +  int  main (int argc, char **argv)  { @@ -309,7 +384,9 @@ main (int argc, char **argv)        dbus_error_free (&error);        exit (1);      } -   + +  setup_reload_pipe (bus_context_get_loop (context)); +     _dbus_set_signal_handler (SIGHUP, signal_handler);    _dbus_set_signal_handler (SIGTERM, signal_handler); | 
