summaryrefslogtreecommitdiffstats
path: root/config-db
diff options
context:
space:
mode:
authorOliver Tappe2008-06-08 20:09:07 +0200
committerOliver Tappe2008-06-08 20:09:07 +0200
commit03ac6162f1261e54d01d2b40bdcd8fe7a048de5e (patch)
tree04ed53ed20e8061eac66f93e48ed1bf8457bdc3d /config-db
parent* adjusted config-path for kdmrc as needed (diff)
downloadcore-03ac6162f1261e54d01d2b40bdcd8fe7a048de5e.tar.gz
core-03ac6162f1261e54d01d2b40bdcd8fe7a048de5e.tar.xz
core-03ac6162f1261e54d01d2b40bdcd8fe7a048de5e.zip
* refactored locking file to make use of ScopedResource
git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1867 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'config-db')
-rwxr-xr-xconfig-db/slxconfig-demuxer90
1 files changed, 41 insertions, 49 deletions
diff --git a/config-db/slxconfig-demuxer b/config-db/slxconfig-demuxer
index a14ffc8d..c435d7d4 100755
--- a/config-db/slxconfig-demuxer
+++ b/config-db/slxconfig-demuxer
@@ -51,6 +51,7 @@ use OpenSLX::Basics;
use OpenSLX::ConfigDB qw(:support);
use OpenSLX::ConfigFolder;
use OpenSLX::MakeInitRamFS::Engine;
+use OpenSLX::ScopedResource;
use OpenSLX::Utils;
my (
@@ -112,13 +113,46 @@ if (createConfigFolderForDefaultSystem()) {
chomp(my $slxVersion = qx{slxversion});
-my $lockFile = "$openslxConfig{'private-path'}/config-demuxer.lock";
-my $haveLock = lockScript($lockFile);
-
-END
-{
- unlockScript($lockFile) if $haveLock;
-}
+# protect against parallel executions of this script
+my $criticalSection = OpenSLX::ScopedResource->new({
+ name => 'osplugin::session',
+ acquire => sub {
+ return if $option{dryRun};
+
+ # use a lock-file to singularize execution of this script:
+ my $lockFile = "$openslxConfig{'private-path'}/config-demuxer.lock";
+ if (-e $lockFile) {
+ my $ctime = (stat($lockFile))[10];
+ my $now = time();
+ if ($now - $ctime > 15 * 60) {
+ # existing lock file is older than 15 minutes, wipe it:
+ unlink $lockFile;
+ }
+ }
+ if (!sysopen(LOCKFILE, $lockFile, O_RDWR | O_CREAT | O_EXCL)) {
+ if ($! == 13) {
+ die _tr(qq[Unable to create lock-file <%s>, exiting!\n], $lockFile);
+ } else {
+ die _tr(unshiftHereDoc(<<" End-of-Here"),
+ Lock-file '%s' exists, script is already running.
+ Please remove the logfile and try again if you are sure that no one else
+ is executing this script.
+ End-of-Here
+ $lockFile
+ );
+ }
+ }
+ 1
+ },
+ release => sub {
+ return if $option{dryRun};
+
+ my $lockFile = "$openslxConfig{'private-path'}/config-demuxer.lock";
+ close(LOCKFILE);
+ unlink $lockFile;
+ 1
+ },
+});
my $tempPath = "$openslxConfig{'temp-path'}/slxconfig-demuxer";
if (!$option{dryRun}) {
@@ -197,47 +231,6 @@ exit;
################################################################################
###
################################################################################
-sub lockScript
-{
- my $lockFile = shift;
-
- return if $option{dryRun};
-
- # use a lock-file to singularize execution of this script:
- if (-e $lockFile) {
- my $ctime = (stat($lockFile))[10];
- my $now = time();
- if ($now - $ctime > 15 * 60) {
- # existing lock file is older than 15 minutes, wipe it:
- unlink $lockFile;
- }
- }
- if (!sysopen(LOCKFILE, $lockFile, O_RDWR | O_CREAT | O_EXCL)) {
- if ($! == 13) {
- die _tr(qq[Unable to create lock-file <%s>, exiting!\n], $lockFile);
- } else {
- die _tr(
- qq[Lock-file <%s> exists, script is already running.
-Please remove the logfile and try again if you are sure that no one else
-is executing this script.\n], $lockFile
- );
- }
- }
- return 1;
-}
-
-sub unlockScript
-{
- my $lockFile = shift;
-
- return if $option{dryRun};
-
- close(LOCKFILE);
- unlink $lockFile;
-
- return;
-}
-
sub folderContainsFiles
{
my $folder = shift;
@@ -898,4 +891,3 @@ Please refer to the C<slxsettings>-manpage for a more detailed description
of these options.
=cut
-