new env vars: OBJECT_REMOTE_PERL_PATH and OBJECT_REMOTE_LOG_FORMAT
[scpubgit/Object-Remote.git] / lib / Object / Remote / Role / Connector / PerlInterpreter.pm
index a7b4316..670ad73 100644 (file)
@@ -4,7 +4,7 @@ use IPC::Open2;
 use IPC::Open3; 
 use IO::Handle;
 use Symbol; 
-use Object::Remote::Logging qw( :log :dlog get_router );
+use Object::Remote::Logging qw( :log :dlog router );
 use Object::Remote::ModuleSender;
 use Object::Remote::Handle;
 use Object::Remote::Future;
@@ -31,24 +31,31 @@ sub _build_module_sender {
 }
 
 sub _build_perl_command {
-    my ($self) = @_; 
+    my ($self) = @_;
     my $nice = $self->nice;
     my $ulimit = $self->ulimit;
-    my $shell_code = '';  
-    
+    my $perl_path = 'perl';
+    my $shell_code = '';
+
     if (defined($ulimit)) {
-        $shell_code .= "ulimit -v $ulimit; ";
+        $shell_code .= "ulimit $ulimit || exit 1; ";
     }
-    
+
     if (defined($nice)) {
         $shell_code .= "nice -n $nice ";
     }
-    
-    $shell_code .= 'perl -';
-        
-    return [ 'sh', '-c', $shell_code ];        
+
+    if (defined($ENV{OBJECT_REMOTE_PERL_PATH})) {
+        log_debug { "Using OBJECT_REMOTE_PERL_PATH environment variable as perl path" };
+        $perl_path = $ENV{OBJECT_REMOTE_PERL_PATH};
+    }
+
+    $shell_code .= $perl_path . ' -';
+
+    return [ 'bash', '-c', $shell_code ];
 }
 
+
 around connect => sub {
   my ($orig, $self) = (shift, shift);
   my $f = $self->$start::start($orig => @_);
@@ -57,7 +64,7 @@ around connect => sub {
       my ($conn) = $f->get;
       $self->_setup_watchdog_reset($conn); 
       my $sub = $conn->remote_sub('Object::Remote::Logging::init_logging_forwarding');
-      $sub->('Object::Remote::Logging', router => get_router, connection_id => $conn->_id);
+      $sub->('Object::Remote::Logging', router => router(), connection_id => $conn->_id);
       Object::Remote::Handle->new(
         connection => $conn,
         class => 'Object::Remote::ModuleLoader',
@@ -186,15 +193,20 @@ sub _setup_watchdog_reset {
 
 sub fatnode_text {
   my ($self) = @_;
+  my $connection_timeout = $self->timeout;
+  my $watchdog_timeout = $self->watchdog_timeout;
   my $text = '';
 
   require Object::Remote::FatNode;
   
-  if (defined($self->watchdog_timeout)) {
-    $text = "my \$WATCHDOG_TIMEOUT = '" . $self->watchdog_timeout . "';\n";   
-    $text .= "alarm(\$WATCHDOG_TIMEOUT);\n";    
+  if (defined($connection_timeout)) {
+    $text .= "alarm($connection_timeout);\n";
+  }
+  
+  if (defined($watchdog_timeout)) {
+    $text .= "my \$WATCHDOG_TIMEOUT = $watchdog_timeout;\n";   
   } else {
-    $text = "my \$WATCHDOG_TIMEOUT = undef;\n";
+    $text .= "my \$WATCHDOG_TIMEOUT = undef;\n";
   }
   
   $text .= <<'END';