Index: configure =================================================================== --- configure (revision 171187) +++ configure (working copy) @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac Revision: 168734 . +# From configure.ac Revision: 170112 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for asterisk 1.6. # @@ -786,6 +786,10 @@ IMAP_TK_INCLUDE IMAP_TK_DIR PBX_IMAP_TK +INOTIFY_LIB +INOTIFY_INCLUDE +INOTIFY_DIR +PBX_INOTIFY IODBC_LIB IODBC_INCLUDE IODBC_DIR @@ -1630,6 +1634,7 @@ --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-c=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 @@ -8531,6 +8536,37 @@ + INOTIFY_DESCRIP="inotify support" + INOTIFY_OPTION="c" + PBX_INOTIFY=0 + +# Check whether --with-c was given. +if test "${with_c+set}" = set; then + withval=$with_c; + 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 @@ -13332,11 +13368,13 @@ cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ -#include +#include /* for off_t */ + #include int main () { -return fseeko (stdin, 0, 0) && (fseeko) (stdin, 0, 0); +int (*fp) (FILE *, off_t, int) = fseeko; + return fseeko (stdin, 0, 0) && fp (stdin, 0, 0); ; return 0; } @@ -13376,11 +13414,13 @@ cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ #define _LARGEFILE_SOURCE 1 -#include +#include /* for off_t */ + #include int main () { -return fseeko (stdin, 0, 0) && (fseeko) (stdin, 0, 0); +int (*fp) (FILE *, off_t, int) = fseeko; + return fseeko (stdin, 0, 0) && fp (stdin, 0, 0); ; return 0; } @@ -34953,6 +34993,268 @@ +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 +_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 +_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. @@ -53443,6 +53745,10 @@ 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 @@ -53466,10 +53772,6 @@ 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 -LUA_DIR!$LUA_DIR$ac_delim _ACEOF if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then @@ -53511,6 +53813,10 @@ ac_delim='%!_!# ' for ac_last_try in false false false false false :; do cat >conf$$subs.sed <<_ACEOF +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 MISDN_INCLUDE!$MISDN_INCLUDE$ac_delim @@ -53604,10 +53910,6 @@ 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 -PBX_SPEEXDSP!$PBX_SPEEXDSP$ac_delim _ACEOF if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then @@ -53649,6 +53951,10 @@ ac_delim='%!_!# ' for ac_last_try in false false false false false :; do cat >conf$$subs.sed <<_ACEOF +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 SQLITE_DIR!$SQLITE_DIR$ac_delim @@ -53742,10 +54048,6 @@ 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 -EDITLINE_LIB!$EDITLINE_LIB$ac_delim -PBX_H323!$PBX_H323$ac_delim _ACEOF if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then @@ -53787,6 +54089,10 @@ ac_delim='%!_!# ' for ac_last_try in false false false false false :; do cat >conf$$subs.sed <<_ACEOF +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 CONFIG_SDL!$CONFIG_SDL$ac_delim CONFIG_GTK!$CONFIG_GTK$ac_delim @@ -53798,7 +54104,7 @@ LTLIBOBJS!$LTLIBOBJS$ac_delim _ACEOF - if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 9; then + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 13; then break elif $ac_last_try; then { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 Index: configure.ac =================================================================== --- configure.ac (revision 171187) +++ configure.ac (working copy) @@ -239,6 +239,7 @@ 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], [c]) 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]) @@ -1268,6 +1269,8 @@ 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: include/asterisk/autoconfig.h.in =================================================================== --- include/asterisk/autoconfig.h.in (revision 171187) +++ include/asterisk/autoconfig.h.in (working copy) @@ -395,6 +395,12 @@ /* 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 header file. */ #undef HAVE_INTTYPES_H Index: main/stdtime/localtime.c =================================================================== --- main/stdtime/localtime.c (revision 171187) +++ main/stdtime/localtime.c (working copy) @@ -51,6 +51,9 @@ #include #include #include +#ifdef HAVE_INOTIFY +#include +#endif #include "private.h" #include "tzfile.h" @@ -147,6 +150,9 @@ char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt), (2 * (MY_TZNAME_MAX + 1)))]; struct lsinfo lsis[TZ_MAX_LEAPS]; +#ifndef HAVE_INOTIFY + time_t mtime[2]; +#endif AST_LIST_ENTRY(state) list; }; @@ -217,6 +223,128 @@ #define TZ_STRLEN_MAX 255 #endif /* !defined TZ_STRLEN_MAX */ +static pthread_t inotify_thread = AST_PTHREADT_NULL; +#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; + + if ((inotify_fd = inotify_init()) < 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 (strcmp(cur->name, buf.iev.name) == 0) { + 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_pthread_create_background(&inotify_thread, NULL, inotify_daemon, NULL); + /* Give the thread a chance to initialize */ + usleep(1); + } + + if (inotify_fd > -1) { + char fullpath[FILENAME_MAX + 1] = ""; + if (readlink(path, fullpath, sizeof(fullpath) - 1) != -1) { + /* If file the symlink points to changes */ + inotify_add_watch(inotify_fd, fullpath, IN_ATTRIB | IN_DELETE_SELF | IN_MODIFY | IN_MOVE_SELF | IN_ONESHOT); + } + /* or if the symlink itself changes (or the real file is here, if path is not a symlink) */ + inotify_add_watch(inotify_fd, path, IN_ATTRIB | IN_DELETE_SELF | IN_MODIFY | IN_MOVE_SELF | IN_ONESHOT | IN_DONT_FOLLOW); + } +} +#else +static void *notify_daemon(void *data) +{ + struct stat st, lst; + struct state *cur; + + 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_pthread_create_background(&inotify_thread, NULL, notify_daemon, NULL); + /* Give the thread a chance to initialize */ + usleep(1); + } + + 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 +433,7 @@ return -1; if ((fid = open(name, OPEN_MODE)) == -1) return -1; + add_notify(sp, fullname); } nread = read(fid, u.buf, sizeof u.buf); if (close(fid) < 0 || nread <= 0)