Ignore:
Timestamp:
Oct 31, 2011, 9:42:22 PM (13 years ago)
Author:
katerina
Message:

Patch for ticket #265 (inotify support).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_fInotify.c

    r368 r371  
    143143        }
    144144    }
     145  else if (arg != NULL && arg->initval < 0 &&
     146      (sh.flag.isdaemon != S_TRUE && sh.flag.loop != S_TRUE))
     147    {
     148      sh.flag.inotify = 0;
     149      return SH_MOD_FAILED;
     150    }
    145151  else if (arg != NULL && arg->initval == SH_MOD_THREAD &&
    146152           (sh.flag.isdaemon == S_TRUE || sh.flag.loop == S_TRUE))
     
    162168  ssize_t len = -1;
    163169  char *  buffer = SH_ALLOC(16384);
     170  static int count = 0;
    164171
    165172  if (ShfInotifyActive == S_FALSE)
     
    175182  /* Blocking read from inotify file descriptor.
    176183   */
    177   len = sh_inotify_read(buffer, 16384);
     184  len = sh_inotify_read_timeout(buffer, 16384, 1);
    178185 
    179186  if (len > 0)
     
    203210   */
    204211  sh_inotify_recheck_watches (&sh_file_watches, &sh_file_missing);
     212
     213  ++count;
     214
     215  if (count >= 10)
     216    {
     217      count = 0; /* Re-expand glob patterns to discover added files */
     218      sh_files_check_globFilePatterns();
     219    }
    205220
    206221  return 0;
     
    274289  SH_MUTEX_LOCK(mutex_thread_nolog);
    275290  sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN,
    276                   _("Cannot set max_user_watches"), _("sh_fInotify_set_nwatches"));
     291                  _("Cannot set max_user_watches"),
     292                  _("sh_fInotify_set_nwatches"));
    277293  SH_MUTEX_UNLOCK(mutex_thread_nolog);
    278294  return;
     
    353369  unsigned long check_mask;
    354370  char * filename;
     371  extern int flag_err_debug;
     372
     373  if (flag_err_debug == SL_TRUE)
     374    {
     375      char dbgbuf[256];
     376      sl_strlcpy (dbgbuf, "inotify mask: ", sizeof(dbgbuf));
     377      if (event->mask & IN_ACCESS) sl_strlcat(dbgbuf, "IN_ACCESS ", sizeof(dbgbuf));
     378      if (event->mask & IN_ATTRIB) sl_strlcat(dbgbuf, "IN_ATTRIB ", sizeof(dbgbuf));
     379      if (event->mask & IN_CLOSE_WRITE) sl_strlcat(dbgbuf, "IN_CLOSE_WRITE ", sizeof(dbgbuf));
     380      if (event->mask & IN_CLOSE_NOWRITE) sl_strlcat(dbgbuf, "IN_CLOSE_NOWRITE ", sizeof(dbgbuf));
     381      if (event->mask & IN_CREATE) sl_strlcat(dbgbuf, "IN_CREATE ", sizeof(dbgbuf));
     382      if (event->mask & IN_DELETE) sl_strlcat(dbgbuf, "IN_DELETE ", sizeof(dbgbuf));
     383      if (event->mask & IN_DELETE_SELF) sl_strlcat(dbgbuf, "IN_DELETE_SELF ", sizeof(dbgbuf));
     384      if (event->mask & IN_MODIFY) sl_strlcat(dbgbuf, "IN_MODIFY ", sizeof(dbgbuf));
     385      if (event->mask & IN_MOVE_SELF) sl_strlcat(dbgbuf, "IN_MOVE_SELF ", sizeof(dbgbuf));
     386      if (event->mask & IN_MOVED_FROM) sl_strlcat(dbgbuf, "IN_MOVED_FROM ", sizeof(dbgbuf));
     387      if (event->mask & IN_MOVED_TO) sl_strlcat(dbgbuf, "IN_MOVED_TO ", sizeof(dbgbuf));
     388      if (event->mask & IN_OPEN) sl_strlcat(dbgbuf, "IN_OPEN ", sizeof(dbgbuf));
     389      if (event->mask & IN_IGNORED) sl_strlcat(dbgbuf, "IN_IGNORED ", sizeof(dbgbuf));
     390      if (event->mask & IN_ISDIR) sl_strlcat(dbgbuf, "IN_ISDIR ", sizeof(dbgbuf));
     391      if (event->mask & IN_Q_OVERFLOW) sl_strlcat(dbgbuf, "IN_Q_OVERFLOW ", sizeof(dbgbuf));
     392      if (event->mask & IN_UNMOUNT) sl_strlcat(dbgbuf, "IN_UNMOUNT ", sizeof(dbgbuf));
     393      SH_MUTEX_LOCK(mutex_thread_nolog);
     394      sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, 0, MSG_E_SUBGEN,
     395                      dbgbuf, _("sh_fInotify_process"));
     396      SH_MUTEX_UNLOCK(mutex_thread_nolog);
     397    }
     398
    355399
    356400  if (event->wd >= 0)
     
    438482    }
    439483
    440   if ( (event->mask & (IN_ACCESS|IN_MODIFY)) != 0)
     484  if ( (event->mask & (IN_ATTRIB|IN_MODIFY)) != 0)
    441485    {
    442486      sh_files_search_file(path, &class, &check_mask, &reported);
     
    477521      if (S_FALSE == sh_ignore_chk_new(path))
    478522        {
     523          int ret;
     524
    479525          sh_files_clear_file_reported(path);
    480526         
    481           sh_files_search_file(path, &class, &check_mask, &reported);
     527          ret = sh_files_search_file(path, &class, &check_mask, &reported);
    482528         
    483529          sh_files_filecheck (class, check_mask, filename,
     
    486532          if (SH_FFLAG_REPORTED_SET(reported))
    487533            sh_files_set_file_reported(path);
     534
     535          if (ret != 0)
     536            {
     537              sh_inotify_add_watch(path, &sh_file_watches, &ret,
     538                                   class, check_mask);
     539            }
    488540        }
    489541    }
Note: See TracChangeset for help on using the changeset viewer.