]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - make/template/inspircd
Fix finding files when the init script is not in the cwd.
[user/henk/code/inspircd.git] / make / template / inspircd
index cb2d2902d520eca9752a7cf0da4b4f4004c9a2c4..d0978ee295dd71a24487c35065a0858b929d1664 100644 (file)
@@ -48,17 +48,27 @@ use constant {
     GENERIC_EXIT_NOT_RUNNING => 7
 };
 
+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@";
 my $valgrindlogpath    =       "$basepath/valgrindlogs";
 my $executable =       "inspircd";
-my $version    =       "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@+@VERSION_LABEL@";
+my $version    =       "@VERSION_FULL@";
 my $uid = "@UID@";
 
-if (!("--runasroot" ~~ @ARGV) && ($< == 0 || $> == 0)) {
+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
                $uid = getpwnam $uid;
@@ -87,7 +97,7 @@ for my $a (@ARGV)
        }
 }
 if (!defined $conf) {
-       $conf = $confpath . "inspircd.conf";
+       $conf = expand_fragment $confpath, "inspircd.conf";
        push @ARGV, '--config='.$conf;
 }
 
@@ -203,7 +213,7 @@ sub dev_debug(@)
        checkgdb();
 
        # If we are still alive here.. Try starting the IRCd..
-       exec 'gdb', "--command=$basepath/.gdbargs", '--args', "$binpath/$executable", qw(--nofork --debug), @_;
+       exec 'gdb', "--command=$scriptpath/.gdbargs", '--args', "$binpath/$executable", qw(--nofork --debug), @_;
        die "Failed to start GDB: $!\n";
 }
 
@@ -222,7 +232,7 @@ sub dev_screendebug(@)
        # If we are still alive here.. Try starting the IRCd..
        print "Starting InspIRCd in `screen`, type `screen -r` when the ircd crashes to view the gdb output and get a backtrace.\n";
        print "Once you're inside the screen session press ^C + d to re-detach from the session\n";
-       exec qw(screen -m -d gdb), "--command=$basepath/.gdbargs", '-args', "$binpath/$executable", qw(--nofork --debug --nolog), @_;
+       exec qw(screen -m -d gdb), "--command=$scriptpath/.gdbargs", '-args', "$binpath/$executable", qw(--nofork --debug --nolog), @_;
        die "Failed to start screen: $!\n";
 }
 
@@ -311,7 +321,7 @@ sub cmd_stop()
        # Get to here, we have something to kill.
        my $pid = getprocessid();
        print "Stopping InspIRCd (pid: $pid)...\n";
-       my $maxwait = (`ps -o command $pid` =~ /valgrind/i) ? 90 : 15;
+       my $maxwait = (`ps -o command $pid 2>/dev/null` =~ /valgrind/i) ? 90 : 15;
        kill TERM => $pid or die "Cannot terminate IRCd: $!\n";
        for (1..$maxwait) {
                sleep 1;
@@ -350,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};
@@ -376,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;
                }
        }