From 01d73715067f681e555a17581b3181661133e301 Mon Sep 17 00:00:00 2001 From: chenglch Date: Fri, 27 May 2016 02:51:39 -0400 Subject: [PATCH] Fix error when stopping tftp process in AAsn.pm The check logic that wait for the tftp process can not be finished due to the empty loop. This patch aims to check the status of process group in the loop. close-issue: #1219 --- xCAT-server/lib/xcat/plugins/AAsn.pm | 47 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/AAsn.pm b/xCAT-server/lib/xcat/plugins/AAsn.pm index e09e33aba..49523111e 100755 --- a/xCAT-server/lib/xcat/plugins/AAsn.pm +++ b/xCAT-server/lib/xcat/plugins/AAsn.pm @@ -1411,31 +1411,38 @@ sub enable_TFTPhpa if (-x "/usr/sbin/in.tftpd") { - system("killall in.tftpd"); #xinetd can leave behind blocking tftp servers even if it won't start new ones - if ($distro =~ /ubuntu.*/i){ - sleep 1; - my @checkproc=`ps axf|grep -v grep|grep in.tftpd`; - if (@checkproc){ - system("stop tftpd-hpa"); + system("killall in.tftpd"); #xinetd can leave behind blocking tftp servers even if it won't start new ones + if ($distro =~ /ubuntu.*/i || $distro =~ /debian.*/i){ + sleep 1; + my @checkproc=`ps axf|grep -v grep|grep in.tftpd`; + if (@checkproc){ + xCAT::Utils->stopservice("tftpd-hpa"); + } } - } - if ($distro =~ /debian.*/i){ - sleep 1; - my @checkproc=`ps axf|grep -v grep|grep in.tftpd`; - if (@checkproc){ - #system("service tftpd-hpa stop"); - xCAT::Utils->stopservice("tftpd-hpa"); + my @tftpprocpids=`ps axf | grep -v 'awk /in.tftpd/' | awk '/in.tftpd/ {print \$1}'`; + if (@tftpprocpids) { + my %pids_map; + my $count = 0; + map { chomp; $pids_map{$_} = 1 } @tftpprocpids; + while (keys %pids_map) { + foreach my $pid (keys %pids_map) { + if (xCAT::Utils->is_process_exists($pid)) { + $count++; + if($count >= 50) { + xCAT::MsgUtils->message("S","Error: can not stop tftp process in 5 seconds."); + return 1; + } + sleep 0.1; + } else { + delete $pids_map{$pid} + } + } + } } - } - my @tftpprocs=`ps axf|grep -v grep|grep in.tftpd`; - while (@tftpprocs) { - sleep 0.1; - } system("$startcmd"); } - - return 0; + return 0; } # enable or disable proxydhcp service