- 1;
-}) { # (Socket::MsgHdr|Inline::C), $sock, $pwd are all available:
- open my $dh, '<', '.' or die "open(.) $!";
- my $buf = join("\0", scalar(@ARGV), @ARGV);
- while (my ($k, $v) = each %ENV) { $buf .= "\0$k=$v" }
- $buf .= "\0\0";
- $send_cmd->($sock, [ 0, 1, 2, fileno($dh) ], $buf, MSG_EOR);
- $SIG{TERM} = $SIG{INT} = $SIG{QUIT} = sub {
- my ($sig) = @_; # 'TERM', not an integer :<
- $SIG{$sig} = 'DEFAULT';
- kill($sig, $$); # exit($signo + 128)
- };
- my $x_it_code = 0;
- while (1) {
- my (@fds) = $recv_cmd->($sock, $buf, 4096 * 33);
- if (scalar(@fds) == 1 && !defined($fds[0])) {
- last if $! == ECONNRESET;
- next if $! == EINTR;
- die "recvmsg: $!";
- }
- last if $buf eq '';
- if ($buf =~ /\Ax_it ([0-9]+)\z/) {
- $x_it_code = $1 + 0;
- last;
- } elsif ($buf =~ /\Aexec (.+)\z/) {
- exec_cmd(\@fds, split(/\0/, $1));
- } else {
- sigchld();
- die $buf;
- }
- }
- sigchld();
- if (my $sig = ($x_it_code & 127)) {
- kill $sig, $$;
- sleep;
+ last if $buf eq '';
+ if ($buf =~ /\Aexec (.+)\z/) {
+ $exec_cmd->(\@fds, split(/\0/, $1));
+ } elsif ($buf eq '-WINCH') {
+ kill($buf, @parent); # for MUA
+ } elsif ($buf eq 'umask') {
+ send($sock, 'u'.pack('V', umask), MSG_EOR) or die "send: $!"
+ } elsif ($buf =~ /\Ax_it ([0-9]+)\z/) {
+ $x_it_code ||= $1 + 0;
+ last;
+ } elsif ($buf =~ /\Achild_error ([0-9]+)\z/) {
+ $x_it_code ||= $1 + 0;
+ } elsif ($buf eq 'wait') {
+ $sigchld->();
+ } else {
+ $sigchld->();
+ die $buf;