- # (Socket::MsgHdr|Inline::C), $sock 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";
- my $n = $send_cmd->($sock, [0, 1, 2, fileno($dh)], $buf, MSG_EOR);
- if (!$n) {
- die "sendmsg: $! (check RLIMIT_NOFILE)\n" if $!{ETOOMANYREFS};
- die "sendmsg: $!\n";
- }
- 1;
-}) { # connected and request sent to lei-daemon, wait for responses or EOF
- my $x_it_code = 0;
- while (1) {
- my (@fds) = $recv_cmd->($sock, my $buf, 4096 * 33);
- if (scalar(@fds) == 1 && !defined($fds[0])) {
- next if $!{EINTR};
- last if $!{ECONNRESET};
- die "recvmsg: $!";
- }
- 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 =~ /\Ax_it ([0-9]+)\z/) {
- $x_it_code = $1 + 0;
- last;
- } elsif ($buf =~ /\Achild_error ([0-9]+)\z/) {
- $x_it_code = $1 + 0;
- } else {
- $sigchld->();
- die $buf;
- }
- }
- $sigchld->();
- if (my $sig = ($x_it_code & 127)) {
- kill $sig, $$;
- sleep(1) while 1;
+ 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;