Update of /cvsroot/mod-c/ehtml/src
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv23213/src
Modified Files:
DiskSessionDriver.cpp
Log Message:
* Renaming the session file is not wise at all.
Perhaps we could implement a save to tmp file, unlink original file, and
rename the new file.
Index: DiskSessionDriver.cpp
===================================================================
RCS file: /cvsroot/mod-c/ehtml/src/DiskSessionDriver.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** DiskSessionDriver.cpp 31 Oct 2006 12:23:30 -0000 1.8
--- DiskSessionDriver.cpp 3 Nov 2006 20:34:53 -0000 1.9
***************
*** 46,50 ****
time_t old_enough;
string filename(const SessionID& id);
- string locked_filename(const SessionID& id);
public:
DiskSessionDriver(): connected(false), collect_prob(1), old_enough(86400) { ; }
--- 46,49 ----
***************
*** 68,75 ****
}
- string DiskSessionDriver::locked_filename(const SessionID& id) {
- return filename(id) + ",$$";
- }
-
bool DiskSessionDriver::mayBeCollect() {
ProfileMe();
--- 67,70 ----
***************
*** 152,163 ****
mayBeCollect();
string name = filename(id);
! string lname = locked_filename(id);
! if (rename(name.c_str(), lname.c_str())) {
! Application()->Error("stale session (id=%s, rename error=%s)",
id.hex().c_str(), strerror(errno));
return NULL;
}
Session* dev = new Session(id);
! ifstream in(lname.c_str());
try {
in >> *dev;
--- 147,158 ----
mayBeCollect();
string name = filename(id);
! struct stat st;
! if (stat(name.c_str(), &st) < 0) {
! Application()->Error("Error opening session (id=%s, error=%s)",
id.hex().c_str(), strerror(errno));
return NULL;
}
Session* dev = new Session(id);
! ifstream in(name.c_str());
try {
in >> *dev;
***************
*** 177,181 ****
Application()->Error("expired session (id=%s, expires=%lu, "
"now=%lu)\n", id.hex().c_str(), dev->Expires(), time(NULL));
- unlink(lname.c_str());
delete dev;
dev = NULL;
--- 172,175 ----
***************
*** 189,194 ****
if (!connected)
return false;
! string lfile = locked_filename(s->ID());
! ofstream out(lfile.c_str());
if (!out)
return false;
--- 183,188 ----
if (!connected)
return false;
! string file = filename(s->ID());
! ofstream out(file.c_str());
if (!out)
return false;
***************
*** 202,206 ****
return false;
unlink(filename(s->ID()).c_str());
- unlink(locked_filename(s->ID()).c_str());
return true;
}
--- 196,199 ----
***************
*** 210,217 ****
if (!connected)
return false;
! string name(filename(s->ID()));
! string lname(locked_filename(s->ID()));
! int status = rename(lname.c_str(), name.c_str());
! return status ? false : true;
}
--- 203,207 ----
if (!connected)
return false;
! return true;
}
|