Handle IN_DONT_FOLLOW correctly in VFS2 inotify.

Added a syscall test for IN_DONT_FOLLOW as well.

PiperOrigin-RevId: 462224328
This commit is contained in:
Ayush Ranjan
2022-07-20 14:03:14 -07:00
committed by gVisor bot
parent 21981a2bda
commit 567444310c
2 changed files with 28 additions and 3 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ func InotifyAddWatch(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kern
// "IN_DONT_FOLLOW: Don't dereference pathname if it is a symbolic link."
// -- inotify(7)
follow := followFinalSymlink
if mask&linux.IN_DONT_FOLLOW == 0 {
if mask&linux.IN_DONT_FOLLOW != 0 {
follow = nofollowFinalSymlink
}
+27 -2
View File
@@ -1303,8 +1303,7 @@ TEST(Inotify, SymlinkGeneratesCreateEvent) {
const int root_wd = ASSERT_NO_ERRNO_AND_VALUE(
InotifyAddWatch(fd.get(), root.path(), IN_ALL_EVENTS));
ASSERT_NO_ERRNO_AND_VALUE(
InotifyAddWatch(fd.get(), file1.path(), IN_ALL_EVENTS));
ASSERT_NO_ERRNO(InotifyAddWatch(fd.get(), file1.path(), IN_ALL_EVENTS));
ASSERT_THAT(symlink(file1.path().c_str(), link1.path().c_str()),
SyscallSucceeds());
@@ -1315,6 +1314,32 @@ TEST(Inotify, SymlinkGeneratesCreateEvent) {
ASSERT_THAT(events, Are({Event(IN_CREATE, root_wd, Basename(link1.path()))}));
}
TEST(Inotify, SymlinkFollow) {
const TempPath file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile());
const TempPath link(NewTempAbsPath());
ASSERT_THAT(symlink(file.path().c_str(), link.path().c_str()),
SyscallSucceeds());
const FileDescriptor fd =
ASSERT_NO_ERRNO_AND_VALUE(InotifyInit1(IN_NONBLOCK));
const int file_wd = ASSERT_NO_ERRNO_AND_VALUE(
InotifyAddWatch(fd.get(), link.path(), IN_ALL_EVENTS));
const int link_wd = ASSERT_NO_ERRNO_AND_VALUE(
InotifyAddWatch(fd.get(), link.path(), IN_ALL_EVENTS | IN_DONT_FOLLOW));
ASSERT_NO_ERRNO(Unlink(file.path()));
ASSERT_NO_ERRNO(Unlink(link.path()));
const std::vector<Event> events =
ASSERT_NO_ERRNO_AND_VALUE(DrainEvents(fd.get()));
ASSERT_THAT(
events,
Are({Event(IN_ATTRIB, file_wd), Event(IN_DELETE_SELF, file_wd),
Event(IN_IGNORED, file_wd), Event(IN_ATTRIB, link_wd),
Event(IN_DELETE_SELF, link_wd), Event(IN_IGNORED, link_wd)}));
}
TEST(Inotify, LinkGeneratesAttribAndCreateEvents) {
// Inotify does not work properly with hard links in gofer and overlay fs.
SKIP_IF(IsRunningOnGvisor() &&