diff options
author | Fabricio Voznika <fvoznika@google.com> | 2018-12-21 11:52:39 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-12-21 11:54:02 -0800 |
commit | 1679ef31ef15344eba218a5251fa1fb1438b4cb7 (patch) | |
tree | 8ca6bb1f5a074dfc21925f31f5f461fc93b140c0 /test/syscalls/linux/inotify.cc | |
parent | 5c7f70a07d8f4b08db3446e0cf75ad43bb2c1953 (diff) |
inotify notifies watchers when control events bit are set
The code that matches the event being published with events watchers
was wronly matching all watchers in case any of the control event bits
were set.
Issue #121
PiperOrigin-RevId: 226521230
Change-Id: Ie2c42bc4366faaf59fbf80a74e9297499bd93f9e
Diffstat (limited to 'test/syscalls/linux/inotify.cc')
-rw-r--r-- | test/syscalls/linux/inotify.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/syscalls/linux/inotify.cc b/test/syscalls/linux/inotify.cc index 62fc55c72..0e361496c 100644 --- a/test/syscalls/linux/inotify.cc +++ b/test/syscalls/linux/inotify.cc @@ -1484,6 +1484,34 @@ TEST(Inotify, MaskAddMergesWithExistingEventMask) { ASSERT_THAT(events, Are({Event(IN_CLOSE_WRITE, wd)})); } +// Test that control events bits are not considered when checking event mask. +TEST(Inotify, ControlEvents) { + const TempPath dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir()); + const FileDescriptor fd = + ASSERT_NO_ERRNO_AND_VALUE(InotifyInit1(IN_NONBLOCK)); + + const int wd = ASSERT_NO_ERRNO_AND_VALUE( + InotifyAddWatch(fd.get(), dir.path(), IN_ACCESS)); + + // Check that events in the mask are dispatched and that control bits are + // part of the event mask. + std::vector<std::string> files = + ASSERT_NO_ERRNO_AND_VALUE(ListDir(dir.path(), false)); + ASSERT_EQ(files.size(), 2); + + const std::vector<Event> events1 = + ASSERT_NO_ERRNO_AND_VALUE(DrainEvents(fd.get())); + ASSERT_THAT(events1, Are({Event(IN_ACCESS | IN_ISDIR, wd)})); + + // Check that events not in the mask are discarded. + const FileDescriptor dir_fd = + ASSERT_NO_ERRNO_AND_VALUE(Open(dir.path(), O_RDONLY | O_DIRECTORY)); + + const std::vector<Event> events2 = + ASSERT_NO_ERRNO_AND_VALUE(DrainEvents(fd.get())); + ASSERT_THAT(events2, Are({})); +} + } // namespace } // namespace testing } // namespace gvisor |