From a480b4faf4befb029bf905fdb604996c8312a6a2 Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Mon, 22 Jun 2020 09:52:51 -0700 Subject: Allow readdir(/proc/[tid]/net) to return EINVAL on a zombie task. Despite what the man page says, linux will return EINVAL when calling getdents() an a /proc/[tid]/net file corresponding to a zombie task. This causes readdir() to return a null pointer AND errno=EINVAL. See fs/proc/proc_net.c:proc_tgid_net_readdir() for where this occurs. We have tests that recursively read /proc, and are likely to hit this when running natively, so we must catch and handle this case. PiperOrigin-RevId: 317674168 --- test/syscalls/linux/proc.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/syscalls/linux/proc.cc b/test/syscalls/linux/proc.cc index d73d392d5..923699ed3 100644 --- a/test/syscalls/linux/proc.cc +++ b/test/syscalls/linux/proc.cc @@ -1967,6 +1967,17 @@ void CheckDuplicatesRecursively(std::string path) { errno = 0; struct dirent* dp = readdir(dir); if (dp == nullptr) { + // Linux will return EINVAL when calling getdents on a /proc/tid/net + // file corresponding to a zombie task. + // See fs/proc/proc_net.c:proc_tgid_net_readdir(). + // + // We just ignore the directory in this case. + if (errno == EINVAL && absl::StartsWith(path, "/proc/") && + absl::EndsWith(path, "/net")) { + break; + } + + // Otherwise, no errors are allowed. ASSERT_EQ(errno, 0) << path; break; // We're done. } -- cgit v1.2.3