… | |
… | |
26 | } |
26 | } |
27 | |
27 | |
28 | use utf8; |
28 | use utf8; |
29 | use strict qw(vars subs); |
29 | use strict qw(vars subs); |
30 | |
30 | |
|
|
31 | use Socket (); |
31 | use AnyEvent (); |
32 | use AnyEvent (); |
|
|
33 | use AnyEvent::Util (); |
32 | use Pod::POM (); |
34 | use Pod::POM (); |
33 | use File::Path (); |
35 | use File::Path (); |
34 | use Storable (); # finally |
36 | use Storable (); # finally |
35 | use Fcntl (); |
37 | use Fcntl (); |
36 | use JSON::XS qw(encode_json decode_json); |
38 | use JSON::XS qw(encode_json decode_json); |
… | |
… | |
67 | s/</</g; |
69 | s/</</g; |
68 | |
70 | |
69 | $_ |
71 | $_ |
70 | } |
72 | } |
71 | |
73 | |
72 | sub socketpipe() { |
|
|
73 | socketpair my $fh1, my $fh2, &Socket::AF_UNIX, &Socket::SOCK_STREAM, &Socket::PF_UNSPEC |
|
|
74 | or die "cannot establish bidirectional pipe: $!\n"; |
|
|
75 | |
|
|
76 | ($fh1, $fh2) |
|
|
77 | } |
|
|
78 | |
|
|
79 | sub background(&;&) { |
74 | sub background(&;&) { |
80 | my ($bg, $cb) = @_; |
75 | my ($bg, $cb) = @_; |
81 | |
76 | |
82 | my ($fh_r, $fh_w) = DC::socketpipe; |
77 | my ($fh_r, $fh_w) = AnyEvent::Util::portable_socketpair |
|
|
78 | or die "unable to create background socketpair: $!"; |
83 | |
79 | |
84 | my $pid = fork; |
80 | my $pid = fork; |
85 | |
81 | |
86 | if (defined $pid && !$pid) { |
82 | if (defined $pid && !$pid) { |
87 | local $SIG{__DIE__}; |
83 | local $SIG{__DIE__}; |