diff options
author | Oliver Tappe | 2008-03-24 11:41:16 +0100 |
---|---|---|
committer | Oliver Tappe | 2008-03-24 11:41:16 +0100 |
commit | 4f6b63abf59c2478968506e0e779d0992323534f (patch) | |
tree | 94630439ab7d0d8d21ee05a6de5351bfec2f0ca8 /os-plugins | |
parent | * moved syscall related code into a module of its own right (diff) | |
download | core-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 'os-plugins')
-rw-r--r-- | os-plugins/OpenSLX/OSPlugin/Engine.pm | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/os-plugins/OpenSLX/OSPlugin/Engine.pm b/os-plugins/OpenSLX/OSPlugin/Engine.pm index 61b835a4..3d967166 100644 --- a/os-plugins/OpenSLX/OSPlugin/Engine.pm +++ b/os-plugins/OpenSLX/OSPlugin/Engine.pm @@ -1,4 +1,4 @@ -# Copyright (c) 2007 - OpenSLX GmbH +# Copyright (c) 2007, 2008 - OpenSLX GmbH # # This program is free software distributed under the GPL version 2. # See http://openslx.org/COPYING @@ -24,6 +24,7 @@ use Storable; use OpenSLX::Basics; use OpenSLX::OSSetup::Engine; +use OpenSLX::ScopedResource; use OpenSLX::Utils; =head1 NAME @@ -516,28 +517,30 @@ sub _callChrootedFunctionForPlugin # bind-mount openslx basepath to /mnt/openslx of vendor-OS: my $basePath = $openslxConfig{'base-path'}; my $openslxPathInChroot = "$self->{'vendor-os-path'}/mnt/openslx"; - mkpath( [ $openslxPathInChroot ] ); - if (slxsystem("mount -o bind $basePath $openslxPathInChroot")) { - croak( - _tr( - "unable to bind mount '%s' to '%s'! (%s)", - $basePath, $openslxPathInChroot, $! - ) - ); - } + mkpath($openslxPathInChroot); + + my $pluginSession = OpenSLX::ScopedResource->new({ + name => 'osplugin::session', + acquire => sub { + # bind mount openslx base path into vendor-OS + slxsystem("mount -o bind -o ro $basePath $openslxPathInChroot") == 0 + or die _tr( + "unable to bind mount '%s' to '%s'! (%s)", + $basePath, $openslxPathInChroot, $! + ); + 1 + }, + release => sub { + slxsystem("umount $openslxPathInChroot") == 0 + or die _tr( + "unable to umount '%s'! (%s)", $openslxPathInChroot, $! + ); + 1 + }, + }); # now let plugin install itself into vendor-OS - my $ok = eval { - $self->{'ossetup-engine'}->callChrootedFunctionForVendorOS($function); - }; - - if (slxsystem("umount $openslxPathInChroot")) { - croak(_tr("unable to umount '%s'! (%s)", $openslxPathInChroot, $!)); - } - - if (!$ok) { - die $@; - } + $self->{'ossetup-engine'}->callChrootedFunctionForVendorOS($function); return; } |