Merge pull request #282 from zhangningdlut:chris_test_proc

PiperOrigin-RevId: 257855479
This commit is contained in:
gVisor bot 2019-07-12 13:11:01 -07:00
commit eff2c264a4
2 changed files with 21 additions and 1 deletions

View File

@ -162,6 +162,11 @@ func (f *subtasksFile) Readdir(ctx context.Context, file *fs.File, ser fs.Dentry
// subtask to emit.
offset := file.Offset()
tasks := f.t.ThreadGroup().MemberIDs(f.pidns)
if len(tasks) == 0 {
return offset, syserror.ENOENT
}
if offset == 0 {
// Serialize "." and "..".
root := fs.RootFromContext(ctx)
@ -178,7 +183,6 @@ func (f *subtasksFile) Readdir(ctx context.Context, file *fs.File, ser fs.Dentry
}
// Serialize tasks.
tasks := f.t.ThreadGroup().MemberIDs(f.pidns)
taskInts := make([]int, 0, len(tasks))
for _, tid := range tasks {
taskInts = append(taskInts, int(tid))

View File

@ -1964,6 +1964,22 @@ TEST(ProcPid, RootDumpableOwner) {
EXPECT_THAT(st.st_gid, AnyOf(Eq(0), Eq(65534)));
}
TEST(Proc, GetdentsEnoent) {
FileDescriptor fd;
ASSERT_NO_ERRNO(WithSubprocess(
[&](int pid) -> PosixError {
// Running.
ASSIGN_OR_RETURN_ERRNO(fd, Open(absl::StrCat("/proc/", pid, "/task"),
O_RDONLY | O_DIRECTORY));
return NoError();
},
nullptr, nullptr));
char buf[1024];
ASSERT_THAT(syscall(SYS_getdents, fd.get(), buf, sizeof(buf)),
SyscallFailsWithErrno(ENOENT));
}
} // namespace
} // namespace testing
} // namespace gvisor