* [PATCH] daemon: expand @ARGV paths for running in '/'
@ 2016-03-17 1:59 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-03-17 1:59 UTC (permalink / raw)
To: meta
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 | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index c6fb62b..c9594a3 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: $!";
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-03-17 1:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-17 1:59 [PATCH] daemon: expand @ARGV paths for running in '/' Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).