about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-03-17 01:50:07 +0000
committerEric Wong <e@80x24.org>2016-03-17 01:57:27 +0000
commit8c56a2317a3daca70d0e35c0e38b4b15be4823a8 (patch)
treeb69e27f685c57bb2e0c93b87b49eb5a7b92b5767 /lib
parent3a8265c85b219e92f71d50faa8dda79c7dbbcecc (diff)
downloadpublic-inbox-8c56a2317a3daca70d0e35c0e38b4b15be4823a8.tar.gz
We also require --stdout/--stderr/--pid-file to be absolute
paths for USR2 usage.  However, allow PSGI files for -httpd
to be relative paths for ease-of-use.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Daemon.pm18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index c6fb62bf..c9594a37 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -8,6 +8,7 @@ use warnings;
 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
 use IO::Handle;
 use IO::Socket;
+use Cwd qw/abs_path/;
 STDOUT->autoflush(1);
 STDERR->autoflush(1);
 require Danga::Socket;
@@ -91,7 +92,24 @@ sub daemon_prepare ($) {
         die "No listeners bound\n" unless @listeners;
 }
 
+sub check_absolute ($$) {
+        my ($var, $val) = @_;
+        if (defined $val && index($val, '/') != 0) {
+                die
+"--$var must be an absolute path when using --daemonize: $val\n";
+        }
+}
+
 sub daemonize () {
+        foreach my $i (0..$#ARGV) {
+                my $arg = $ARGV[$i];
+                next unless -e $arg;
+                $ARGV[$i] = abs_path($arg);
+        }
+        check_absolute('stdout', $stdout);
+        check_absolute('stderr', $stderr);
+        check_absolute('pid-file', $pid_file);
+
         chdir '/' or die "chdir failed: $!";
         open(STDIN, '+<', '/dev/null') or die "redirect stdin failed: $!";