-sub getpidfile {
- my ($file) = @_;
- # Before we start, do we have a PID already? (Should never occur)
- if ($pid ne "") {
- return;
- }
- # Are We using a relative path?
- if ($file !~ /^\//) {
- # Convert it to a full path..
- $file = $confpath . $file;
- }
-
- # Have we checked this file before?
- for (my $i = 0; $i < $filesparsed; $i++) {
- if ($filesparsed[$i] eq $file) {
- # Already Parsed, Possible recursive loop..
- return;
- }
- }
-
- # If we get here, Mark as 'Read'
- $filesparsed[$filesparsed] = $file;
-
- # Open the File..
- open INFILE, "< $file" or die "Unable to open file $file\n";
- # Grab entire file contents..
- my(@lines) = <INFILE>;
- # Close the file
- close INFILE;
-
- # remove trailing spaces
- chomp(@lines);
- foreach $i (@lines) {
- # clean it up
- $i =~ s/[^=]+=\s(.*)/\1/;
- # Does this file have a pid?
- if (($i =~ /<pid file=\"(\S+)\">/i) && ($i !~ /^#/))
- {
- # Set the PID file and return.
- $pidfile = $1;
- return;
- }
- }
-
- # If we get here, NO PID FILE! -- Check for includes
- foreach $i (@lines) {
- $i =~ s/[^=]+=\s(.*)/\1/;
- if (($i =~ s/\<include file=\"(.+?)\"\>//i) && ($i !~ /^#/))
- {
- # Decend into that file, and check for PIDs.. (that sounds like an STD ;/)
- getpidfile($1);
- # Was a PID found?
- if ($pidfile ne "") {
- # Yes, Return.
- return;
- }
- }
- }
-
- # End of includes / No includes found. Using default.
- $pidfile = $confpath . "inspircd.pid";
+my %filesparsed;
+
+sub getpidfile
+{
+ my ($file) = @_;
+ # Before we start, do we have a PID already? (Should never occur)
+ if ($pid ne "") {
+ return;
+ }
+ # Are We using a relative path?
+ if ($file !~ /^\//) {
+ # Convert it to a full path.
+ $file = $confpath . $file;
+ }
+
+ # Have we checked this file before?
+ return if $filesparsed{$file};
+ $filesparsed{$file} = 1;
+
+ # Open the File..
+ open INFILE, "< $file" or die "Unable to open file $file included in configuration\n";
+ # Grab entire file contents..
+ my(@lines) = <INFILE>;
+ # Close the file
+ close INFILE;
+
+ # remove trailing spaces
+ chomp(@lines);
+ for my $i (@lines) {
+ # clean it up
+ $i =~ s/[^=]+=\s(.*)/\1/;
+ # Does this file have a pid?
+ if (($i =~ /<pid file=\"(\S+)\">/i) && ($i !~ /^#/))
+ {
+ # Set the PID file and return.
+ $pidfile = $1;
+ if (-f $pidfile)
+ {
+ return;
+ }
+ else
+ {
+ if (-f $confpath . $pidfile)
+ {
+ $pidfile = $confpath . $pidfile;
+ return;
+ }
+ }
+ return;
+ }
+ }
+
+
+ # If we get here, NO PID FILE! -- Check for includes
+ for my $i (@lines) {
+ $i =~ s/[^=]+=\s(.*)/\1/;
+ if (($i =~ s/\<include file=\"(.+?)\"\>//i) && ($i !~ /^#/))
+ {
+ # Decend into that file, and check for PIDs.. (that sounds like an STD ;/)
+ getpidfile($1);
+ # Was a PID found?
+ if (-f $pidfile)
+ {
+ return;
+ }
+ else
+ {
+ if (-f $confpath . $pidfile)
+ {
+ $pidfile = $confpath . $pidfile;
+ return;
+ }
+ }
+ if ($pidfile ne "") {
+ # Yes, Return.
+ return;
+ }
+ }
+ }
+
+ # End of includes / No includes found. Using default.
+ $pidfile = $confpath . "inspircd.pid";