diff options
author | Oliver Tappe | 2007-05-11 22:41:59 +0200 |
---|---|---|
committer | Oliver Tappe | 2007-05-11 22:41:59 +0200 |
commit | 31f532de7fb86e1191003da85d07f7a3be172f80 (patch) | |
tree | 3eb6a5f6a9cdd55110dbe4856098a8b4d0fe918f /lib | |
parent | * changed the way the DB-modules are tested: now we check for the OpenSLX::Me... (diff) | |
download | core-31f532de7fb86e1191003da85d07f7a3be172f80.tar.gz core-31f532de7fb86e1191003da85d07f7a3be172f80.tar.xz core-31f532de7fb86e1191003da85d07f7a3be172f80.zip |
* implemented a simple registration mechanism for cleanup functions in order to
improve the reliability of cleaning up in case of user interrupts
git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1048 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'lib')
-rw-r--r-- | lib/OpenSLX/Basics.pm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/OpenSLX/Basics.pm b/lib/OpenSLX/Basics.pm index 998e7982..e723c431 100644 --- a/lib/OpenSLX/Basics.pm +++ b/lib/OpenSLX/Basics.pm @@ -26,6 +26,7 @@ $VERSION = 1.01; &warn &die &executeInSubprocess &slxsystem &vlog &instantiateClass + &addCleanupFunction &removeCleanupFunction ); use vars qw(%openslxConfig %cmdlineConfig); @@ -135,6 +136,8 @@ my %openslxCmdlineArgs = ( # level of logging verbosity (0-3) ); +my %cleanupFunctions; + # filehandle used for logging: my $openslxLog = *STDERR; @@ -321,6 +324,33 @@ sub executeInSubprocess } # ------------------------------------------------------------------------------ +sub addCleanupFunction +{ + my $name = shift; + my $func = shift; + + $cleanupFunctions{$name} = $func; +} + +# ------------------------------------------------------------------------------ +sub removeCleanupFunction +{ + my $name = shift; + + delete $cleanupFunctions{$name}; +} + +# ------------------------------------------------------------------------------ +sub invokeCleanupFunctions +{ + my @funcNames = keys %cleanupFunctions; + foreach my $name (@funcNames) { + vlog 2, "invoking cleanup function '$name'..."; + $cleanupFunctions{$name}->(); + } +} + +# ------------------------------------------------------------------------------ sub slxsystem { vlog 2, _tr("executing: %s", join ' ', @_); @@ -350,6 +380,8 @@ sub warn # ------------------------------------------------------------------------------ sub die { + invokeCleanupFunctions(); + my $msg = shift; $msg =~ s[^\*\*\* ][]igms; $msg =~ s[^][*** ]igms; |