hal: Branch 'master'
David Zeuthen
david at kemper.freedesktop.org
Fri Apr 6 18:32:30 PDT 2007
hald/device_info.c | 20 +-------
hald/hald.c | 4 -
hald/linux/osspec.c | 120 --------------------------------------------------
hald/mmap_cache.c | 123 ++++++++++++++++++++++++++++++++--------------------
hald/mmap_cache.h | 2
hald/osspec.h | 3 -
6 files changed, 84 insertions(+), 188 deletions(-)
New commits:
diff-tree 1d6a396237a1fc50493a8c11e2e429c61574eda5 (from 8c1b67d8dd16b69e4b4be7b6ae8cebf65b90aeb3)
Author: David Zeuthen <davidz at redhat.com>
Date: Fri Apr 6 21:32:19 2007 -0400
use the new file monitor abstraction to watch fdi directories
diff --git a/hald/device_info.c b/hald/device_info.c
index 8355011..baee95c 100644
--- a/hald/device_info.c
+++ b/hald/device_info.c
@@ -973,19 +973,14 @@ rules_match_and_merge_device (void *fdi_
}
}
-static gboolean fdi_cache_invalidated = FALSE;
-
-
/* merge the device info type, either preprobe, info or policy */
gboolean
di_search_and_merge (HalDevice *d, DeviceInfoType type){
struct cache_header *header = (struct cache_header*) RULES_PTR(0);
- if (fdi_cache_invalidated) {
- /* make sure our fdi rule cache is up to date */
- if (di_cache_coherency_check ())
- di_rules_init ();
- fdi_cache_invalidated = FALSE;
+ /* make sure our fdi rule cache is up to date */
+ if (di_cache_coherency_check (FALSE)) {
+ di_rules_init ();
}
switch (type) {
@@ -1028,12 +1023,3 @@ di_search_and_merge (HalDevice *d, Devic
return TRUE;
}
-
-/* Called by OS specific code to tell that the fdi cache is invalid */
-void
-osspec_fdi_cache_invalid (void)
-{
- HAL_INFO (("invalidating fdi cache"));
- fdi_cache_invalidated = TRUE;
-}
-
diff --git a/hald/hald.c b/hald/hald.c
index bf9a889..02e6645 100644
--- a/hald/hald.c
+++ b/hald/hald.c
@@ -768,8 +768,8 @@ main (int argc, char *argv[])
hald_is_initialising = TRUE;
- /* make sure our fdi rule cache is up to date */
- di_cache_coherency_check();
+ /* make sure our fdi rule cache is up to date and setup file monitoring */
+ di_cache_coherency_check(TRUE);
/* initialize operating system specific parts */
osspec_init ();
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 46aa9fa..b8900d5 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -261,126 +261,6 @@ mount_tree_changed_event (GIOChannel *ch
return TRUE;
}
-#if 0
-static gboolean
-inotify_data (GIOChannel *source, GIOCondition condition, gpointer user_data)
-{
- int fd;
- char buf[256];
-
- fd = g_io_channel_unix_get_fd (source);
-again:
- if (read (fd, buf, sizeof (buf)) < 0) {
- if (errno == EINTR) {
- goto again;
- } else {
- HAL_ERROR (("read: %s", strerror (errno)));
- }
- }
-
- /* TODO: OK, so the right thing to do would be to add watches
- * for directories that appear
- */
-
- osspec_fdi_cache_invalid ();
- return TRUE;
-}
-
-static gboolean
-add_fdi_watch (int inotify_fd, const char *fdi_dir)
-{
- int wd;
- gboolean ret;
- GDir *dir;
- GError *error = NULL;
- const char *name;
-
- ret = FALSE;
-
- wd = inotify_add_watch (inotify_fd, fdi_dir, IN_MODIFY | IN_CREATE | IN_DELETE);
- if (wd < 0) {
- HAL_ERROR (("Unable to inotify_add_watch() for '%s': %s", fdi_dir, strerror (errno)));
- goto out;
- }
-
- /* watch sub dirs */
- dir = g_dir_open (fdi_dir, 0, &error);
- if (dir == NULL)
- goto out;
- while ((name = g_dir_read_name (dir)) != NULL) {
- char *sub_dir;
-
- sub_dir = g_strdup_printf ("%s/%s", fdi_dir, name);
- if (g_file_test (sub_dir, G_FILE_TEST_IS_DIR)) {
- add_fdi_watch (inotify_fd, sub_dir);
- }
- g_free (sub_dir);
- }
- g_dir_close (dir);
-
- ret = TRUE;
-out:
- return ret;
-}
-
-static void
-watch_fdi_files (void)
-{
- int inotify_fd;
- char *hal_fdi_source_preprobe;
- char *hal_fdi_source_information;
- char *hal_fdi_source_policy;
- GIOChannel *inotify_channel;
-
- hal_fdi_source_preprobe = getenv ("HAL_FDI_SOURCE_PREPROBE");
- hal_fdi_source_information = getenv ("HAL_FDI_SOURCE_INFORMATION");
- hal_fdi_source_policy = getenv ("HAL_FDI_SOURCE_POLICY");
-
- inotify_fd = inotify_init ();
- if (inotify_fd < 0) {
- DIE (("Unable to initialize inotify: %s ", strerror (errno)));
- goto out;
- }
- inotify_channel = g_io_channel_unix_new (inotify_fd);
- g_io_add_watch (inotify_channel, G_IO_IN, inotify_data, NULL);
- g_io_channel_unref (inotify_channel);
-
- if (hal_fdi_source_preprobe != NULL) {
- if (!add_fdi_watch (inotify_fd, hal_fdi_source_preprobe))
- goto out;
- } else {
- if (!add_fdi_watch (inotify_fd, PACKAGE_DATA_DIR "/hal/fdi/preprobe"))
- goto out;
- if (!add_fdi_watch (inotify_fd, PACKAGE_SYSCONF_DIR "/hal/fdi/preprobe"))
- goto out;
- }
-
- if (hal_fdi_source_information != NULL) {
- if (!add_fdi_watch (inotify_fd, hal_fdi_source_information))
- goto out;
- } else {
- if (!add_fdi_watch (inotify_fd, PACKAGE_DATA_DIR "/hal/fdi/information"))
- goto out;
- if (!add_fdi_watch (inotify_fd, PACKAGE_SYSCONF_DIR "/hal/fdi/information"))
- goto out;
- }
-
- if (hal_fdi_source_policy != NULL) {
- if (!add_fdi_watch (inotify_fd, hal_fdi_source_policy))
- goto out;
- } else {
- if (!add_fdi_watch (inotify_fd, PACKAGE_DATA_DIR "/hal/fdi/policy"))
- goto out;
- if (!add_fdi_watch (inotify_fd, PACKAGE_SYSCONF_DIR "/hal/fdi/policy"))
- goto out;
- }
-
- return;
-out:
- DIE (("Error watching fdi files"));
-}
-#endif
-
static HalFileMonitor *file_monitor = NULL;
HalFileMonitor *
diff --git a/hald/mmap_cache.c b/hald/mmap_cache.c
index 1711f3f..6cdec6b 100644
--- a/hald/mmap_cache.c
+++ b/hald/mmap_cache.c
@@ -44,6 +44,8 @@
#include "rule.h"
#include "mmap_cache.h"
#include "hald_runner.h"
+#include "hal-file-monitor.h"
+#include "osspec.h"
extern void *rules_ptr;
static size_t rules_size = 0;
@@ -89,40 +91,6 @@ int di_rules_init (void)
return 0;
}
-static void dir_mtime(const char * path, time_t * mt)
-{
- struct dirent **namelist;
- struct stat st;
- int n;
- char cpath[PATH_MAX];
-
- if (!stat(path, &st)) {
- if(st.st_mtime > *mt)
- *mt = st.st_mtime;
-
- if(S_ISDIR(st.st_mode)) {
- n = scandir(path, &namelist, 0, alphasort);
- if (n < 0)
- return;
- else {
- while(n--) {
-#ifdef HAVE_SNPRINTF
- snprintf(cpath, PATH_MAX, "%s/%s", path, namelist[n]->d_name);
-#else
- sprintf(cpath, "%s/%s", path, namelist[n]->d_name);
-#endif
- if(namelist[n]->d_name[0] != '.')
- dir_mtime(cpath, mt);
-
- free(namelist[n]);
- }
- free(namelist);
- }
- }
- }
-}
-
-
static gboolean regen_cache_done;
static gint regen_cache_success;
@@ -193,8 +161,69 @@ regen_cache (void)
HAL_INFO (("fdi cache generation done"));
}
+static gboolean cache_valid = FALSE;
+
+static void
+cache_invalidated (HalFileMonitor *monitor,
+ HalFileMonitorEvent event,
+ const char *path,
+ gpointer user_data)
+{
+ HAL_INFO (("dir '%s' changed - marking fdi cache as invalid", path));
+ cache_valid = FALSE;
+}
+
+static void
+dir_mtime (const char *path, time_t *mt, gboolean setup_watches)
+{
+ struct dirent **namelist;
+ struct stat st;
+ int n;
+ char cpath[PATH_MAX];
+
+ if (setup_watches) {
+ HalFileMonitor *file_monitor;
+
+ file_monitor = osspec_get_file_monitor ();
+ if (file_monitor != NULL) {
+ hal_file_monitor_add_notify (file_monitor,
+ path,
+ HAL_FILE_MONITOR_EVENT_CREATE|
+ HAL_FILE_MONITOR_EVENT_DELETE|
+ HAL_FILE_MONITOR_EVENT_CHANGE,
+ cache_invalidated,
+ NULL);
+ }
+ }
+
+ if (!stat(path, &st)) {
+ if(st.st_mtime > *mt)
+ *mt = st.st_mtime;
+
+ if(S_ISDIR(st.st_mode)) {
+ n = scandir(path, &namelist, 0, alphasort);
+ if (n < 0)
+ return;
+ else {
+ while(n--) {
+#ifdef HAVE_SNPRINTF
+ snprintf(cpath, PATH_MAX, "%s/%s", path, namelist[n]->d_name);
+#else
+ sprintf(cpath, "%s/%s", path, namelist[n]->d_name);
+#endif
+ if(namelist[n]->d_name[0] != '.')
+ dir_mtime(cpath, mt, setup_watches);
+
+ free(namelist[n]);
+ }
+ free(namelist);
+ }
+ }
+ }
+}
+
gboolean
-di_cache_coherency_check (void)
+di_cache_coherency_check (gboolean setup_watches)
{
char *hal_fdi_source_preprobe;
char *hal_fdi_source_information;
@@ -204,33 +233,35 @@ di_cache_coherency_check (void)
struct stat st;
gboolean did_regen;
+ if (cache_valid)
+ return FALSE;
+
did_regen = FALSE;
mt = 0;
-
hal_fdi_source_preprobe = getenv ("HAL_FDI_SOURCE_PREPROBE");
hal_fdi_source_information = getenv ("HAL_FDI_SOURCE_INFORMATION");
hal_fdi_source_policy = getenv ("HAL_FDI_SOURCE_POLICY");
if (hal_fdi_source_preprobe != NULL) {
- dir_mtime (hal_fdi_source_preprobe, &mt);
+ dir_mtime (hal_fdi_source_preprobe, &mt, setup_watches);
} else {
- dir_mtime (PACKAGE_DATA_DIR "/hal/fdi/preprobe", &mt);
- dir_mtime (PACKAGE_SYSCONF_DIR "/hal/fdi/preprobe", &mt);
+ dir_mtime (PACKAGE_DATA_DIR "/hal/fdi/preprobe", &mt, setup_watches);
+ dir_mtime (PACKAGE_SYSCONF_DIR "/hal/fdi/preprobe", &mt, setup_watches);
}
if (hal_fdi_source_information != NULL) {
- dir_mtime (hal_fdi_source_information, &mt);
+ dir_mtime (hal_fdi_source_information, &mt, setup_watches);
} else {
- dir_mtime (PACKAGE_DATA_DIR "/hal/fdi/information", &mt);
- dir_mtime (PACKAGE_SYSCONF_DIR "/hal/fdi/information", &mt);
+ dir_mtime (PACKAGE_DATA_DIR "/hal/fdi/information", &mt, setup_watches);
+ dir_mtime (PACKAGE_SYSCONF_DIR "/hal/fdi/information", &mt, setup_watches);
}
if (hal_fdi_source_policy != NULL) {
- dir_mtime (hal_fdi_source_policy, &mt);
+ dir_mtime (hal_fdi_source_policy, &mt, setup_watches);
} else {
- dir_mtime (PACKAGE_DATA_DIR "/hal/fdi/policy", &mt);
- dir_mtime (PACKAGE_SYSCONF_DIR "/hal/fdi/policy", &mt);
+ dir_mtime (PACKAGE_DATA_DIR "/hal/fdi/policy", &mt, setup_watches);
+ dir_mtime (PACKAGE_SYSCONF_DIR "/hal/fdi/policy", &mt, setup_watches);
}
cachename = getenv ("HAL_FDI_CACHE_NAME");
@@ -250,5 +281,7 @@ di_cache_coherency_check (void)
HAL_INFO(("cache mtime is %d",mt));
+ cache_valid = TRUE;
+
return did_regen;
}
diff --git a/hald/mmap_cache.h b/hald/mmap_cache.h
index ce4d48c..5dbd6b5 100644
--- a/hald/mmap_cache.h
+++ b/hald/mmap_cache.h
@@ -34,7 +34,7 @@
#include <glib.h>
int di_rules_init (void);
-gboolean di_cache_coherency_check (void);
+gboolean di_cache_coherency_check (gboolean setup_watches);
#define RULES_PTR(x) ((void *)((unsigned char *) rules_ptr + x))
#endif
diff --git a/hald/osspec.h b/hald/osspec.h
index 08cf6a2..26290eb 100644
--- a/hald/osspec.h
+++ b/hald/osspec.h
@@ -52,9 +52,6 @@ gboolean osspec_device_reprobe (HalDevic
/* Called to refresh mount state for a device object of capability volume */
void osspec_refresh_mount_state_for_block_device (HalDevice *d);
-/* Called by OS specific code to tell that the fdi cache is invalid */
-void osspec_fdi_cache_invalid (void);
-
/** Called when the org.freedesktop.Hal service receives a messaged that the generic daemon
* doesn't handle. Can be used for intercepting messages from kernel or core OS components.
*
More information about the hal-commit
mailing list