From 213db13fcc39a098a7d91f85c16e9c498be35a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0imerda?= Date: Thu, 12 May 2016 14:41:23 +0200 Subject: [PATCH] ignore `ESRCH` on processes to be killed Sometimes a debugged process is already gone when python-ptrace performs steps to terminate it. In that case we need to gracefully ignore any `ESRCH` errors. This issue was discovered when running network-testing[1] and resulted in the following traceback. Traceback (most recent call last): File "./test-client-server", line 5, in main() File "/home/pavlix/oss/network-testing/network_testing/client_server.py", line 55, in main suite.run() File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 431, in run testcase.run() File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 391, in run scenario.run() File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 172, in run debugger.quit() File "/home/pavlix/oss/network-testing/network_testing/debug.py", line 198, in quit super(SyscallDebugger, self).quit() File "/usr/lib64/python3.4/site-packages/ptrace/debugger/debugger.py", line 105, in quit process.terminate() File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 330, in terminate self.waitExit() File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 351, in waitExit self.cont(signum) File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 717, in cont ptrace_cont(self.pid, signum) File "/usr/lib64/python3.4/site-packages/ptrace/binding/func.py", line 212, in ptrace_cont ptrace(PTRACE_CONT, pid, 0, signum) File "/usr/lib64/python3.4/site-packages/ptrace/binding/func.py", line 148, in ptrace raise PtraceError(message, errno=errno, pid=pid) ptrace.error.PtraceError: ptrace(cmd=7, pid=12894, 0, 133) error #3: No such process [1]: https://github.com/pavlix/network-testing --- ptrace/debugger/process.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ptrace/debugger/process.py b/ptrace/debugger/process.py index a759d2b..542ac2a 100644 --- a/ptrace/debugger/process.py +++ b/ptrace/debugger/process.py @@ -723,7 +723,11 @@ def dumpRegs(self, log=None): def cont(self, signum=0): signum = self.filterSignal(signum) - ptrace_cont(self.pid, signum) + try: + ptrace_cont(self.pid, signum) + except PtraceError as error: + if error.errno != 3: + raise self.is_stopped = False def setoptions(self, options):