Пример #1
0
  void monitor::start()
  {
#ifdef HAVE_CXX_MUTEX
    lock_guard<mutex> run_guard(run_mutex);
#endif
    this->run();
  }
Пример #2
0
  void poll_monitor::run()
  {
    collect_initial_data();

    for (;;)
    {
#ifdef HAVE_CXX_MUTEX
      unique_lock<mutex> run_guard(run_mutex);
      if (should_stop) break;
      run_guard.unlock();
#endif

      FSW_ELOG(_("Done scanning.\n"));

      sleep(latency < MIN_POLL_LATENCY ? MIN_POLL_LATENCY : latency);

      time(&curr_time);

      collect_data();

      if (events.size())
      {
        notify_events(events);
        events.clear();
      }
    }
  }
Пример #3
0
  void kqueue_monitor::run()
  {
    initialize_kqueue();

    for(;;)
    {
#ifdef HAVE_CXX_MUTEX
      unique_lock<mutex> run_guard(run_mutex);
      if (should_stop) break;
      run_guard.unlock();
#endif

      // remove the deleted descriptors
      remove_deleted();

      // rescan the pending descriptors
      rescan_pending();

      // scan the root paths to check whether someone is missing
      scan_root_paths();

      vector<struct kevent> changes;
      vector<struct kevent> event_list;

      for (const pair<int, string>& fd_path : load->file_names_by_descriptor)
      {
        struct kevent change;

        EV_SET(&change,
               fd_path.first,
               EVFILT_VNODE,
               EV_ADD | EV_ENABLE | EV_CLEAR,
               NOTE_DELETE | NOTE_EXTEND | NOTE_RENAME | NOTE_WRITE | NOTE_ATTRIB | NOTE_LINK | NOTE_REVOKE,
               0,
               0);

        changes.push_back(change);
        struct kevent event;
        event_list.push_back(event);
      }

      /*
       * If no files can be observed yet, then wait and repeat the loop.
       */
      if (!changes.size())
      {
        sleep(latency);
        continue;
      }

      const int event_num = wait_for_events(changes, event_list);
      process_events(changes, event_list, event_num);
    }

    terminate_kqueue();
  }
Пример #4
0
void filter(Guard* g, Array* a, Array*& _out) {
  _out = NULL;
  bool  __sa0=(0) < (a->s);
  int  i=0;
  int  outsz=0;
  int*  out= new int [a->s]; CopyArr<int >(out,0, a->s);
  while (__sa0) {
    bool  _out_s64=0;
    run_guard(g, (a->A[i]), _out_s64);
    if (_out_s64) {
      int  uo_s2=outsz;
      outsz = outsz + 1;
      (out[uo_s2]) = (a->A[i]);
    }
    i = i + 1;
    __sa0 = (i) < (a->s);
  }
  _out = Array::create(outsz, (out+ 0), outsz);
  delete[] out;
  return;
}
Пример #5
0
  void monitor::inactivity_callback(monitor *mon)
  {
    if (!mon) throw libfsw_exception(_("Callback argument cannot be null."));

    FSW_ELOG(_("Inactivity notification thread: starting\n"));

    for (;;)
    {
      std::unique_lock<std::mutex> run_guard(mon->run_mutex);
      if (mon->should_stop) break;
      run_guard.unlock();

      milliseconds elapsed =
        duration_cast<milliseconds>(system_clock::now().time_since_epoch())
        - mon->last_notification.load();

      // Sleep and loop again if sufficient time has not elapsed yet.
      if (elapsed < mon->get_latency_ms())
      {
        milliseconds to_sleep = mon->get_latency_ms() - elapsed;
        seconds max_sleep_time(2);

        std::this_thread::sleep_for(
          to_sleep > max_sleep_time ? max_sleep_time : to_sleep);
        continue;
      }

      // Build a fake event.
      time_t curr_time;
      time(&curr_time);

      std::vector<event> events;
      events.push_back({"", curr_time, {NoOp}});

      mon->notify_events(events);
    }

    FSW_ELOG(_("Inactivity notification thread: exiting\n"));
  }
Пример #6
0
void recursive_expression(Array* a, int bnd, Array*& _out, bool* tape__ANONYMOUS_s106/* len = 143 */, int& tape_index__ANONYMOUS_s85) {
  _out = NULL;
  if ((bnd) < (0)) {
    _out = NULL;
    return;
  }
  tape_index__ANONYMOUS_s85 = 0;
  bool  s1=0;
  bool  s2=0;
  bool  s3=0;
  bool  s4=0;
  bool  s5=0;
  bool  s6=0;
  Guard*  g_s8=NULL;
  guard_expression(a, 3, s1, g_s8, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
  int  target_s10=0;
  integer_expression(a, 3, s2, target_s10, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
  assertion ((tape_index__ANONYMOUS_s85) == (16));;
  Array*  b_s12=NULL;
  array_expression(a, 4, s3, b_s12, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
  Array*  x_s14=NULL;
  array_expression(a, 4, s4, x_s14, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
  Array*  x=NULL;
  x = x_s14;
  bool  rx_s16=0;
  flip(rx_s16, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
  Array*  y_s18=NULL;
  array_expression(a, 4, s5, y_s18, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
  Array*  y=NULL;
  y = y_s18;
  bool  ry_s20=0;
  flip(ry_s20, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
  Array*  z_s22=NULL;
  array_expression(a, 4, s6, z_s22, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
  Array*  z=NULL;
  z = z_s22;
  bool  rz_s24=0;
  flip(rz_s24, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
  assertion ((s1 && s2) && s3);;
  bool  _out_s26=0;
  run_guard(g_s8, target_s10, _out_s26);
  if (_out_s26) {
    _out = b_s12;
    return;
  }
  assertion ((s4 && s5) && s6);;
  if (rz_s24) {
    assertion ((x_s14->s) < (a->s));;
    Array*  x_s28=NULL;
    recursive_expression(x_s14, bnd - 1, x_s28, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
    x = x_s28;
  }
  if (ry_s20) {
    assertion ((y_s18->s) < (a->s));;
    Array*  y_s30=NULL;
    recursive_expression(y_s18, bnd - 1, y_s30, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
    y = y_s30;
  }
  if (rz_s24) {
    assertion ((z_s22->s) < (a->s));;
    Array*  z_s32=NULL;
    recursive_expression(z_s22, bnd - 1, z_s32, tape__ANONYMOUS_s106, tape_index__ANONYMOUS_s85);
    z = z_s32;
  }
  Array*  _out_s34=NULL;
  concatenate3(x, y, z, _out_s34);
  _out = _out_s34;
  return;
}