pike.git / lib / modules / Filesystem.pmod / Monitor.pmod / basic.pike

version» Context lines:

pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:8:   //   //! Basic filesystem monitor.   //!   //! This module is intended to be used for incremental scanning of   //! a filesystem.   //!   //! Supports FSEvents on MacOS X and Inotify on Linux to provide low   //! overhead monitoring; other systems use a less efficient polling approach.   //!   //! @seealso - //! @[System.FSEvents], @[System.Inotify] + //! @[Filesystem.Monitor.symlinks], @[System.FSEvents], @[System.Inotify]    - #ifdef FILESYSTEM_MONITOR_DEBUG - #define MON_WERR(X...) werror(X) - #else - #define MON_WERR(X...) - #endif -  +    //! The default maximum number of seconds between checks of directories   //! in seconds.   //!   //! This value is multiplied with @[default_file_interval_factor] to   //! get the corresponding default maximum number of seconds for files.   //!   //! The value can be changed by calling @[create()].   //!   //! The value can be overridden for individual files or directories   //! by calling @[monitor()].
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:49:   protected constant default_file_interval_factor = 5;      //! The default minimum number of seconds without changes for a change   //! to be regarded as stable (see @[stable_data_change()].   protected constant default_stable_time = 5;      protected int max_dir_check_interval = default_max_dir_check_interval;   protected int file_interval_factor = default_file_interval_factor;   protected int stable_time = default_stable_time;    + protected inline constant SeverityLevel = DefaultCompilerEnvironment.SeverityLevel; + protected inline constant NOTICE = DefaultCompilerEnvironment.NOTICE; + protected inline constant WARNING = DefaultCompilerEnvironment.WARNING; + protected inline constant ERROR = DefaultCompilerEnvironment.ERROR; + protected inline constant FATAL = DefaultCompilerEnvironment.FATAL; +    // Callbacks    -  + //! Event tracing callback. + //! + //! @param level + //! Severity level of the event. + //! + //! @param fun + //! Name of the function that called @[report()]. + //! + //! @param format + //! @[sprintf()] formatting string describing the event. + //! + //! @param args + //! Optional extra arguments for the @[format] string. + //! + //! This function is called in various places to provide + //! granular tracing of the monitor state. + //! + //! The default implementation calls @[werror()] with + //! @[format] and @[args] if @[level] is @[ERROR] or higher, + //! or if @tt{FILESYSTEM_MONITOR_DEBUG@} has been defined. + protected void report(SeverityLevel level, string(7bit) fun, +  sprintf_format format, sprintf_args ... args) + { + #ifndef FILESYSTEM_MONITOR_DEBUG +  if (level < ERROR) return; + #endif +  werror(format, @args); + } +  + #define MON_WERR(X...) report(NOTICE, __func__, X) + #define MON_WARN(X...) report(WARNING, __func__, X) + #define MON_ERROR(X...) report(ERROR, __func__, X) +    //! File content changed callback.   //!   //! @param path   //! Path of the file which has had content changed.   //!   //! This function is called when a change has been detected for a   //! monitored file.   //!   //! Called by @[check()] and @[check_monitor()].   //!
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:187:    inherit ADT.Heap.Element;       int next_poll;    Stdio.Stat st;    int last_change = 0x7fffffff; // Future... Can be set to -0x7fffffff    // to indicate immediate stabilization    // (avoid an extra check() round to    // let the stat stabilize).    array(string) files;    +  //! Event tracing callback. +  //! +  //! @param level +  //! Severity level of the event. +  //! +  //! @param fun +  //! Name of the function that called @[report()]. +  //! +  //! @param format +  //! @[sprintf()] formatting string describing the event. +  //! +  //! @param args +  //! Optional extra arguments for the @[format] string. +  //! +  //! This function is called in various places to provide +  //! granular tracing of the monitor state. +  //! +  //! The default implementation just calls @[global::report()] +  //! with the same arguments. +  protected void report(SeverityLevel level, string(7bit) fun, +  sprintf_format format, sprintf_args ... args) +  { +  global::report(level, fun, format, @args); +  } +     //! Register the @[Monitor] with the monitoring system.    //!    //! @param initial    //! Indicates that the @[Monitor] is newly created.    protected void register_path(int|void initial)    {    if (initial) {    // We need to be polled...    MON_WERR("Registering %O for polling.\n", path);    mixed key = monitor_mutex->lock();
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:800: Inside #if HAVE_EVENTSTREAM
   if(Monitor m = monitors[checkpath]) {    MON_WERR("Found monitor %O for path %O.\n", m, checkpath);    m->check(monitor_flags);    found = 1;    break;    }    checkpath = dirname (checkpath);    }       if (!found) -  MON_WERR("No monitor found for path %O.\n", path); +  MON_WARN("No monitor found for path %O.\n", path);   }      protected void eventstream_callback(string path, int flags, int event_id)   {    if (backend)    backend->call_out(low_eventstream_callback, 0, path, flags, event_id);    else    low_eventstream_callback(path, flags, event_id);   }   
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:843:    inherit Monitor;       protected void register_path(int|void initial)    {   #ifndef INHIBIT_EVENTSTREAM_MONITOR    if (initial) {    if (Pike.DefaultBackend.executing_thread() != Thread.this_thread()) {    // eventstream stuff (especially start()) must be called from    // the backend thread, otherwise events will be fired in    // CFRunLoop contexts where noone listens. +  MON_WERR("%O: Switching to backend thread.\n", this_function);    call_out(register_path, 0, initial);    return;    }       // We're now in the main backend.       if (!eventstream) {    start_accelerator();    }   
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:876: Inside #if undefined(INHIBIT_EVENTSTREAM_MONITOR)
   mixed err = catch {    MON_WERR("Adding %O to the set of monitored paths.\n", path);    eventstream_paths += ({path});    if(eventstream->is_started())    eventstream->stop();    eventstream->add_path(path);    eventstream->start();    };       if (err) { -  werror("%O: Failed to register path %O.\n", this_function, path); +  MON_ERROR("%O: Failed to register path %O.\n", this_function, path);    master()->handle_error(err);    }    }    // Note: Falling through to ::register_path() below.    // This is needed to handle paths mounted on eg network    // filesystems that are modified on other machines.    }   #endif /* !INHIBIT_EVENTSTREAM_MONITOR */    ::register_path(initial);    }
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:924:    } else if (m->flags & MF_RECURSE) {    // We've missed creation of the submonitor.    //    // This can happen in the    //    // Exist ==> Deleted ==> Exists    //    // with no update of the directory inbetween race-condition.    //    // Create the submonitor. -  MON_WERR("Monitor lost for path %O.\n", full_path); +  MON_WARN("Monitor lost for path %O.\n", full_path);    monitor(full_path, m->flags | MF_AUTO | MF_HARD,    m->max_dir_check_interval,    m->file_interval_factor,    m->stable_time);    m = monitors[full_path];    m->check(0); // Init monitor.    }    }    }   
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:953:    if (event & System.Inotify.IN_CLOSE_WRITE)    // File marked as stable immediately.    m->last_change = -0x7fffffff;    m->check(0);    };    if (err) {    master()->handle_error(err);    }    } else {    // Most likely not reached. -  MON_WERR("Monitor not found for cookie %O, path %O.\n", icookie, path); +  MON_WARN("Monitor not found for cookie %O, path %O.\n", icookie, path);    }   }      protected void start_accelerator()   {    MON_WERR("Creating Inotify monitor instance.\n");    instance = System.Inotify._Instance();    if (backend) instance->set_backend(backend);    instance->set_event_callback(inotify_event);    if (co_id) {
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1052:    MON_WERR("### Unregistering from inotify.\n");    // NB: Inotify automatically removes watches for deleted files,    // and will complain if we attempt to remove them too.    //    // Since we have no idea if there's already a queued ID_IGNORED    // pending we just throw away any error here.    mixed err = catch {    instance->rm_watch(wd);    };    if (err) { -  MON_WERR("### Failed to unregister %O: %s\n", +  MON_WARN("### Failed to unregister %O: %s\n",    path, describe_backtrace(err));    }    }    wd = -1;    }    ::unregister_path(dying);    }   }      constant DefaultMonitor = InotifyMonitor;