our @call_fds;
our $socket_path;
-sub fail ($) {
+sub fail_log ($) {
my ($m) = @_;
- print STDERR "$0: prefork [$$]: $m\n";
- flush STDERR;
+ syslog(LOG_ERROR, "$0: prefork [$$]: error: $m");
_exit 127;
}
my $child = fork // fail("fork executor: $!");
if (!$child) {
#---- executor ----
- open ::STDIN , "<& $call_fds[0]" or fail("dup for fd0");
- open ::STDOUT, ">& $call_fds[1]" or fail("dup for fd1");
- open ::STDERR, ">& $call_fds[2]" or fail("dup for fd2");
+ open ::STDIN , "<& $call_fds[0]" or fail_log("dup for fd0");
+ open ::STDOUT, ">& $call_fds[1]" or fail_log("dup for fd1");
+ open ::STDERR, ">& $call_fds[2]" or fail_log("dup for fd2");
POSIX::close($_) foreach @call_fds;
close CALL;
return;
}
#---- monitor [2] ----
- my $got = waitpid $child, 0 // fail("wait for executor: $!");
- $got == $child or fail("wait for esecutor gave $got, expected $child");
+ my $got = waitpid $child, 0 // fail_log("wait for executor: $!");
+ $got == $child or fail_log("wait for esecutor gave $got, expected $child");
protocol_write(pack "L", $?);
_exit(0);
my ($d) = @_;
return if (print CALL $d and flush CALL);
_exit(0) if $!==EPIPE || $!==ECONNRESET;
- fail("protocol write: $!");
+ fail_log("protocol write: $!");
}
sub eintr_retry ($) {
sub protocol_read_fail ($) {
my ($what) = @_;
_exit(0) if $!==ECONNRESET;
- fail("recv $what: $!");
+ fail_log("recv $what: $!");
}
sub protocol_exchange () {
$r == $len or _exit(0);
@ARGV = split /\0/, $data;
- @ARGV >= 2 or fail("message data has too few strings");
- length(pop(@ARGV)) and fail("message data missing trailing nul");
+ @ARGV >= 2 or fail_log("message data has too few strings");
+ length(pop(@ARGV)) and fail_log("message data missing trailing nul");
%ENV = ();
while (my $s = shift @ARGV) {
last if !length $s;
- $s =~ m/=/ or fail("message data env var missing equals");
+ $s =~ m/=/ or fail_log("message data env var missing equals");
$ENV{$`} = $';
}
}
# --- server(pm) [2] ----
- setsid() > 0 or fail("setsid: $!");
- open STDIN, "<&NULL" or fail("dup null onto stdin: $!");
- open STDOUT, ">&NULL" or fail("dup null onto stdout: $!");
- open STDERR, ">&NULL" or fail("dup null onto stderr: $!");
+ setsid() > 0 or fail_log("setsid: $!");
+ open STDIN, "<&NULL" or fail_log("dup null onto stdin: $!");
+ open STDOUT, ">&NULL" or fail_log("dup null onto stdout: $!");
+ open STDERR, ">&NULL" or fail_log("dup null onto stderr: $!");
close NULL;
POSIX::close($_) foreach @call_fds;
close CALL;
- my $flags = fcntl(LISTEN, F_GETFL, 0) or fail("F_GETFL listen socket: $!");
+ my $flags = fcntl(LISTEN, F_GETFL, 0)
+ or fail_log("F_GETFL listen socket: $!");
$flags |= O_NONBLOCK;
- fcntl(LISTEN, F_SETFL, $flags) or fail("F_SETFL listen socket: $!");
+ fcntl(LISTEN, F_SETFL, $flags)
+ or fail_log("F_SETFL listen socket: $!");
my $errcount = 0;
if ($nfound) {
if (accept(CALL, LISTEN)) {
- $child = fork // fail("fork for accepted call failed: $!");
+ $child = fork // fail_log("fork for accepted call failed: $!");
if (!$child) {
#---- monitor [1] ----
close LISTEN;
}
# are we still live?
- my @st_listen = stat(LISTEN) // fail("fstat listening socket: $!");
+ my @st_listen = stat(LISTEN) // fail_log("fstat listening socket: $!");
my @st_socket = stat($socket_path) // do {
if ($! == ENOENT) { server_quit("socket $socket is ENOENT"); }
- fail("stat socket $socket: $!");
+ fail_log("stat socket $socket: $!");
};
if ("@st_listen[0..2]" ne "@st_socket[0..2]") {
server_quit("socket $socket is no longer ours");