From 75491b75aad671ca5a3281b62855796d13b8f309 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Tue, 9 Jun 2015 13:40:12 -0400 Subject: [PATCH] Task 46440 Cleanup the nmap process for switchdiscover command --- xCAT-server/lib/xcat/plugins/switchdiscover.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index a00245822..197d70f3a 100755 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -627,6 +627,16 @@ sub nmap_scan { } } + # handle ctrl-c + $SIG{TERM} = $SIG{INT} = sub { + #clean up the nmap processes + my $nmap_pid = `ps -ef | grep nmap | grep -v grep | awk '{print \$2}'`; + if ($nmap_pid) { + system("kill -9 $nmap_pid >/dev/null 2>&1"); + exit 0; + } + }; + $ccmd = "/usr/bin/nmap -sP -oX - @$ranges"; my $result = xCAT::Utils->runcmd($ccmd, 0); if ($::RUNCMD_RC != 0)