[interchange-cvs] interchange - heins modified lib/Vend/Session.pm
interchange-cvs at icdevgroup.org
interchange-cvs at icdevgroup.org
Thu Nov 13 11:15:40 EST 2003
User: heins
Date: 2003-11-13 16:15:40 GMT
Modified: lib/Vend Session.pm
Log:
* Remove thread-safe problem with DBI sessions in PreFork mode, by
using the $::Instance variable hash to store the DB_object and
DB_sessions variables.
* Fix bug where sessions were being locked unnecessarily. This caused
a deadlock in PreFork mode, as the file handle stayed in existence.
It was not a problem (other than performance) in forking mode, as
the lock was released when the child died.
Revision Changes Path
2.14 +23 -16 interchange/lib/Vend/Session.pm
rev 2.14, prev_rev 2.13
Index: Session.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Session.pm,v
retrieving revision 2.13
retrieving revision 2.14
diff -u -r2.13 -r2.14
--- Session.pm 18 Jun 2003 17:34:44 -0000 2.13
+++ Session.pm 13 Nov 2003 16:15:40 -0000 2.14
@@ -1,6 +1,6 @@
# Vend::Session - Interchange session routines
#
-# $Id: Session.pm,v 2.13 2003/06/18 17:34:44 jon Exp $
+# $Id: Session.pm,v 2.14 2003/11/13 16:15:40 mheins Exp $
#
# Copyright (C) 2002-2003 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
@@ -27,7 +27,7 @@
require Exporter;
use vars qw($VERSION);
-$VERSION = substr(q$Revision: 2.13 $, 10);
+$VERSION = substr(q$Revision: 2.14 $, 10);
@ISA = qw(Exporter);
@@ -69,7 +69,7 @@
}
my (%Session_class);
-my ($Session_open, $File_sessions, $Lock_sessions, $DB_sessions, $DB_object);
+my ($Session_open, $File_sessions, $Lock_sessions);
# Selects based on initial config
@@ -77,7 +77,7 @@
%Session_class = (
# $File_sessions, $Lock_sessions, &$Session_open
GDBM => [ 0, 1, sub {
- $DB_object =
+ $::Instance->{DB_object} =
tie(%Vend::SessionDBM,
'GDBM_File',
$Vend::Cfg->{SessionDatabase} . ".gdbm",
@@ -85,7 +85,7 @@
$Vend::Cfg->{FileCreationMask}
);
die "Could not tie to $Vend::Cfg->{SessionDatabase}: $!\n"
- unless defined $DB_object;
+ unless defined $::Instance->{DB_object};
},
],
DB_File => [ 0, 1, sub {
@@ -101,14 +101,14 @@
],
DBI => [ 0, 0, sub {
- return 1 if $DB_sessions;
+ return 1 if $::Instance->{DB_sessions};
tie (
%Vend::SessionDBM,
'Vend::SessionDB',
$Vend::Cfg->{SessionDB}
)
or die "Could not tie to $Vend::Cfg->{SessionDB}: $!\n";
- $DB_sessions = 1;
+ $::Instance->{DB_sessions} = 1;
},
],
@@ -182,7 +182,7 @@
($File_sessions, $Lock_sessions, $Session_open) = @{$Session_class{File}};
}
#::logDebug("open_session: File_sessions=$File_sessions Sub=$Session_open");
- unless($File_sessions) {
+ if($Lock_sessions) {
open(Vend::SessionLock, "+>>$Vend::Cfg->{SessionLockFile}")
or die "Could not open lock file '$Vend::Cfg->{SessionLockFile}': $!\n";
lockfile(\*Vend::SessionLock, 1, 1)
@@ -261,7 +261,7 @@
#::logDebug("init_session $Vend::SessionName is: " . ::uneval($Vend::Session));
#::logDebug("init_session $Vend::SessionName");
$Vend::HaveSession = 1;
- return if $File_sessions || $DB_sessions;
+ return if $File_sessions || $::Instance->{DB_sessions};
write_session();
close_session();
return;
@@ -269,11 +269,16 @@
sub close_session {
#::logDebug ("try to close session id=$Vend::SessionID name=$Vend::SessionName");
- return 0 if ! defined $Vend::SessionOpen;
+ return 0 unless defined $Vend::SessionOpen;
- unless($DB_sessions) {
-#::logDebug ("close session id=$Vend::SessionID name=$Vend::SessionName");
- undef $DB_object;
+ unless($::Instance->{DB_sessions}) {
+ undef $::Instance->{DB_object};
+ undef $File_sessions;
+ untie %Vend::SessionDBM
+ or die "Could not close $Vend::Cfg->{SessionDatabase}: $!\n";
+ undef $Vend::SessionOpen;
+ }
+ else {
untie %Vend::SessionDBM
or die "Could not close $Vend::Cfg->{SessionDatabase}: $!\n";
undef $Vend::SessionOpen;
@@ -301,6 +306,7 @@
}
$Vend::Session->{username} = $Vend::username;
$Vend::Session->{admin} = $Vend::admin;
+ $Vend::Session->{groups} = $Vend::groups;
$Vend::Session->{superuser} = $Vend::superuser;
$Vend::Session->{login_table} = $Vend::login_table;
$s = ! $File_sessions ? uneval_fast($Vend::Session) : $Vend::Session;
@@ -399,6 +405,7 @@
$Vend::username = $Vend::Session->{username};
$Vend::admin = $Vend::Session->{admin};
$Vend::superuser = $Vend::Session->{superuser};
+ $Vend::groups = $Vend::Session->{groups};
$Vend::login_table = $Vend::Session->{login_table};
$Vend::Session->{arg} = $Vend::Argument;
@@ -494,9 +501,9 @@
}
sub reorg {
- return unless $DB_object;
- GDBM_File::reorganize($DB_object);
- GDBM_File::sync($DB_object);
+ return unless $::Instance->{DB_object};
+ GDBM_File::reorganize($::Instance->{DB_object});
+ GDBM_File::sync($::Instance->{DB_object});
}
sub expire_sessions {
More information about the interchange-cvs
mailing list