PennMUSH Community

Changeset 1195

Show
Ignore:
Timestamp:
01/03/08 02:43:46 (1 year ago)
Author:
shawnw
Message:

First pass at using fam-based monitoring of help.txt and friends.

Isn't actually getting notifications of changes on my linux test box,
even though it never generates any errors. Needs testing on other OSes,
which are more of what the fam target is intended for. inotify is
used instead of fam on linux systems that have both.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/config.h.in

    r1187 r1195  
    7474 
    7575#undef HAVE_SYS_INOTIFY_H 
     76 
     77#undef HAVE_FAM_H 
     78 
     79#undef HAVE_LIBFAM 
    7680 
    7781/* C99ish headers. The first two are really really nice to have. */ 
  • 1.8.3/branches/devel/configure

    r1187 r1195  
    74967496 
    74977497 
    7498 for ac_header in poll.h sys/epoll.h sys/select.h sys/inotify.h 
     7498 
     7499for ac_header in poll.h sys/epoll.h sys/select.h sys/inotify.h fam.h 
    74997500do 
    75007501as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` 
     
    1185011851fi 
    1185111852 
     11853 
     11854 
     11855{ echo "$as_me:$LINENO: checking for FAMOpen in -lfam" >&5 
     11856echo $ECHO_N "checking for FAMOpen in -lfam... $ECHO_C" >&6; } 
     11857if test "${ac_cv_lib_fam_FAMOpen+set}" = set; then 
     11858  echo $ECHO_N "(cached) $ECHO_C" >&6 
     11859else 
     11860  ac_check_lib_save_LIBS=$LIBS 
     11861LIBS="-lfam  $LIBS" 
     11862cat >conftest.$ac_ext <<_ACEOF 
     11863/* confdefs.h.  */ 
     11864_ACEOF 
     11865cat confdefs.h >>conftest.$ac_ext 
     11866cat >>conftest.$ac_ext <<_ACEOF 
     11867/* end confdefs.h.  */ 
     11868 
     11869/* Override any GCC internal prototype to avoid an error. 
     11870   Use char because int might match the return type of a GCC 
     11871   builtin and then its argument prototype would still apply.  */ 
     11872#ifdef __cplusplus 
     11873extern "C" 
     11874#endif 
     11875char FAMOpen (); 
     11876int 
     11877main () 
     11878{ 
     11879return FAMOpen (); 
     11880  ; 
     11881  return 0; 
     11882} 
     11883_ACEOF 
     11884rm -f conftest.$ac_objext conftest$ac_exeext 
     11885if { (ac_try="$ac_link" 
     11886case "(($ac_try" in 
     11887  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; 
     11888  *) ac_try_echo=$ac_try;; 
     11889esac 
     11890eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 
     11891  (eval "$ac_link") 2>conftest.er1 
     11892  ac_status=$? 
     11893  grep -v '^ *+' conftest.er1 >conftest.err 
     11894  rm -f conftest.er1 
     11895  cat conftest.err >&5 
     11896  echo "$as_me:$LINENO: \$? = $ac_status" >&5 
     11897  (exit $ac_status); } && { 
     11898     test -z "$ac_c_werror_flag" || 
     11899     test ! -s conftest.err 
     11900       } && test -s conftest$ac_exeext && 
     11901       $as_test_x conftest$ac_exeext; then 
     11902  ac_cv_lib_fam_FAMOpen=yes 
     11903else 
     11904  echo "$as_me: failed program was:" >&5 
     11905sed 's/^/| /' conftest.$ac_ext >&5 
     11906 
     11907    ac_cv_lib_fam_FAMOpen=no 
     11908fi 
     11909 
     11910rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ 
     11911      conftest$ac_exeext conftest.$ac_ext 
     11912LIBS=$ac_check_lib_save_LIBS 
     11913fi 
     11914{ echo "$as_me:$LINENO: result: $ac_cv_lib_fam_FAMOpen" >&5 
     11915echo "${ECHO_T}$ac_cv_lib_fam_FAMOpen" >&6; } 
     11916if test $ac_cv_lib_fam_FAMOpen = yes; then 
     11917  cat >>confdefs.h <<_ACEOF 
     11918#define HAVE_LIBFAM 1 
     11919_ACEOF 
     11920 
     11921  LIBS="-lfam $LIBS" 
     11922 
     11923fi 
    1185211924 
    1185311925 
  • 1.8.3/branches/devel/configure.in

    r1187 r1195  
    117117AC_CHECK_HEADER(sys/types.h, [AC_DEFINE(I_SYS_TYPES)]) 
    118118AC_CHECK_HEADERS([sys/un.h ieeefp.h sys/resource.h sys/event.h sys/uio.h]) 
    119 AC_CHECK_HEADERS([poll.h sys/epoll.h sys/select.h sys/inotify.h]) 
     119AC_CHECK_HEADERS([poll.h sys/epoll.h sys/select.h sys/inotify.h fam.h]) 
    120120### C language support 
    121121# Only need to check C99 and GNU extensions 
     
    156156AC_CHECK_LIB(crypt, crypt) 
    157157LIB_SOCKET_NSL 
     158AC_CHECK_LIB(fam, FAMOpen) 
    158159 
    159160# with_ssl=set 
  • 1.8.3/branches/devel/game/restart

    r954 r1195  
    155155export DATEMSK 
    156156 
     157export GAMEDIR 
     158 
    157159LC_ALL=$LANG LANG=$LANG ./netmush $@ $GAMEDIR/$CONF_FILE & 
  • 1.8.3/branches/devel/src/bsd.c

    r1194 r1195  
    8585#ifdef HAVE_SYS_INOTIFY_H 
    8686#include <sys/inotify.h> 
     87#endif 
     88#ifdef HAVE_FAM_H 
     89#include <fam.h> 
    8790#endif 
    8891 
     
    388391static char **saved_argv = NULL; 
    389392 
    390 #ifdef HAVE_INOTIFY 
    391393int file_watch_init(void); 
    392394void file_watch_event(int); 
    393 #endif 
    394395 
    395396#ifndef BOOLEXP_DEBUGGING 
     
    878879#endif 
    879880  unsigned long input_ready, output_ready; 
    880 #ifdef HAVE_INOTIFY 
    881881  int notify_fd = -1; 
    882 #endif 
    883882 
    884883  if (!restarting) { 
     
    906905  do_rawlog(LT_ERR, "RESTART FINISHED."); 
    907906 
    908 #ifdef HAVE_INOTIFY 
    909907  notify_fd = file_watch_init(); 
    910 #endif 
    911908 
    912909  our_gettimeofday(&then); 
     
    10201017    } 
    10211018 
    1022 #ifdef HAVE_INOTIFY 
    10231019    if (notify_fd >= 0) 
    10241020      FD_SET(notify_fd, &input_set); 
    1025 #endif 
    10261021 
    10271022    found = select(maxd, &input_set, &output_set, (fd_set *) 0, &timeout); 
     
    11101105#endif 
    11111106#endif 
    1112 #ifdef HAVE_INOTIFY 
     1107 
    11131108      if (notify_fd >= 0 && FD_ISSET(notify_fd, &input_set)) 
    11141109    file_watch_event(notify_fd); 
    1115 #endif 
     1110 
    11161111      for (d = descriptor_list; d; d = dnext) { 
    11171112        dnext = d->next; 
     
    47224717 
    47234718 
    4724 #ifdef HAVE_INOTIFY 
    47254719/* File modification watching code. Linux-specific for now.  
    47264720 * Future directions include: kqueue() for BSD, fam for linux, irix, others? 
     
    47354729 
    47364730static void 
    4737 watch_files(int fd) 
     4731reload_files(void) 
     4732
     4733  do_rawlog(LT_TRACE, 
     4734        "Reloading help indexes and cached files after detecting a change."); 
     4735  fcache_load(NOTHING); 
     4736  help_reindex(NOTHING); 
     4737
     4738 
     4739#ifdef HAVE_INOTIFY 
     4740/* Linux 2.6 and greater inotify() file monitoring interface */ 
     4741 
     4742static void 
     4743watch_files_in(int fd) 
    47384744{ 
    47394745  int n; 
     
    47474753  } while (0) 
    47484754       
    4749  
    47504755  do_rawlog(LT_TRACE, 
    47514756        "'No such file or directory' errors immediately following are probably harmless."); 
     
    47674772} 
    47684773 
    4769 /** Start monitoring various useful files for changes.  
    4770  * \return descriptor of the notification service, or -1 on error 
    4771  */ 
    4772 int 
    4773 file_watch_init(void) 
     4774static int 
     4775file_watch_init_in(void) 
    47744776{ 
    47754777  int fd = inotify_init(); 
    4776   
     4778 
    47774779 if (fd < 0) { 
    47784780    penn_perror("file_watch_init:inotify_init"); 
     
    47834785    maxd = fd + 1; 
    47844786 
    4785   watch_files(fd); 
     4787  watch_files_in(fd); 
    47864788 
    47874789  make_nonblocking(fd); 
     
    47904792} 
    47914793 
    4792 /** Test for modified files and re-read them if indicated.  
    4793  * \param fd the notification monitorh descriptor 
    4794  */ 
    4795 void 
    4796 file_watch_event(int fd) 
     4794static void 
     4795file_watch_event_in(int fd) 
    47974796{ 
    47984797  struct inotify_event ev; 
     
    48014800    do_rawlog(LT_TRACE, "Got event. Flags: 0x%x", ev.mask); 
    48024801    if (ev.mask != IN_IGNORED) { 
    4803       do_rawlog(LT_TRACE, 
    4804         "Reloading help indexes and cached files after detecting a change."); 
    4805       fcache_load(NOTHING); 
    4806       help_reindex(NOTHING); 
    4807       watch_files(fd); 
    4808     } 
    4809   } 
    4810 
    4811  
    4812 #endif 
     4802      reload_files(); 
     4803      watch_files_in(fd); 
     4804    } 
     4805  } 
     4806
     4807 
     4808#elif defined(HAVE_LIBFAM) 
     4809/* libfam monitoring interface */ 
     4810 
     4811static FAMConnection famc; 
     4812 
     4813static int 
     4814file_watch_init_fam(void) 
     4815
     4816  int n; 
     4817  help_file *h; 
     4818  FAMRequest famr; 
     4819  const char *gamedir; 
     4820 
     4821  memset(&famc, 0, sizeof famc); 
     4822 
     4823  gamedir = getenv("GAMEDIR"); 
     4824  if (!gamedir) { 
     4825    do_rawlog(LT_TRACE, 
     4826          "file_watch_init: Unable to get GAMEDIR environment variable."); 
     4827    return -1; 
     4828  } 
     4829   
     4830  if (FAMOpen(&famc) < 0) { 
     4831    do_rawlog(LT_TRACE, "file_watch_init: FAMOpen: %s", FamErrlist[FAMErrno]); 
     4832    return -1; 
     4833  } 
     4834 
     4835#define WATCH(name) do { \ 
     4836    const char *fullname = tprintf("%s/%s", gamedir, (name));    \ 
     4837    do_rawlog(LT_TRACE, "Watching %s", fullname);           \ 
     4838    if (FAMMonitorFile(&famc, fullname, &famr, NULL) < 0)       \ 
     4839      do_rawlog(LT_TRACE, "file_watch_init:FAMMonitorFile(\"%s\"): %s", \ 
     4840        (name), FamErrlist[FAMErrno]);              \ 
     4841  } while (0) 
     4842       
     4843  do_rawlog(LT_TRACE, 
     4844        "'No such file or directory' errors immediately following are probably harmless."); 
     4845  for (n = 0; n < 2; n++) { 
     4846    WATCH(options.connect_file[n]); 
     4847    WATCH(options.motd_file[n]); 
     4848    WATCH(options.wizmotd_file[n]); 
     4849    WATCH(options.register_file[n]); 
     4850    WATCH(options.quit_file[n]); 
     4851    WATCH(options.down_file[n]); 
     4852    WATCH(options.full_file[n]); 
     4853    WATCH(options.guest_file[n]); 
     4854  } 
     4855   
     4856  for (h = hash_firstentry(&help_files); h; h = hash_nextentry(&help_files))  
     4857    WATCH(h->file); 
     4858 
     4859#undef WATCH 
     4860   
     4861  return FAMCONNECTION_GETFD(&famc); 
     4862
     4863 
     4864static void 
     4865file_watch_event_fam(void) 
     4866
     4867  do_rawlog(LT_TRACE, "In file_watch_event_fam()"); 
     4868 
     4869  while (FAMPending(&famc)) { 
     4870    FAMEvent famev; 
     4871     
     4872    memset(&famev, 0, sizeof famev); 
     4873     
     4874    if (FAMNextEvent(&famc, &famev) < 0) { 
     4875      do_rawlog(LT_TRACE, "file_watch_event: FAMNextEvent: %s", 
     4876        FamErrlist[FAMErrno]); 
     4877      break; 
     4878    } 
     4879     
     4880    do_rawlog(LT_TRACE, "Code is: %d for %s", famev.code, famev.filename); 
     4881 
     4882    switch (famev.code) { 
     4883    case FAMChanged: 
     4884    case FAMDeleted: 
     4885      reload_files(); 
     4886      break; 
     4887    default: 
     4888      break; 
     4889    } 
     4890  } 
     4891
     4892 
     4893#endif 
     4894 
     4895/** Start monitoring various useful files for changes.  
     4896 * \return descriptor of the notification service, or -1 on error 
     4897 */ 
     4898int 
     4899file_watch_init(void) 
     4900
     4901#ifdef HAVE_INOTIFY 
     4902  return file_watch_init_in(); 
     4903#elif defined(HAVE_LIBFAM) 
     4904  return file_watch_init_fam(); 
     4905#else 
     4906  return -1; 
     4907#endif 
     4908
     4909 
     4910/** Test for modified files and re-read them if indicated.  
     4911 * \param fd the notification monitorh descriptor 
     4912 */ 
     4913void 
     4914file_watch_event(int fd __attribute__((__unused__))) 
     4915
     4916#ifdef HAVE_INOTIFY 
     4917  file_watch_event_in(fd); 
     4918#elif defined(HAVE_LIBFAM) 
     4919  file_watch_event_fam(); 
     4920#endif 
     4921  return; 
     4922