FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Do not add (self) events for FSEvents · TomA-R/osquery@db3782b · GitHub

/ osquery Public
forked from osquery/osquery

Commit db3782b

Browse files
Teddy Reed
committed
Do not add (self) events for FSEvents
1 parent d379264 commit db3782b

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎osquery/events/darwin/fsevents.cpp‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,24 @@ void FSEventsEventPublisher::restart() {
8282
// Remove any existing stream.
8383
stop();
8484

85-
// Create the FSEvent stream
85+
// Set stream flags.
86+
auto flags =
87+
kFSEventStreamCreateFlagFileEvents | kFSEventStreamCreateFlagWatchRoot;
88+
if (no_defer_) {
89+
flags |= kFSEventStreamCreateFlagNoDefer;
90+
}
91+
if (no_self_) {
92+
flags |= kFSEventStreamCreateFlagIgnoreSelf;
93+
}
94+
95+
// Create the FSEvent stream.
8696
stream_ = FSEventStreamCreate(nullptr,
8797
&FSEventsEventPublisher::Callback,
8898
nullptr,
8999
watch_list,
90100
kFSEventStreamEventIdSinceNow,
91101
1,
92-
kFSEventStreamCreateFlagFileEvents |
93-
kFSEventStreamCreateFlagNoDefer |
94-
kFSEventStreamCreateFlagWatchRoot);
102+
flags);
95103
if (stream_ != nullptr) {
96104
// Schedule the stream on the run loop.
97105
FSEventStreamScheduleWithRunLoop(stream_, run_loop_, kCFRunLoopDefaultMode);

‎osquery/events/darwin/fsevents.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,16 @@ class FSEventsEventPublisher
144144
/// Set of paths to monitor, determined by a configure step.
145145
std::set<std::string> paths_;
146146

147+
/// Reference to the run loop for this thread.
147148
CFRunLoopRef run_loop_{nullptr};
148149

150+
private:
151+
/// For testing only, ask the event stream to publish events immediately.
152+
bool no_defer_{false};
153+
154+
/// For testing only, allow the event stream to publish its own events.
155+
bool no_self_{true};
156+
149157
private:
150158
friend class FSEventsTests;
151159
FRIEND_TEST(FSEventsTests, test_register_event_pub);

‎osquery/events/darwin/tests/fsevents_tests.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class FSEventsTests : public testing::Test {
4040

4141
void StartEventLoop() {
4242
event_pub_ = std::make_shared<FSEventsEventPublisher>();
43+
event_pub_->no_defer_ = true;
44+
event_pub_->no_self_ = false;
4345
EventFactory::registerEventPublisher(event_pub_);
4446
FILE* fd = fopen(trigger_path.c_str(), "w");
4547
fclose(fd);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL