diff --git a/test/zdtm.py b/test/zdtm.py index 7a7cdfd3b61..3cec4062b11 100755 --- a/test/zdtm.py +++ b/test/zdtm.py @@ -40,6 +40,7 @@ def alarm(*args): print("==== ALARM ====") + raise InterruptedError("ALARM") def traceit(f, e, a): @@ -717,11 +718,9 @@ def start(self): # regular files, so we loop. data = b'' while not data: - # In python 2.7, peer_file.read() doesn't call the read - # system call if it's read file to the end once. The - # next seek allows to workaround this problem. - data = os.read(peer_file.fileno(), 16) + data = os.read(peer_file.fileno(), len(msg) + 16) time.sleep(0.1) + peer_file.close() except Exception as e: print("Unable to read a peer file: %s" % e) sys.exit(1) @@ -752,7 +751,16 @@ def stop(self): my_file.write(msg) my_file.flush() i += 1 - pid, status = os.waitpid(self.__peer_pid, 0) + signal.alarm(10) + try: + pid, status = os.waitpid(self.__peer_pid, 0) + except InterruptedError: + fds = set(os.listdir("/proc/%s/fd" % self.__peer_pid)) + self.kill() + pid, status = os.waitpid(self.__peer_pid, 0) + fds = self.__fds.difference(fds) + if fds: + print("before SIGKILL, child managed to close fds: " + str(fds)) with open(self.__name + ".out") as output: print(output.read()) self.__peer_pid = 0