]> Sergey Matveev's repositories - public-inbox.git/commitdiff
daemon: do not chdir unless daemonizing
authorEric Wong <e@80x24.org>
Tue, 2 Aug 2016 01:47:54 +0000 (01:47 +0000)
committerEric Wong <e@80x24.org>
Tue, 2 Aug 2016 07:49:22 +0000 (07:49 +0000)
As far as most process managers are concerned (e.g. systemd),
they should already start in '/'.  So avoid making our daemon
more complex to run by requiring absolute paths during
development.

lib/PublicInbox/Daemon.pm

index 9125584b3b12b334a078eb1c9aec1ff4aa5f27af..795ab8222950e57d9df5727720f304a7977ae4e3 100644 (file)
@@ -102,16 +102,18 @@ sub check_absolute ($$) {
 }
 
 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);
+       if ($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: $!";
+               chdir '/' or die "chdir failed: $!";
+       }
 
        return unless (defined $pid_file || defined $group || defined $user
                        || $daemonize);