mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-09-09 05:00:44 +00:00
fix(detect_dhcpd): find tcpdump through PATH
Both copies refused to run unless /usr/sbin/tcpdump existed. Debian and Ubuntu install it as /usr/bin/tcpdump, so the rogue DHCP detector never ran there and the probe reported its tcpdump check as failed. Resolve tcpdump through PATH and the standard system directories with CommandUtils::find_executable, run the resolved path, and match that path when the capture process is killed at the end.
This commit is contained in:
@@ -5,6 +5,7 @@ BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/o
|
||||
|
||||
use lib "$::XCATROOT/probe/lib/perl";
|
||||
use probe_utils;
|
||||
use xCAT::CommandUtils;
|
||||
use File::Basename;
|
||||
use IO::Socket::INET;
|
||||
use Time::HiRes qw(gettimeofday sleep);
|
||||
@@ -63,7 +64,8 @@ if ($::TEST) {
|
||||
exit 0;
|
||||
}
|
||||
|
||||
unless (-x "/usr/sbin/tcpdump") {
|
||||
my $tcpdump = xCAT::CommandUtils::find_executable('tcpdump');
|
||||
unless ($tcpdump) {
|
||||
probe_utils->send_msg("$output", "f", "Tool 'tcpdump' is installed on current server");
|
||||
probe_utils->send_msg("$output", "d", "$program_name needs to leverage 'tcpdump', please install 'tcpdump' first");
|
||||
exit 1;
|
||||
@@ -158,7 +160,7 @@ if (!defined $pid) {
|
||||
} elsif ($pid == 0) {
|
||||
|
||||
# Child process
|
||||
my $cmd = "tcpdump -i $nic port 68 -n -vvvvvv > $dumpfile 2>/dev/null";
|
||||
my $cmd = "$tcpdump -i $nic port 68 -n -vvvvvv > $dumpfile 2>/dev/null";
|
||||
`$cmd`;
|
||||
exit 0;
|
||||
}
|
||||
@@ -379,7 +381,7 @@ sub packdhcppkg {
|
||||
|
||||
sub kill_child {
|
||||
kill 15, $pid;
|
||||
my @pidoftcpdump = `ps -ef | grep -E "[0-9]+:[0-9]+:[0-9]+ tcpdump -i $nic" | awk -F' ' '{print \$2}'`;
|
||||
my @pidoftcpdump = `ps -ef | grep -E "[0-9]+:[0-9]+:[0-9]+ $tcpdump -i $nic" | awk -F' ' '{print \$2}'`;
|
||||
foreach my $cpid (@pidoftcpdump) {
|
||||
kill 15, $cpid;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
#!/usr/bin/perl
|
||||
BEGIN {
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
use xCAT::CommandUtils;
|
||||
use IO::Socket::INET;
|
||||
use Time::HiRes qw(gettimeofday sleep);
|
||||
use Getopt::Long;
|
||||
@@ -27,7 +32,8 @@ if (!GetOptions(
|
||||
|
||||
if ($::HELP) { print $::USAGE; exit 0; }
|
||||
|
||||
unless (-x "/usr/sbin/tcpdump") {
|
||||
my $tcpdump = xCAT::CommandUtils::find_executable('tcpdump');
|
||||
unless ($tcpdump) {
|
||||
print "Error: Please install tcpdump before the detecting.\n";
|
||||
exit 1;
|
||||
}
|
||||
@@ -92,7 +98,7 @@ my $dumpfile = "/tmp/dhcpdumpfile.log";
|
||||
if ($pid == 0) {
|
||||
|
||||
# Child process
|
||||
my $cmd = "tcpdump -i $IF port 68 -n -vvvvvv > $dumpfile 2>/dev/null";
|
||||
my $cmd = "$tcpdump -i $IF port 68 -n -vvvvvv > $dumpfile 2>/dev/null";
|
||||
`$cmd`;
|
||||
exit 0;
|
||||
}
|
||||
@@ -146,7 +152,7 @@ kill_child();
|
||||
|
||||
#kill the child process
|
||||
kill 15, $pid;
|
||||
my @pidoftcpdump = `ps -ef | grep -E "[0-9]+:[0-9]+:[0-9]+ tcpdump -i $IF" | awk -F' ' '{print \$2}'`;
|
||||
my @pidoftcpdump = `ps -ef | grep -E "[0-9]+:[0-9]+:[0-9]+ $tcpdump -i $IF" | awk -F' ' '{print \$2}'`;
|
||||
foreach my $cpid (@pidoftcpdump) {
|
||||
kill 15, $cpid;
|
||||
|
||||
@@ -341,7 +347,7 @@ sub packdhcppkg {
|
||||
|
||||
sub kill_child {
|
||||
kill 15, $pid;
|
||||
my @pidoftcpdump = `ps -ef | grep -E "[0-9]+:[0-9]+:[0-9]+ tcpdump -i $IF" | awk -F' ' '{print \$2}'`;
|
||||
my @pidoftcpdump = `ps -ef | grep -E "[0-9]+:[0-9]+:[0-9]+ $tcpdump -i $IF" | awk -F' ' '{print \$2}'`;
|
||||
foreach my $cpid (@pidoftcpdump) {
|
||||
kill 15, $cpid;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user