ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.298 by root, Sun Jul 8 14:50:07 2007 UTC vs.
Revision 1.299 by root, Sun Jul 8 14:56:05 2007 UTC

409Coro::Storable. May, of course, block. Note that the executed sub may 409Coro::Storable. May, of course, block. Note that the executed sub may
410never block itself or use any form of Event handling. 410never block itself or use any form of Event handling.
411 411
412=cut 412=cut
413 413
414sub _store_scalar {
415 open my $fh, ">", \my $buf
416 or die "fork_call: cannot open fh-to-buf in child : $!";
417 Storable::store_fd $_[0], $fh;
418 close $fh;
419
420 $buf
421}
422
414sub fork_call(&@) { 423sub fork_call(&@) {
415 my ($cb, @args) = @_; 424 my ($cb, @args) = @_;
416 425
417# socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC 426# socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC
418# or die "socketpair: $!"; 427# or die "socketpair: $!";
433 return wantarray ? @$res : $res->[-1]; 442 return wantarray ? @$res : $res->[-1];
434 } else { 443 } else {
435 reset_signals; 444 reset_signals;
436 local $SIG{__WARN__}; 445 local $SIG{__WARN__};
437 local $SIG{__DIE__}; 446 local $SIG{__DIE__};
447 # just in case, this hack effectively disables event
448 # in the child. cleaner and slower would be canceling all watchers,
449 # but this works for the time being.
438 local $Coro::idle; 450 local $Coro::idle;
439 $Coro::current->prio (Coro::PRIO_MAX); 451 $Coro::current->prio (Coro::PRIO_MAX);
452
440 eval { 453 eval {
441 close $fh1; 454 close $fh1;
442 455
443 my @res = eval { $cb->(@args) }; 456 my @res = eval { $cb->(@args) };
444 457
445 open my $fh, ">", \my $buf 458 syswrite $fh2, _store_scalar $@ ? \"$@" : \@res;
446 or die "fork_call: cannot open fh-to-buf in child : $!";
447 Storable::store_fd +($@ ? \"$@" : \@res), $fh;
448 close $fh;
449
450 warn "writing ", length $buf;
451 my $x;
452 (length $buf) == ($x = syswrite $fh2, $buf)
453 or warn "error writing ".(length $buf)." != $x\n";
454 close $fh2; 459 close $fh2;
455 }; 460 };
456 461
457 warn $@ if $@; 462 warn $@ if $@;
458 _exit 0; 463 _exit 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines