From 9de9c77d91b71832bd973c6a18f32a7a33af4760 Mon Sep 17 00:00:00 2001 From: jay Date: Sat, 28 Jun 2014 09:59:00 +0000 Subject: [PATCH] Make Zenmap use SIGTERM (instead of SIGKILL) for "Cancel Scan" so that Nmap has a chance to shutdown cleanly. However, if Nmap is still running after 5 seconds, send a SIGKILL. --- zenmap/zenmapCore/NmapCommand.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/zenmap/zenmapCore/NmapCommand.py b/zenmap/zenmapCore/NmapCommand.py index a71a3968b..accc18493 100644 --- a/zenmap/zenmapCore/NmapCommand.py +++ b/zenmap/zenmapCore/NmapCommand.py @@ -252,13 +252,22 @@ class NmapCommand(object): def kill(self): """Kill the nmap subprocess.""" + from time import sleep + log.debug(">>> Killing scan process %s" % self.command_process.pid) if sys.platform != "win32": try: - from signal import SIGKILL - os.kill(self.command_process.pid, SIGKILL) - self.command_process.wait() + from signal import SIGTERM, SIGKILL + os.kill(self.command_process.pid, SIGTERM) + for i in range(10): + sleep(0.5) + if self.command_process.poll() is not None: # Process has been TERMinated + break + else: + log.debug(">>> SIGTERM has not worked even after waiting for 5 seconds. Using SIGKILL.") + os.kill(self.command_process.pid, SIGKILL) + self.command_process.wait() except: pass else: