fswatch 1.20.1
Loading...
Searching...
No Matches
fsw::fanotify_monitor Class Reference

Linux fanotify monitor. More...

#include <fanotify_monitor.hpp>

Inheritance diagram for fsw::fanotify_monitor:
fsw::monitor

Public Member Functions

 fanotify_monitor (std::vector< std::string > paths, FSW_EVENT_CALLBACK *callback, void *context=nullptr)
Public Member Functions inherited from fsw::monitor
 monitor (std::vector< std::string > paths, FSW_EVENT_CALLBACK *callback, void *context=nullptr)
 Constructs a monitor watching the specified paths.
virtual ~monitor ()
 Destructs a monitor instance.
 monitor (const monitor &orig)=delete
 This class is not copy constructible.
monitoroperator= (const monitor &that)=delete
 This class is not copy assignable.
void set_property (const std::string &name, const std::string &value)
 Sets a custom property.
void set_properties (const std::map< std::string, std::string > options)
 Sets the custom properties.
std::string get_property (std::string name)
 Gets the value of a property.
void set_latency (double latency)
 Sets the latency.
void set_fire_idle_event (bool fire_idle_event)
 Sets the fire idle event flag.
void set_allow_overflow (bool overflow)
 Notify buffer overflows as change events.
void set_recursive (bool recursive)
 Recursively scan subdirectories.
void set_directory_only (bool directory_only)
 Watch directories only.
void add_filter (const monitor_filter &filter)
 Add a path filter.
void set_filters (const std::vector< monitor_filter > &filters)
 Set the path filters.
void set_follow_symlinks (bool follow)
 Follow symlinks.
void * get_context () const
 Get the pointer to the context data.
void set_context (void *context)
 Set the context data.
void set_bubble_events (bool bubble_events)
 Set the bubble events flag.
void start ()
 Start the monitor.
void stop ()
 Stop the monitor.
bool is_running ()
 Check whether the monitor is running.
void add_event_type_filter (const fsw_event_type_filter &filter)
 Add an event type filter.
void set_event_type_filters (const std::vector< fsw_event_type_filter > &filters)
 Set the event type filters.
void set_watch_access (bool access)
 Monitor file access.

Static Public Attributes

static constexpr const char * PROCESS_ID_PROPERTY = "fanotify.process-id"
static constexpr const char * REPORT_PIDFD_PROPERTY = "fanotify.report-pidfd"
static constexpr const char * UNLIMITED_QUEUE_PROPERTY = "fanotify.unlimited-queue"
static constexpr const char * UNLIMITED_MARKS_PROPERTY = "fanotify.unlimited-marks"

Protected Member Functions

void run () override
 Execute monitor loop.
void on_stop () override
 Execute an implementation-specific stop handler.
Protected Member Functions inherited from fsw::monitor
bool accept_event_type (fsw_event_flag event_type) const
 Check whether an event should be accepted.
bool accept_path (const std::string &path) const
 Check whether a path should be accepted.
void notify_events (const std::vector< event > &events) const
 Notify change events.
void notify_overflow (const std::string &path) const
 Notify an overflow event.
std::vector< fsw_event_flagfilter_flags (const event &evt) const
 Filter event types.

Additional Inherited Members

Protected Attributes inherited from fsw::monitor
std::vector< std::string > paths
 List of paths to watch.
std::map< std::string, std::string > properties
 Map of custom properties.
FSW_EVENT_CALLBACKcallback
 Callback to which change events should be notified.
void * context = nullptr
 Pointer to context data that will be passed to the monitor::callback.
double latency = 1.0
 Latency of the monitor.
bool fire_idle_event = false
 If true, the monitor will notify an event when idle.
bool allow_overflow = false
 If true, queue overflow events will be notified to the caller, otherwise the monitor will throw a libfsw_exception.
bool recursive = false
 If true, directories will be scanned recursively.
bool follow_symlinks = false
 If true, symbolic links are followed.
bool directory_only = false
 Flag indicating whether only directories should be monitored.
bool watch_access = false
 Flag indicating whether file access should be watched.
bool running = false
 Flag indicating whether the monitor is in the running state.
bool should_stop = false
 Flag indicating whether the monitor should preemptively stop.
bool bubble_events = false
 Bubble events by joining flags received for the same (time, path) pair.
std::mutex run_mutex
 Mutex used to serialize access to the monitor state from multiple threads.
std::mutex notify_mutex
 Mutex used to serialize access to the notify_events() method.

Detailed Description

Linux fanotify monitor.

This monitor is backed by the Linux fanotify API and is available only on systems whose headers and C library expose the required fanotify features.

Member Function Documentation

◆ on_stop()

void fsw::fanotify_monitor::on_stop ( )
overrideprotectedvirtual

Execute an implementation-specific stop handler.

This function is executed by the stop() method, after requesting the monitor to stop. This handler is required if the thread running run() is not able to preemptively stop its execution by checking the monitor::should_stop flag.

See also
stop()

Reimplemented from fsw::monitor.

◆ run()

void fsw::fanotify_monitor::run ( )
overrideprotectedvirtual

Execute monitor loop.

This function implements the monitor event watching logic. This function is called from start() and it is executed on its thread. This function should block until the monitoring loop terminates: when it returns, the monitor is marked as stopped.

This function should cooperatively check the monitor::should_stop field locking monitor::run_mutex and return if set to true.

See also
start()
stop()

Implements fsw::monitor.


The documentation for this class was generated from the following files: