Use notification when timezone files change and re-scan then.
authorTilghman Lesher <tilghman@meg.abyt.es>
Wed, 25 Feb 2009 19:24:44 +0000 (19:24 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Wed, 25 Feb 2009 19:24:44 +0000 (19:24 +0000)
(closes issue #14300)
 Reported by: jamessan
 Patches:
       20090127__bug14300.diff.txt uploaded by tilghman (license 14)
       20090224__bug14300.diff uploaded by jamessan (license 246)
 Tested by: jamessan
 Review: http://reviewboard.digium.com/r/136/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@178605 65c4cc65-6c06-0410-ace0-fbb531ad65f3

configure
configure.ac
include/asterisk/autoconfig.h.in
main/stdtime/localtime.c

index ff37ce8..10d94fd 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 173130 .
+# From configure.ac Revision: 177162 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61 for asterisk 1.6.
 #
@@ -787,6 +787,10 @@ IMAP_TK_LIB
 IMAP_TK_INCLUDE
 IMAP_TK_DIR
 PBX_IMAP_TK
+INOTIFY_LIB
+INOTIFY_INCLUDE
+INOTIFY_DIR
+PBX_INOTIFY
 IODBC_LIB
 IODBC_INCLUDE
 IODBC_DIR
@@ -1632,6 +1636,7 @@ Optional Packages:
   --with-iconv=PATH       use Iconv Library files in PATH
   --with-iksemel=PATH     use Iksemel Jabber Library files in PATH
   --with-imap=PATH        use UW IMAP Toolkit files in PATH
+  --with-inotify=PATH     use inotify support files in PATH
   --with-iodbc=PATH       use iODBC files in PATH
   --with-isdnnet=PATH     use ISDN4Linux Library files in PATH
   --with-jack=PATH        use Jack Audio Connection Kit files in PATH
@@ -8578,6 +8583,37 @@ fi
 
 
 
+    INOTIFY_DESCRIP="inotify support"
+    INOTIFY_OPTION="inotify"
+    PBX_INOTIFY=0
+
+# Check whether --with-inotify was given.
+if test "${with_inotify+set}" = set; then
+  withval=$with_inotify;
+       case ${withval} in
+       n|no)
+       USE_INOTIFY=no
+       # -1 is a magic value used by menuselect to know that the package
+       # was disabled, other than 'not found'
+       PBX_INOTIFY=-1
+       ;;
+       y|ye|yes)
+       ac_mandatory_list="${ac_mandatory_list} INOTIFY"
+       ;;
+       *)
+       INOTIFY_DIR="${withval}"
+       ac_mandatory_list="${ac_mandatory_list} INOTIFY"
+       ;;
+       esac
+
+fi
+
+
+
+
+
+
+
     IODBC_DESCRIP="iODBC"
     IODBC_OPTION="iodbc"
     PBX_IODBC=0
 
 
 
+if test "x${PBX_INOTIFY}" != "x1" -a "${USE_INOTIFY}" != "no"; then
+   pbxlibdir=""
+   # if --with-INOTIFY=DIR has been specified, use it.
+   if test "x${INOTIFY_DIR}" != "x"; then
+      if test -d ${INOTIFY_DIR}/lib; then
+        pbxlibdir="-L${INOTIFY_DIR}/lib"
+      else
+        pbxlibdir="-L${INOTIFY_DIR}"
+      fi
+   fi
+   pbxfuncname="inotify_init"
+   if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
+      AST_INOTIFY_FOUND=yes
+   else
+      as_ac_Lib=`echo "ac_cv_lib_c_${pbxfuncname}" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for ${pbxfuncname} in -lc" >&5
+echo $ECHO_N "checking for ${pbxfuncname} in -lc... $ECHO_C" >&6; }
+if { as_var=$as_ac_Lib; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lc ${pbxlibdir}  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ${pbxfuncname} ();
+int
+main ()
+{
+return ${pbxfuncname} ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_Lib=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       eval "$as_ac_Lib=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+ac_res=`eval echo '${'$as_ac_Lib'}'`
+              { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_Lib'}'` = yes; then
+  AST_INOTIFY_FOUND=yes
+else
+  AST_INOTIFY_FOUND=no
+fi
+
+   fi
+
+   # now check for the header.
+   if test "${AST_INOTIFY_FOUND}" = "yes"; then
+      INOTIFY_LIB="${pbxlibdir} -lc "
+      # if --with-INOTIFY=DIR has been specified, use it.
+      if test "x${INOTIFY_DIR}" != "x"; then
+        INOTIFY_INCLUDE="-I${INOTIFY_DIR}/include"
+      fi
+      INOTIFY_INCLUDE="${INOTIFY_INCLUDE} "
+      if test "xsys/inotify.h" = "x" ; then    # no header, assume found
+         INOTIFY_HEADER_FOUND="1"
+      else                             # check for the header
+         saved_cppflags="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${INOTIFY_INCLUDE}"
+        if test "${ac_cv_header_sys_inotify_h+set}" = set; then
+  { echo "$as_me:$LINENO: checking for sys/inotify.h" >&5
+echo $ECHO_N "checking for sys/inotify.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_sys_inotify_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_inotify_h" >&5
+echo "${ECHO_T}$ac_cv_header_sys_inotify_h" >&6; }
+else
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking sys/inotify.h usability" >&5
+echo $ECHO_N "checking sys/inotify.h usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <sys/inotify.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking sys/inotify.h presence" >&5
+echo $ECHO_N "checking sys/inotify.h presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/inotify.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+        test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: sys/inotify.h: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: sys/inotify.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/inotify.h: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: sys/inotify.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: sys/inotify.h: present but cannot be compiled" >&5
+echo "$as_me: WARNING: sys/inotify.h: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/inotify.h:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: sys/inotify.h:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/inotify.h: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: sys/inotify.h: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/inotify.h:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: sys/inotify.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/inotify.h: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: sys/inotify.h: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/inotify.h: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: sys/inotify.h: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## ------------------------------- ##
+## Report this to www.asterisk.org ##
+## ------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for sys/inotify.h" >&5
+echo $ECHO_N "checking for sys/inotify.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_sys_inotify_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_header_sys_inotify_h=$ac_header_preproc
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_inotify_h" >&5
+echo "${ECHO_T}$ac_cv_header_sys_inotify_h" >&6; }
+
+fi
+if test $ac_cv_header_sys_inotify_h = yes; then
+  INOTIFY_HEADER_FOUND=1
+else
+  INOTIFY_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${saved_cppflags}"
+      fi
+      if test "x${INOTIFY_HEADER_FOUND}" = "x0" ; then
+         INOTIFY_LIB=""
+         INOTIFY_INCLUDE=""
+      else
+         if test "x${pbxfuncname}" = "x" ; then                # only checking headers -> no library
+           INOTIFY_LIB=""
+        fi
+         PBX_INOTIFY=1
+         # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_INOTIFY 1
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_INOTIFY_VERSION
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+
 if test "x${PBX_JACK}" != "x1" -a "${USE_JACK}" != "no"; then
    pbxlibdir=""
    # if --with-JACK=DIR has been specified, use it.
@@ -53585,6 +53883,10 @@ IMAP_TK_LIB!$IMAP_TK_LIB$ac_delim
 IMAP_TK_INCLUDE!$IMAP_TK_INCLUDE$ac_delim
 IMAP_TK_DIR!$IMAP_TK_DIR$ac_delim
 PBX_IMAP_TK!$PBX_IMAP_TK$ac_delim
+INOTIFY_LIB!$INOTIFY_LIB$ac_delim
+INOTIFY_INCLUDE!$INOTIFY_INCLUDE$ac_delim
+INOTIFY_DIR!$INOTIFY_DIR$ac_delim
+PBX_INOTIFY!$PBX_INOTIFY$ac_delim
 IODBC_LIB!$IODBC_LIB$ac_delim
 IODBC_INCLUDE!$IODBC_INCLUDE$ac_delim
 IODBC_DIR!$IODBC_DIR$ac_delim
@@ -53607,10 +53909,6 @@ LIBXML2_DIR!$LIBXML2_DIR$ac_delim
 PBX_LIBXML2!$PBX_LIBXML2$ac_delim
 LTDL_LIB!$LTDL_LIB$ac_delim
 LTDL_INCLUDE!$LTDL_INCLUDE$ac_delim
-LTDL_DIR!$LTDL_DIR$ac_delim
-PBX_LTDL!$PBX_LTDL$ac_delim
-LUA_LIB!$LUA_LIB$ac_delim
-LUA_INCLUDE!$LUA_INCLUDE$ac_delim
 _ACEOF
 
   if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -53652,6 +53950,10 @@ _ACEOF
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   cat >conf$$subs.sed <<_ACEOF
+LTDL_DIR!$LTDL_DIR$ac_delim
+PBX_LTDL!$PBX_LTDL$ac_delim
+LUA_LIB!$LUA_LIB$ac_delim
+LUA_INCLUDE!$LUA_INCLUDE$ac_delim
 LUA_DIR!$LUA_DIR$ac_delim
 PBX_LUA!$PBX_LUA$ac_delim
 MISDN_LIB!$MISDN_LIB$ac_delim
@@ -53745,10 +54047,6 @@ PBX_SPEEX!$PBX_SPEEX$ac_delim
 SPEEX_PREPROCESS_LIB!$SPEEX_PREPROCESS_LIB$ac_delim
 SPEEX_PREPROCESS_INCLUDE!$SPEEX_PREPROCESS_INCLUDE$ac_delim
 SPEEX_PREPROCESS_DIR!$SPEEX_PREPROCESS_DIR$ac_delim
-PBX_SPEEX_PREPROCESS!$PBX_SPEEX_PREPROCESS$ac_delim
-SPEEXDSP_LIB!$SPEEXDSP_LIB$ac_delim
-SPEEXDSP_INCLUDE!$SPEEXDSP_INCLUDE$ac_delim
-SPEEXDSP_DIR!$SPEEXDSP_DIR$ac_delim
 _ACEOF
 
   if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -53790,6 +54088,10 @@ _ACEOF
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   cat >conf$$subs.sed <<_ACEOF
+PBX_SPEEX_PREPROCESS!$PBX_SPEEX_PREPROCESS$ac_delim
+SPEEXDSP_LIB!$SPEEXDSP_LIB$ac_delim
+SPEEXDSP_INCLUDE!$SPEEXDSP_INCLUDE$ac_delim
+SPEEXDSP_DIR!$SPEEXDSP_DIR$ac_delim
 PBX_SPEEXDSP!$PBX_SPEEXDSP$ac_delim
 SQLITE_LIB!$SQLITE_LIB$ac_delim
 SQLITE_INCLUDE!$SQLITE_INCLUDE$ac_delim
@@ -53883,10 +54185,6 @@ OPENH323_INCDIR!$OPENH323_INCDIR$ac_delim
 OPENH323_LIBDIR!$OPENH323_LIBDIR$ac_delim
 OPENH323_SUFFIX!$OPENH323_SUFFIX$ac_delim
 OPENH323_BUILD!$OPENH323_BUILD$ac_delim
-PBX_AIS!$PBX_AIS$ac_delim
-AIS_INCLUDE!$AIS_INCLUDE$ac_delim
-AIS_LIB!$AIS_LIB$ac_delim
-CONFIG_GMIME!$CONFIG_GMIME$ac_delim
 _ACEOF
 
   if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -53928,6 +54226,10 @@ _ACEOF
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   cat >conf$$subs.sed <<_ACEOF
+PBX_AIS!$PBX_AIS$ac_delim
+AIS_INCLUDE!$AIS_INCLUDE$ac_delim
+AIS_LIB!$AIS_LIB$ac_delim
+CONFIG_GMIME!$CONFIG_GMIME$ac_delim
 EDITLINE_LIB!$EDITLINE_LIB$ac_delim
 PBX_H323!$PBX_H323$ac_delim
 PBX_IXJUSER!$PBX_IXJUSER$ac_delim
@@ -53941,7 +54243,7 @@ PBX_GENERIC_ODBC!$PBX_GENERIC_ODBC$ac_delim
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 11; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 15; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
index d21ed6a..ca87f66 100644 (file)
@@ -243,6 +243,7 @@ AST_EXT_LIB_SETUP([HOARD], [Hoard Memory Allocator], [hoard])
 AST_EXT_LIB_SETUP([ICONV], [Iconv Library], [iconv])
 AST_EXT_LIB_SETUP([IKSEMEL], [Iksemel Jabber Library], [iksemel])
 AST_EXT_LIB_SETUP([IMAP_TK], [UW IMAP Toolkit], [imap])
+AST_EXT_LIB_SETUP([INOTIFY], [inotify support], [inotify])
 AST_EXT_LIB_SETUP([IODBC], [iODBC], [iodbc])
 AST_EXT_LIB_SETUP([ISDNNET], [ISDN4Linux Library], [isdnnet])
 AST_EXT_LIB_SETUP([JACK], [Jack Audio Connection Kit], [jack])
@@ -1273,6 +1274,8 @@ fi
 
 AST_EXT_LIB_CHECK([IODBC], [iodbc], [SQLConnect], [sql.h], [-lpthread])
 
+AST_EXT_LIB_CHECK([INOTIFY], [c], [inotify_init], [sys/inotify.h])
+
 AST_EXT_LIB_CHECK([JACK], [jack], [jack_activate], [jack/jack.h])
 
 # Needed by unixodbc
index de71b70..8747629 100644 (file)
 /* Define to 1 if you have the `inet_ntoa' function. */
 #undef HAVE_INET_NTOA
 
+/* Define this to indicate the ${INOTIFY_DESCRIP} library */
+#undef HAVE_INOTIFY
+
+/* Define to indicate the ${INOTIFY_DESCRIP} library version */
+#undef HAVE_INOTIFY_VERSION
+
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
index 389107c..e247a4d 100644 (file)
@@ -51,6 +51,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <float.h>
+#ifdef HAVE_INOTIFY
+#include <sys/inotify.h>
+#endif
 
 #include "private.h"
 #include "tzfile.h"
@@ -147,6 +150,11 @@ struct state {
        char            chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt),
                                (2 * (MY_TZNAME_MAX + 1)))];
        struct lsinfo   lsis[TZ_MAX_LEAPS];
+#ifdef HAVE_INOTIFY
+       int wd[2];
+#else
+       time_t  mtime[2];
+#endif
        AST_LIST_ENTRY(state) list;
 };
 
@@ -217,6 +225,156 @@ static AST_LIST_HEAD_STATIC(zonelist, state);
 #define TZ_STRLEN_MAX 255
 #endif /* !defined TZ_STRLEN_MAX */
 
+static pthread_t inotify_thread = AST_PTHREADT_NULL;
+static ast_cond_t initialization;
+static ast_mutex_t initialization_lock;
+#ifdef HAVE_INOTIFY
+static int inotify_fd = -1;
+
+static void *inotify_daemon(void *data)
+{
+       struct {
+               struct inotify_event iev;
+               char name[FILENAME_MAX + 1];
+       } buf;
+       ssize_t res;
+       struct state *cur;
+
+       inotify_fd = inotify_init();
+
+       ast_mutex_lock(&initialization_lock);
+       ast_cond_signal(&initialization);
+       ast_mutex_unlock(&initialization_lock);
+
+       if (inotify_fd < 0) {
+               ast_log(LOG_ERROR, "Cannot initialize file notification service: %s (%d)\n", strerror(errno), errno);
+               inotify_thread = AST_PTHREADT_NULL;
+               return NULL;
+       }
+
+       for (;/*ever*/;) {
+               /* This read should block, most of the time. */
+               if ((res = read(inotify_fd, &buf, sizeof(buf))) < sizeof(buf.iev) && res > 0) {
+                       /* This should never happen */
+                       ast_log(LOG_ERROR, "Inotify read less than a full event (%d < %d)?!!\n", res, sizeof(buf.iev));
+                       break;
+               } else if (res < 0) {
+                       if (errno == EINTR || errno == EAGAIN) {
+                               /* If read fails, then wait a bit, then continue */
+                               poll(NULL, 0, 10000);
+                               continue;
+                       }
+                       /* Sanity check -- this should never happen, either */
+                       ast_log(LOG_ERROR, "Inotify failed: %s\n", strerror(errno));
+                       break;
+               }
+               AST_LIST_LOCK(&zonelist);
+               AST_LIST_TRAVERSE_SAFE_BEGIN(&zonelist, cur, list) {
+                       if (cur->wd[0] == buf.iev.wd || cur->wd[1] == buf.iev.wd) {
+                               AST_LIST_REMOVE_CURRENT(list);
+                               ast_free(cur);
+                               break;
+                       }
+               }
+               AST_LIST_TRAVERSE_SAFE_END
+               AST_LIST_UNLOCK(&zonelist);
+       }
+       close(inotify_fd);
+       inotify_thread = AST_PTHREADT_NULL;
+       return NULL;
+}
+
+static void add_notify(struct state *sp, const char *path)
+{
+       if (inotify_thread == AST_PTHREADT_NULL) {
+               ast_cond_init(&initialization, NULL);
+               ast_mutex_init(&initialization_lock);
+               ast_mutex_lock(&initialization_lock);
+               if (!(ast_pthread_create_background(&inotify_thread, NULL, inotify_daemon, NULL))) {
+                       /* Give the thread a chance to initialize */
+                       ast_cond_wait(&initialization, &initialization_lock);
+               } else {
+                       ast_log(LOG_ERROR, "Unable to start notification thread\n");
+                       ast_mutex_unlock(&initialization_lock);
+                       return;
+               }
+               ast_mutex_unlock(&initialization_lock);
+       }
+
+       if (inotify_fd > -1) {
+               char fullpath[FILENAME_MAX + 1] = "";
+               if (readlink(path, fullpath, sizeof(fullpath) - 1) != -1) {
+                       /* If file the symlink points to changes */
+                       sp->wd[1] = inotify_add_watch(inotify_fd, fullpath, IN_ATTRIB | IN_DELETE_SELF | IN_MODIFY | IN_MOVE_SELF | IN_CLOSE_WRITE );
+               } else {
+                       sp->wd[1] = -1;
+               }
+               /* or if the symlink itself changes (or the real file is here, if path is not a symlink) */
+               sp->wd[0] = inotify_add_watch(inotify_fd, path, IN_ATTRIB | IN_DELETE_SELF | IN_MODIFY | IN_MOVE_SELF | IN_CLOSE_WRITE | IN_DONT_FOLLOW);
+       }
+}
+#else
+static void *notify_daemon(void *data)
+{
+       struct stat st, lst;
+       struct state *cur;
+
+       ast_mutex_lock(&initialization_lock);
+       ast_cond_signal(&initialization);
+       ast_mutex_unlock(&initialization_lock);
+
+       for (;/*ever*/;) {
+               char            fullname[FILENAME_MAX + 1];
+
+               poll(NULL, 0, 60000);
+               AST_LIST_LOCK(&zonelist);
+               AST_LIST_TRAVERSE_SAFE_BEGIN(&zonelist, cur, list) {
+                       char *name = cur->name;
+
+                       if (name[0] == ':')
+                               ++name;
+                       if (name[0] != '/') {
+                               (void) strcpy(fullname, TZDIR "/");
+                               (void) strcat(fullname, name);
+                               name = fullname;
+                       }
+                       stat(name, &st);
+                       lstat(name, &lst);
+                       if (st.st_mtime > cur->mtime[0] || lst.st_mtime > cur->mtime[1]) {
+                               AST_LIST_REMOVE_CURRENT(list);
+                               ast_free(cur);
+                               continue;
+                       }
+               }
+               AST_LIST_TRAVERSE_SAFE_END
+               AST_LIST_UNLOCK(&zonelist);
+       }
+       inotify_thread = AST_PTHREADT_NULL;
+       return NULL;
+}
+
+static void add_notify(struct state *sp, const char *path)
+{
+       struct stat st;
+
+       if (inotify_thread == AST_PTHREADT_NULL) {
+               ast_cond_init(&initialization, NULL);
+               ast_mutex_init(&initialization_lock);
+               ast_mutex_lock(&initialization_lock);
+               if (!(ast_pthread_create_background(&inotify_thread, NULL, notify_daemon, NULL))) {
+                       /* Give the thread a chance to initialize */
+                       ast_cond_wait(&initialization, &initialization_lock);
+               }
+               ast_mutex_unlock(&initialization_lock);
+       }
+
+       stat(path, &st);
+       sp->mtime[0] = st.st_mtime;
+       lstat(path, &st);
+       sp->mtime[1] = st.st_mtime;
+}
+#endif
+
 /*! \note
 ** Section 4.12.3 of X3.159-1989 requires that
 **     Except for the strftime function, these functions [asctime,
@@ -305,6 +463,7 @@ static int tzload(const char *name, struct state * const sp, const int doextend)
                        return -1;
                if ((fid = open(name, OPEN_MODE)) == -1)
                        return -1;
+               add_notify(sp, name);
        }
        nread = read(fid, u.buf, sizeof u.buf);
        if (close(fid) < 0 || nread <= 0)