Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion include/notify-cpp/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ enum class Event {
delete_self = (1 << 10),
move_self = (1 << 11),



// undefined behaver
none = (1 << 12),
//fanotify only.
q_overflow = (1 << 13),
open_perm = (1 << 14),
ondir = (1 << 15),
on_child = (1 << 16),



// helper
close = Event::close_write | Event::close_nowrite,
Expand Down Expand Up @@ -87,7 +96,7 @@ static const std::array<std::uint32_t, 12> AllFanFlags = {{FAN_ACCESS,
FAN_ALL_CLASS_BITS,
FAN_ENABLE_AUDIT}};
#endif
static const std::array<Event, 15> AllEvents = {Event::access,
static const std::array<Event, 19> AllEvents = {Event::access,
Event::modify,
Event::attrib,
Event::close_write,
Expand All @@ -101,6 +110,10 @@ static const std::array<Event, 15> AllEvents = {Event::access,
Event::move_self,
Event::close,
Event::move,
Event::q_overflow,
Event::open_perm,
Event::ondir,
Event::on_child,
Event::all};

template <>
Expand Down
56 changes: 53 additions & 3 deletions source/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <sys/fanotify.h>
#include <sys/inotify.h>
#include <linux/version.h>

#include <iostream>

Expand Down Expand Up @@ -84,6 +85,12 @@ EventHandler::getInotifyEvent(const Event e) const
return IN_ALL_EVENTS;
case Event::none:
return 0;
case Event::q_overflow:
case Event::open_perm:
case Event::on_child:
case Event::ondir:
assert(!"None existing event");
return 0;
}
return 0;
}
Expand All @@ -96,16 +103,21 @@ EventHandler::getFanotifyEvent(const Event e) const
return FAN_ACCESS;
case Event::modify:
return FAN_MODIFY;
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,1,0)
case Event::attrib:
assert(!"None existing event");
return 0;
#else
case Event::attrib:
return FAN_ATTRIB;
#endif
case Event::close_write:
return FAN_CLOSE_WRITE;
case Event::close_nowrite:
return FAN_CLOSE_NOWRITE;
case Event::open:
return FAN_OPEN;

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,1,0)
case Event::moved_from:
case Event::moved_to:
case Event::create:
Expand All @@ -114,15 +126,37 @@ EventHandler::getFanotifyEvent(const Event e) const
case Event::move_self:
assert(!"None existing event");
return 0;

#else
case Event::moved_from:
return FAN_MOVED_FROM;
case Event::moved_to:
return FAN_MOVED_TO;
case Event::create:
return FAN_CREATE;
case Event::delete_sub:
return FAN_DELETE;
case Event::delete_self:
return FAN_DELETE_SELF;
case Event::move_self:
return FAN_MOVE_SELF;
#endif
case Event::close:
return FAN_CLOSE;

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,1,0)
case Event::move:
case Event::all:
case Event::none:
assert(!"None existing event");
return 0;

#else
case Event::move:
return FAN_MOVE;
case Event::all: //doesn't exist by itself, but its constituents are. Do we emulate this?
case Event::none:
assert(!"None existing event");
return 0;
#endif
}
assert(!"None existing event");
return 0;
Expand Down Expand Up @@ -165,6 +199,14 @@ toString(const Event event)
return std::string("all");
case Event::none:
return std::string("none");
case Event::q_overflow:
return std::string("queue_overflow");
case Event::open_perm:
return std::string("open_perm");
case Event::ondir:
return std::string("ondir");
case Event::on_child:
return std::string("on_child");
}
assert(!"None existing event");
return std::string("ERROR");
Expand Down Expand Up @@ -298,6 +340,14 @@ Event EventHandler::getFanotify(std::uint32_t e) const
return Event::open;
case FAN_CLOSE:
return Event::close;
case FAN_Q_OVERFLOW:
return Event::q_overflow;
case FAN_OPEN_PERM:
return Event::open_perm;
case FAN_ONDIR:
return Event::ondir;
case FAN_EVENT_ON_CHILD:
return Event::on_child;
/* TODO
case FAN_Q_OVERFLOW:
case FAN_OPEN_PERM:
Expand Down
10 changes: 10 additions & 0 deletions source/fanotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>

#include <linux/version.h>
#include <sys/fanotify.h>
Expand Down Expand Up @@ -105,6 +106,15 @@ void Fanotify::watchFile(const FileSystemEvent& fse)

void Fanotify::watch(const std::filesystem::path& path, unsigned int flags, const Event event)
{
//FAN_EVENT_ON_CHILD is ignored with FAN_MARK_MOUNT. Notify the user on this.
if( ((flags & FAN_MARK_MOUNT)!=0) && ((event & Event::on_child) == Event::on_child))
{
std::stringstream errorStream;
errorStream << "watchMountPoint: Event::on_child has no effect on the mountpoint!'";
//
//throw std::runtime_error(errorStream.str());
}

/* Add new fanotify mark */
if (fanotify_mark(_FanotifyFd, flags, getEventMask(event), AT_FDCWD, path.c_str()) < 0) {
std::stringstream errorStream;
Expand Down
Loading