[libinline-java-perl] 153/398: Added localized signal handling Added test fork_launch stuff

Jonas Smedegaard dr at jones.dk
Thu Feb 26 11:42:59 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.55
in repository libinline-java-perl.

commit 59de3a5e0fab8c44bb9c3eecb9ef0562b8810b51
Author: patrick_leb <>
Date:   Sat Jan 26 03:07:55 2002 +0000

    Added localized signal handling
    Added test fork_launch stuff
---
 Java/JVM.pm | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 55 insertions(+), 6 deletions(-)

diff --git a/Java/JVM.pm b/Java/JVM.pm
index 8f0cd8b..8304162 100644
--- a/Java/JVM.pm
+++ b/Java/JVM.pm
@@ -9,6 +9,8 @@ use Carp ;
 use IPC::Open3 ;
 use IO::File ;
 
+my %SIGS = () ;
+
 sub new {
 	my $class = shift ;
 	my $o = shift ;
@@ -16,15 +18,20 @@ sub new {
 	my $this = {} ;
 	bless($this, $class) ;
 
+	foreach my $sig ('HUP', 'INT', 'PIPE', 'TERM'){
+		local $SIG{__WARN__} = sub {} ;
+		$SIGS{$sig} = $SIGS{$sig} ;
+	}
+
 	$this->{socket} = undef ;
 	$this->{JNI} = undef ;
-	$this->{owner} = 1 ;
 
 	$this->{destroyed} = 0 ;
 
 	Inline::Java::debug("Starting JVM...") ;
 
 	if ($o->get_java_config('JNI')){
+		$this->{owner} = 1 ;
 		Inline::Java::debug("  JNI mode") ;
 
 		my $jni = new Inline::Java::JNI(
@@ -37,7 +44,7 @@ sub new {
 	}
 	else{
 		Inline::Java::debug("  Client/Server mode") ;
-		
+
 		my $debug = (Inline::Java::get_DEBUG() ? "true" : "false") ;
 
 		my $shared_jvm = ($o->get_java_config('SHARED_JVM') ? "true" : "false") ;	
@@ -56,6 +63,7 @@ sub new {
 				return $this ;
 			}
 		}
+		$this->capture(1) ;
 
 		my $java = File::Spec->catfile($o->get_java_config('BIN'), 
 			"java" . Inline::Java::portable("EXE_EXTENSION")) ;
@@ -69,10 +77,7 @@ sub new {
 
 		my $pid = 0 ;
 		eval {
-			my $in = new IO::File() ;
-			$pid = open3($in, ">&STDOUT", ">&STDERR", $cmd) ;
-			# We won't be sending anything to the child in this fashion...
-			close($in) ;
+			$pid = $this->launch($cmd) ;
 		} ;
 		croak "Can't exec JVM: $@" if $@ ;
 
@@ -89,6 +94,36 @@ sub new {
 }
 
 
+sub launch {
+	my $this = shift ;
+	my $cmd = shift ;
+
+	my $in = new IO::File() ;
+	my $pid = open3($in, ">&STDOUT", ">&STDERR", $cmd) ;
+	# We won't be sending anything to the child in this fashion...
+	close($in) ;
+
+	return $pid ;
+}
+
+
+sub fork_launch {
+	my $this = shift ;
+	my $cmd = shift ;
+
+	my $pid = fork() ;
+	if (! $pid){
+		# Child 
+		$pid = $this->launch($cmd) ;
+		Inline::Java::set_DONE() ;
+		exit() ;
+	}
+	else{
+		waitpid($pid, 0) ;
+	}
+}
+
+
 sub DESTROY {
 	my $this = shift ;
 
@@ -242,6 +277,10 @@ sub capture {
 		return ;
 	}
 
+	foreach my $sig ('HUP', 'INT', 'PIPE', 'TERM'){
+		$SIG{$sig} = \&Inline::Java::done ;
+	}
+
 	$this->{owner} = 1 ;
 }
 
@@ -260,6 +299,11 @@ sub release {
 		return ;
 	}
 
+	foreach my $sig qw(HUP INT PIPE TERM){
+		local $SIG{__WARN__} = sub {} ;
+		$SIG{$sig} = $SIGS{$sig} ;
+	}
+
 	$this->{owner} = 0 ;
 }
 
@@ -306,3 +350,8 @@ sub process_command {
 
 	return $resp ;
 }
+
+
+
+1 ;
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libinline-java-perl.git



More information about the Pkg-perl-cvs-commits mailing list