Code

Merged changeset:13511 from gosa-lhm.
authorjanw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 9 Mar 2009 10:45:07 +0000 (10:45 +0000)
committerjanw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 9 Mar 2009 10:45:07 +0000 (10:45 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13512 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/modules/DBsqlite.pm

index 3751116584aa8f8a63a9bd4ed2bf6c6fa93f3a77..ab66fce438b6ebe7811e51f0e23b42d4e1c6828f 100644 (file)
@@ -7,7 +7,7 @@ use DBI;
 use Data::Dumper;
 use GOSA::GosaSupportDaemon;
 use Time::HiRes qw(usleep);
-use Fcntl ':flock'; # import LOCK_* constants
+use Fcntl qw/:DEFAULT :flock/; # import LOCK_* constants
 
 my $col_names = {};
 
@@ -40,17 +40,20 @@ sub new {
 
 sub lock {
        my $self = shift;
-       open($self->{db_lock_handle}, ">>".($self->{db_lock})) unless ref $self->{db_lock_handle};
-       flock($self->{db_lock_handle},LOCK_EX);
+       if(not ref $self->{db_lock_handle}) {
+               sysopen($self->{db_lock_handle}, $self->{db_lock}, O_RDWR|O_CREAT, 0600) or &main::daemon_log("0 ERROR: Opening the lockfile for database ".$self->{db_name}." failed with $!", 1);
+       }
+       flock($self->{db_lock_handle}, LOCK_EX);
        seek($self->{db_lock_handle}, 0, 2);
-       chown($main::root_uid, $main::adm_gid, $self->{db_lock_handle});
-       chmod(0640, $self->{db_lock_handle});
 }
 
 
 sub unlock {
        my $self = shift;
-       flock($self->{db_lock_handle},LOCK_UN);
+       if(not ref $self->{db_lock_handle}) {
+               &main::daemon_log("0 BIG ERROR: Lockfile for databse ".$self->{db_name}."got closed within critical section!", 1);
+       }
+       flock($self->{db_lock_handle}, LOCK_UN);
 }