dbus/bus Makefile.am, 1.36, 1.37 bus.c, 1.62, 1.63 config-parser.c, 1.41, 1.42 config-parser.h, 1.17, 1.18 dir-watch.c, NONE, 1.1 dir-watch.h, NONE, 1.1 main.c, 1.30, 1.31

David Zeuthen david at freedesktop.org
Tue Jun 14 19:31:41 PDT 2005


Update of /cvs/dbus/dbus/bus
In directory gabe:/tmp/cvs-serv29978/bus

Modified Files:
	Makefile.am bus.c config-parser.c config-parser.h main.c 
Added Files:
	dir-watch.c dir-watch.h 
Log Message:
2005-06-14  David Zeuthen  <davidz at redhat.com>

        * bus/bus.c (process_config_every_time): Drop existing conf-dir
        watches (if applicable) and add new watches

        * bus/main.c (signal_handler): Handle SIGIO if using D_NOTIFY
        (main): Setup SIGIO signal handler if using D_NOTIFY

        * bus/config-parser.h: Add prototype bus_config_parser_get_conf_dirs

        * bus/config-parser.c (struct BusConfigParser): Add conf_dirs list
        (merge_included): Also merge conf_dirs list
        (bus_config_parser_unref): Clear conf_dirs list
        (include_dir): Add directory to conf_dirs list
        (bus_config_parser_get_conf_dirs): New function

        * bus/dir-watch.[ch]: New files

        * bus/Makefile.am (BUS_SOURCES): Add dir-watch.[ch]

        * configure.in: Add checks for D_NOTIFY on Linux



Index: Makefile.am
===================================================================
RCS file: /cvs/dbus/dbus/bus/Makefile.am,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- Makefile.am	17 Mar 2005 17:48:29 -0000	1.36
+++ Makefile.am	15 Jun 2005 02:31:38 -0000	1.37
@@ -36,6 +36,8 @@
 	connection.h				\
 	desktop-file.c				\
 	desktop-file.h				\
+	dir-watch.c				\
+	dir-watch.h				\
 	dispatch.c				\
 	dispatch.h				\
 	driver.c				\

Index: bus.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/bus.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- bus.c	2 Jun 2005 17:41:04 -0000	1.62
+++ bus.c	15 Jun 2005 02:31:38 -0000	1.63
@@ -30,6 +30,7 @@
 #include "config-parser.h"
 #include "signals.h"
 #include "selinux.h"
+#include "dir-watch.h"
 #include <dbus/dbus-list.h>
 #include <dbus/dbus-hash.h>
 #include <dbus/dbus-internals.h>
@@ -478,6 +479,15 @@
       goto failed;
     }
 
+  /* Drop existing conf-dir watches (if applicable) and watch all conf directories */
+
+  if (is_reload)
+    bus_drop_all_directory_watches ();
+
+  _dbus_list_foreach (bus_config_parser_get_conf_dirs (parser),
+		      (DBusForeachFunction) bus_watch_directory,
+		      NULL);
+
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   retval = TRUE;
 
@@ -720,6 +730,7 @@
       _DBUS_ASSERT_ERROR_IS_SET (error);
       goto failed;
     }
+
   if (parser != NULL)
     bus_config_parser_unref (parser);
   

Index: config-parser.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/config-parser.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- config-parser.c	14 Apr 2005 15:10:22 -0000	1.41
+++ config-parser.c	15 Jun 2005 02:31:38 -0000	1.42
@@ -115,6 +115,8 @@
 
   DBusList *service_dirs; /**< Directories to look for services in */
 
+  DBusList *conf_dirs;   /**< Directories to look for policy configuration in */
+
   BusPolicy *policy;     /**< Security policy */
 
   BusLimits limits;      /**< Limits */
@@ -322,6 +324,9 @@
 
   while ((link = _dbus_list_pop_first_link (&included->service_dirs)))
     _dbus_list_append_link (&parser->service_dirs, link);
+
+  while ((link = _dbus_list_pop_first_link (&included->conf_dirs)))
+    _dbus_list_append_link (&parser->conf_dirs, link);
   
   return TRUE;
 }
@@ -468,6 +473,12 @@
 
       _dbus_list_clear (&parser->service_dirs);
 
+      _dbus_list_foreach (&parser->conf_dirs,
+                          (DBusForeachFunction) dbus_free,
+                          NULL);
+
+      _dbus_list_clear (&parser->conf_dirs);
+
       _dbus_list_foreach (&parser->mechanisms,
                           (DBusForeachFunction) dbus_free,
                           NULL);
@@ -1965,6 +1976,7 @@
   dbus_bool_t retval;
   DBusError tmp_error;
   DBusDirIter *dir;
+  char *s;
   
   if (!_dbus_string_init (&filename))
     {
@@ -2021,7 +2033,21 @@
       dbus_move_error (&tmp_error, error);
       goto failed;
     }
-  
+
+
+  if (!_dbus_string_copy_data (dirname, &s))
+    {
+      BUS_SET_OOM (error);
+      goto failed;
+    }
+
+  if (!_dbus_list_append (&parser->conf_dirs, s))
+    {
+      dbus_free (s);
+      BUS_SET_OOM (error);
+      goto failed;
+    }
+
   retval = TRUE;
   
  failed:
@@ -2358,6 +2384,12 @@
   return &parser->service_dirs;
 }
 
+DBusList**
+bus_config_parser_get_conf_dirs (BusConfigParser *parser)
+{
+  return &parser->conf_dirs;
+}
+
 dbus_bool_t
 bus_config_parser_get_fork (BusConfigParser   *parser)
 {

Index: config-parser.h
===================================================================
RCS file: /cvs/dbus/dbus/bus/config-parser.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- config-parser.h	7 Nov 2004 17:05:19 -0000	1.17
+++ config-parser.h	15 Jun 2005 02:31:38 -0000	1.18
@@ -67,6 +67,7 @@
 dbus_bool_t bus_config_parser_get_fork         (BusConfigParser *parser);
 const char* bus_config_parser_get_pidfile      (BusConfigParser *parser);
 DBusList**  bus_config_parser_get_service_dirs (BusConfigParser *parser);
+DBusList**  bus_config_parser_get_conf_dirs    (BusConfigParser *parser);
 BusPolicy*  bus_config_parser_steal_policy     (BusConfigParser *parser);
 void        bus_config_parser_get_limits       (BusConfigParser *parser,
                                                 BusLimits       *limits);
@@ -81,5 +82,4 @@
                                   const BusConfigParser *parent,
                                   DBusError             *error);
 
-
 #endif /* BUS_CONFIG_PARSER_H */

--- NEW FILE: dir-watch.c ---
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dir-watch.c  OS specific directory change notification for message bus
 *
 * Copyright (C) 2003 Red Hat, Inc.
 *
 * Licensed under the Academic Free License version 2.1
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <config.h>

#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX 
#define _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#endif /* DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX */

#include <dbus/dbus-internals.h>
#include "dir-watch.h"


/* D_NOTIFY is available on Linux 2.4 or greater - the actual SIGIO signal is handled in main.c:signal_handler() */
#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX 

#define MAX_DIRS_TO_WATCH 128

/* use a static array to avoid handling OOM */
static int fds[MAX_DIRS_TO_WATCH];
static int num_fds = 0;

void
bus_watch_directory (const char *dir, void *userdata)
{
  int fd;

  _dbus_assert (dir != NULL);

  if (num_fds >= MAX_DIRS_TO_WATCH )
    {
      _dbus_warn ("Cannot watch config directory '%s'. Already watching %d directories\n", dir, MAX_DIRS_TO_WATCH);
      goto out;
    }

  fd = open (dir, O_RDONLY);
  if (fd < 0)
    {
      _dbus_warn ("Cannot open directory '%s'; error '%s'\n", dir, _dbus_strerror (errno));
      goto out;
    }

  if (fcntl (fd, F_NOTIFY, DN_DELETE|DN_RENAME|DN_MODIFY) == -1)
    {
      _dbus_warn ("Cannot setup D_NOTIFY for '%s' error '%s'\n", dir, _dbus_strerror (errno));
      close (fd);
      goto out;
    }
  
  fds[num_fds++] = fd;
  _dbus_verbose ("Added watch on config directory '%s'\n", dir);

 out:
  ;
}

void 
bus_drop_all_directory_watches (void)
{
  _dbus_verbose ("Dropping all watches on config directories\n");

  int i;
  
  for (i = 0; i < num_fds; i++)
    {
      if (close (fds[i]) != 0)
	{
	  _dbus_verbose ("Error closing fd %d for config directory watch\n", fds[i]);
	}
    }
  
  num_fds = 0;
}

#else /* fallback to NOP */

void 
bus_drop_all_directory_watches (void)
{
}

void
bus_watch_directory (const char *dir, void *userdata)
{
}

#endif

--- NEW FILE: dir-watch.h ---
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dir-watch.h  Watch directories
 *
 * Copyright (C) 2005 Red Hat, Inc.
 *
 * Licensed under the Academic Free License version 2.1
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef DIR_WATCH_H
#define DIR_WATCH_H

/* setup a watch on a directory (OS dependent, may be a NOP) */
void bus_watch_directory (const char *directory, void *userdata);

/* drop all the watches previously set up by bus_config_watch_directory (OS dependent, may be a NOP) */
void bus_drop_all_directory_watches (void);

#endif /* DIR_WATCH_H */

Index: main.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/main.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- main.c	18 Jan 2005 22:20:38 -0000	1.30
+++ main.c	15 Jun 2005 02:31:38 -0000	1.31
@@ -44,6 +44,10 @@
 
   switch (sig)
     {
+#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX 
+    case SIGIO: 
+      /* explicit fall-through */
+#endif /* DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX  */
     case SIGHUP:
       _dbus_string_init_const (&str, "foo");
       if (!_dbus_write (reload_pipe[RELOAD_WRITE_END], &str, 0, 1))
@@ -397,9 +401,12 @@
     }
 
   setup_reload_pipe (bus_context_get_loop (context));
- 
+
   _dbus_set_signal_handler (SIGHUP, signal_handler);
   _dbus_set_signal_handler (SIGTERM, signal_handler);
+#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX 
+  _dbus_set_signal_handler (SIGIO, signal_handler);
+#endif /* DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX */
   
   _dbus_verbose ("We are on D-Bus...\n");
   _dbus_loop_run (bus_context_get_loop (context));



More information about the dbus-commit mailing list