From b1d4dffa9961cd6af7defc85a8e5d70265776578 Mon Sep 17 00:00:00 2001 From: janw Date: Tue, 12 Feb 2008 12:55:57 +0000 Subject: [PATCH] Corrected file lock creation and removal. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8858 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 2 +- gosa-si/modules/DBsqlite.pm | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index d0e45264b..584d34987 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -1092,7 +1092,7 @@ daemon_log(" ", 1); daemon_log("$0 started!", 1); # delete old DBsqlite lock files -unlink('/tmp/gosa_si_lock*'); +#unlink('/tmp/gosa_si_lock*'); # connect to gosa-si job queue my @job_col_names = ("id INTEGER", "timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress"); diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index d5775bd26..029abcbf4 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -17,10 +17,11 @@ sub new { my $class = shift; my $db_name = shift; - my $lock='/tmp/gosa_si_lock'; - my $_lock = $db_name; - $_lock =~ tr/\//_/; - $lock.=$_lock; + my $lock = $db_name.".gosa_lock"; + # delete existing lock - instance should be running only once + if(stat($lock)) { + unlink($lock); + } my $self = {dbh=>undef,db_name=>undef,db_lock=>undef,db_lock_handle=>undef}; my $dbh = DBI->connect("dbi:SQLite:dbname=$db_name"); $self->{dbh} = $dbh; @@ -37,7 +38,7 @@ sub lock_exists : locked { my $lock = $self->{db_lock}; my $result=(-f $lock); if($result) { - #&main::daemon_log("(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock gefunden", 8); + &main::daemon_log("(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock found", 8); usleep 100; } return $result; @@ -46,11 +47,11 @@ sub lock_exists : locked { sub create_lock : locked { my $self=shift; my $funcname=shift; -# &main::daemon_log("(".((defined $funcname)?$funcname:"").") Erzeuge Lock (PID ".$$.") ".($self->{db_lock}),8); + &main::daemon_log("(".((defined $funcname)?$funcname:"").") Creating Lock (PID ".$$.") ".($self->{db_lock}),8); my $lock = $self->{db_lock}; while( -f $lock ) { - #print STDERR "(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock gefunden\n"; + &main::daemon_log("(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock found",8); sleep 1; } @@ -60,7 +61,7 @@ sub create_lock : locked { sub remove_lock : locked { my $self=shift; my $funcname=shift; -# &main::daemon_log("(".((defined $funcname)?$funcname:"").") Entferne Lock (PID ".$$.") ".$self->{db_lock}, 8); + &main::daemon_log("(".((defined $funcname)?$funcname:"").") Removing Lock (PID ".$$.") ".$self->{db_lock}, 8); close($self->{db_lock_handle}); unlink($self->{db_lock}); } -- 2.30.2