fswatch 1.20.1
Loading...
Searching...
No Matches
fanotify_monitor.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Enrico M. Crisostomo
3 *
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 3, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 * details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 */
20
21#ifndef FSW_FANOTIFY_MONITOR_H
22# define FSW_FANOTIFY_MONITOR_H
23
24# include "monitor.hpp"
25# include <string>
26# include <vector>
27# include <filesystem>
28# include <memory>
29# include <sys/types.h>
30
31namespace fsw
32{
34
41 class fanotify_monitor : public monitor
42 {
43 public:
44 static constexpr const char *PROCESS_ID_PROPERTY = "fanotify.process-id";
45 static constexpr const char *REPORT_PIDFD_PROPERTY = "fanotify.report-pidfd";
46 static constexpr const char *UNLIMITED_QUEUE_PROPERTY = "fanotify.unlimited-queue";
47 static constexpr const char *UNLIMITED_MARKS_PROPERTY = "fanotify.unlimited-marks";
48
49 fanotify_monitor(std::vector<std::string> paths,
51 void *context = nullptr);
52
53 ~fanotify_monitor() override;
54
55 protected:
56 void run() override;
57 void on_stop() override;
58
59 private:
60 fanotify_monitor(const fanotify_monitor& orig) = delete;
61 fanotify_monitor& operator=(const fanotify_monitor& that) = delete;
62
63 void initialize();
64 void scan_root_paths();
65 void scan(const std::filesystem::path& path, bool accept_non_dirs = true);
66 bool add_mark(const std::filesystem::path& path);
67 bool is_watched(const std::string& path) const;
68 void process_pending_paths();
69 void process_synthetic_events();
70 void process_events(char *buffer, ssize_t length);
71 void notify_and_clear_events();
72
73 std::unique_ptr<fanotify_monitor_impl> impl;
74 };
75}
76
77#endif /* FSW_FANOTIFY_MONITOR_H */
void run() override
Execute monitor loop.
Definition fanotify_monitor.cpp:632
void on_stop() override
Execute an implementation-specific stop handler.
Definition fanotify_monitor.cpp:614
std::vector< std::string > paths
List of paths to watch.
Definition monitor.hpp:527
void * context
Pointer to context data that will be passed to the monitor::callback.
Definition monitor.hpp:547
FSW_EVENT_CALLBACK * callback
Callback to which change events should be notified.
Definition monitor.hpp:542
monitor(std::vector< std::string > paths, FSW_EVENT_CALLBACK *callback, void *context=nullptr)
Constructs a monitor watching the specified paths.
Definition monitor.cpp:50
Header of the fsw::monitor class.
Main namespace of libfswatch.
Definition event.cpp:24
void FSW_EVENT_CALLBACK(const std::vector< event > &, void *)
Function definition of an event callback.
Definition monitor.hpp:57
Definition fanotify_monitor.cpp:240