summaryrefslogtreecommitdiffstats
path: root/lib/OpenSLX/Basics.pm
diff options
context:
space:
mode:
authorOliver Tappe2008-03-24 11:41:16 +0100
committerOliver Tappe2008-03-24 11:41:16 +0100
commit4f6b63abf59c2478968506e0e779d0992323534f (patch)
tree94630439ab7d0d8d21ee05a6de5351bfec2f0ca8 /lib/OpenSLX/Basics.pm
parent* moved syscall related code into a module of its own right (diff)
downloadcore-4f6b63abf59c2478968506e0e779d0992323534f.tar.gz
core-4f6b63abf59c2478968506e0e779d0992323534f.tar.xz
core-4f6b63abf59c2478968506e0e779d0992323534f.zip
* Switched from explicit cleanup functions to "resource acquisition by definition",
implemented by the new ScopedResource class. This change improves robustness with respect to signals and unexpected errors and makes the code cleaner. git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1678 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'lib/OpenSLX/Basics.pm')
-rw-r--r--lib/OpenSLX/Basics.pm68
1 files changed, 9 insertions, 59 deletions
diff --git a/lib/OpenSLX/Basics.pm b/lib/OpenSLX/Basics.pm
index 230bf72b..9af056e6 100644
--- a/lib/OpenSLX/Basics.pm
+++ b/lib/OpenSLX/Basics.pm
@@ -30,12 +30,10 @@ $VERSION = 1.01;
&vlog
&checkParams
&instantiateClass
- &addCleanupFunction &removeCleanupFunction
);
our (%openslxConfig, %cmdlineConfig, %openslxPath);
-use sigtrap qw( die normal-signals error-signals );
use subs qw(die warn);
use open ':utf8';
@@ -139,8 +137,6 @@ my %openslxCmdlineArgs = (
'verbose-level=i' => \$cmdlineConfig{'verbose-level'},
);
-my %cleanupFunctions;
-
# filehandle used for logging:
my $openslxLog = *STDERR;
@@ -313,27 +309,20 @@ sub callInSubprocess
my $pid = fork();
if (!$pid) {
-
- # child...
- # ...execute the given function and exit:
- my $ok = eval { $childFunc->(); 1 };
- if (!$ok) {
- print STDERR "*** $@";
- exit 5;
- }
+ # child -> execute the given function and exit:
+ eval { $childFunc->(); 1 }
+ or die $@;
exit 0;
}
- # parent...
- # ...pass on interrupt- and terminate-signals to child...
- local $SIG{INT} = sub { kill 'INT', $pid; waitpid($pid, 0); exit $? };
- local $SIG{TERM} = sub { kill 'TERM', $pid; waitpid($pid, 0); exit $? };
+ # parent -> pass on interrupt- and terminate-signals to child ...
+ $SIG{INT} = sub { kill 'INT', $pid; };
+ $SIG{TERM} = sub { kill 'TERM', $pid; };
- # ...and wait for child to do its work:
+ # ... and wait until child has done its work
waitpid($pid, 0);
- if ($?) {
- exit $?;
- }
+ exit $? if $?;
+
return;
}
@@ -355,36 +344,6 @@ sub executeInSubprocess
}
# ------------------------------------------------------------------------------
-sub addCleanupFunction
-{
- my $name = shift;
- my $func = shift;
-
- $cleanupFunctions{$name} = $func;
- return;
-}
-
-# ------------------------------------------------------------------------------
-sub removeCleanupFunction
-{
- my $name = shift;
-
- delete $cleanupFunctions{$name};
- return;
-}
-
-# ------------------------------------------------------------------------------
-sub invokeCleanupFunctions
-{
- my @funcNames = keys %cleanupFunctions;
- foreach my $name (@funcNames) {
- vlog(2, "invoking cleanup function '$name'...");
- $cleanupFunctions{$name}->();
- }
- return;
-}
-
-# ------------------------------------------------------------------------------
sub slxsystem
{
vlog(2, _tr("executing: %s", join ' ', @_));
@@ -426,7 +385,6 @@ sub warn
# ------------------------------------------------------------------------------
sub confess
{
- invokeCleanupFunctions();
_doThrowOrWarn('confess', @_);
return;
}
@@ -434,7 +392,6 @@ sub confess
# ------------------------------------------------------------------------------
sub croak
{
- invokeCleanupFunctions();
_doThrowOrWarn('croak', @_);
return;
}
@@ -442,7 +399,6 @@ sub croak
# ------------------------------------------------------------------------------
sub die
{
- invokeCleanupFunctions();
_doThrowOrWarn('die', @_);
return;
}
@@ -636,10 +592,4 @@ sub instantiateClass
return $class->new;
}
-# ------------------------------------------------------------------------------
-END
-{
- invokeCleanupFunctions() if %cleanupFunctions;
-}
-
1;