From f5b50de9feb64cbc2c8b8108cfc7b7749ff8b988 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sat, 17 Dec 2011 16:06:59 -0800 Subject: [PATCH] Fix squid PID detection https://sourceforge.net/tracker/?func=detail&atid=117457&aid=3459413&group_id=17457 --- squid/squid-lib.pl | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/squid/squid-lib.pl b/squid/squid-lib.pl index 1ffbb23a9..ba528bc59 100755 --- a/squid/squid-lib.pl +++ b/squid/squid-lib.pl @@ -342,19 +342,29 @@ else { sub is_squid_running { local $conf = &get_config(); -local ($pidstruct, $pidfile); -$pidstruct = &find_config("pid_filename", $conf); -if (!$pidstruct) { - $pidstruct = &find_config("pid_filename", $conf, 2); + +# Find all possible PID files +local @pidfiles; +local $pidstruct = &find_config("pid_filename", $conf); +push(@pidfiles, $pidstruct->{'values'}->[0]) if ($pidstruct); +local $def_pidstruct = &find_config("pid_filename", $conf); +push(@pidfiles, $def_pidstruct->{'values'}->[0]) if ($def_pidstruct); +push(@pidfiles, $config{'pid_file'}) if ($config{'pid_file'}); +@pidfiles = grep { $_ ne "none" } @pidfiles; + +# Try check one +foreach my $pidfile (@pidfiles) { + my $pid = &check_pid_file($pidfile); + return $pid if ($pid); } -$pidfile = $pidstruct ? $pidstruct->{'values'}->[0] : $config{'pid_file'}; -if ($pidfile eq "none" || !$pidfile) { + +if (!@pidfiles) { + # Fall back to checking for Squid process local ($pid) = &find_byname("squid"); return $pid; } -else { - return &check_pid_file($pidfile); - } + +return 0; } # this_url()