]> Sergey Matveev's repositories - public-inbox.git/commitdiff
daemon: expand @ARGV paths for running in '/'
authorEric Wong <e@80x24.org>
Thu, 17 Mar 2016 01:50:07 +0000 (01:50 +0000)
committerEric Wong <e@80x24.org>
Thu, 17 Mar 2016 01:57:27 +0000 (01:57 +0000)
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.

lib/PublicInbox/Daemon.pm

index c6fb62bf4d46292f4545b4f1c3de98dce4c14f53..c9594a371f17afde7c4400b44127634474b005c9 100644 (file)
@@ -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: $!";