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 $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;
}
}
if (!defined $conf) {
- $conf = $confpath . "inspircd.conf";
+ $conf = expand_fragment $confpath, "inspircd.conf";
push @ARGV, '--config='.$conf;
}
# 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;
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};
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;
}
}