From 319b9ad4bccedb2a6b1a222cf446e873b2bc6de1 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Mon, 11 Jul 2011 14:50:24 -0400 Subject: Generalize framework to register monitoring of files in nscd nscd can clear caches when certain files change. The list of files was hardcoded so far and worked for nss_files and nss_dns and those modules which need no monitoring. nss_db, for instance, has its own set of files to monitor. Now the NSS modules themselves can request that certain files are monitored. --- nscd/nscd.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'nscd/nscd.c') diff --git a/nscd/nscd.c b/nscd/nscd.c index c3d9fe6cef..4894cb2faa 100644 --- a/nscd/nscd.c +++ b/nscd/nscd.c @@ -46,6 +46,9 @@ #include "selinux.h" #include "../nss/nsswitch.h" #include +#ifdef HAVE_INOTIFY +# include +#endif /* Get libc version number. */ #include @@ -272,8 +275,21 @@ main (int argc, char **argv) /* Cleanup files created by a previous 'bind'. */ unlink (_PATH_NSCDSOCKET); +#ifdef HAVE_INOTIFY + /* Use inotify to recognize changed files. */ + inotify_fd = inotify_init1 (IN_NONBLOCK); +# ifndef __ASSUME_IN_NONBLOCK + if (inotify_fd == -1 && errno == ENOSYS) + { + inotify_fd = inotify_init (); + if (inotify_fd != -1) + fcntl (inotify_fd, F_SETFL, O_RDONLY | O_NONBLOCK); + } +# endif +#endif + /* Make sure we do not get recursive calls. */ - __nss_disable_nscd (); + __nss_disable_nscd (register_traced_file); /* Init databases. */ nscd_init (); -- cgit v1.2.1