From 1ea241e4cc9529d45817e448c66f85213778f948 Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Thu, 17 Dec 2020 11:11:23 -0800 Subject: Fix seek on /proc/pid/cmdline when task is zombie. PiperOrigin-RevId: 348056159 --- test/syscalls/linux/proc.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/syscalls/linux') diff --git a/test/syscalls/linux/proc.cc b/test/syscalls/linux/proc.cc index 575be014c..e508ce27f 100644 --- a/test/syscalls/linux/proc.cc +++ b/test/syscalls/linux/proc.cc @@ -1802,6 +1802,33 @@ TEST(ProcPidCmdline, SubprocessForkSameCmdline) { } } +TEST(ProcPidCmdline, SubprocessSeekCmdline) { + FileDescriptor fd; + ASSERT_NO_ERRNO(WithSubprocess( + [&](int pid) -> PosixError { + // Running. Open /proc/pid/cmdline. + ASSIGN_OR_RETURN_ERRNO( + fd, Open(absl::StrCat("/proc/", pid, "/cmdline"), O_RDONLY)); + return NoError(); + }, + [&](int pid) -> PosixError { + // Zombie, but seek should still succeed. + int ret = lseek(fd.get(), 0x801, 0); + if (ret < 0) { + return PosixError(errno); + } + return NoError(); + }, + [&](int pid) -> PosixError { + // Exited. + int ret = lseek(fd.get(), 0x801, 0); + if (ret < 0) { + return PosixError(errno); + } + return NoError(); + })); +} + // Test whether /proc/PID/ symlinks can be read for a running process. TEST(ProcPidSymlink, SubprocessRunning) { char buf[1]; -- cgit v1.2.3