]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix finding files when the init script is not in the cwd.
authorPeter Powell <petpow@saberuk.com>
Wed, 3 Jul 2019 08:27:09 +0000 (09:27 +0100)
committerPeter Powell <petpow@saberuk.com>
Wed, 3 Jul 2019 09:02:13 +0000 (10:02 +0100)
This should fix #1621.

make/template/inspircd

index 91b2694121f2ed05eb0079c56a3b1b129810decd..d0978ee295dd71a24487c35065a0858b929d1664 100644 (file)
@@ -50,7 +50,7 @@ use constant {
 
 my $scriptpath = "@SCRIPT_DIR@";
 my $basepath   =       "@BASE_DIR@";
-my $confpath   =       "@CONFIG_DIR@/";
+my $confpath   =       "@CONFIG_DIR@";
 my $binpath    =       "@BINARY_DIR@";
 my $runpath    =       "@BASE_DIR@";
 my $datadir    =       "@DATA_DIR@";
@@ -59,6 +59,15 @@ my $executable       =       "inspircd";
 my $version    =       "@VERSION_FULL@";
 my $uid = "@UID@";
 
+sub expand_fragment($$) {
+       my ($base, $fragment) = @_;
+       if ($fragment =~ /^\//) {
+               return $fragment;
+       } else {
+               return "$base/$fragment";
+       }
+}
+
 if (!(grep { $_ eq '--runasroot' } @ARGV) && ($< == 0 || $> == 0)) {
        if ($uid !~ /^\d+$/) {
                # Named UID, look it up
@@ -88,7 +97,7 @@ for my $a (@ARGV)
        }
 }
 if (!defined $conf) {
-       $conf = $confpath . "inspircd.conf";
+       $conf = expand_fragment $confpath, "inspircd.conf";
        push @ARGV, '--config='.$conf;
 }
 
@@ -351,11 +360,9 @@ sub getpidfile
        if ($pid ne "") {
                return;
        }
-       # Are We using a relative path?
-       if ($file !~ /^\//) {
-               # Convert it to a full path.
-               $file = $runpath .'/'. $file;
-       }
+
+       # Expand any relative paths.
+       $file = expand_fragment $confpath, $file;
 
        # Have we checked this file before?
        return if $filesparsed{$file};
@@ -377,16 +384,7 @@ sub getpidfile
                if (($i =~ /<pid file=\"(\S+)\">/i) && ($i !~ /^#/))
                {
                        # Set the PID file and return.
-                       $pidfile = $1;
-                       if (-f $pidfile)
-                       {
-                               return;
-                       }
-                       elsif (-f "$runpath/$pidfile")
-                       {
-                               $pidfile = "$runpath/$pidfile";
-                               return;
-                       }
+                       $pidfile = expand_fragment $datadir, $1;
                        return;
                }
        }