[Speedycgi-users] Logical error in file_lock() [v. 2.21]
Brought to you by:
samh
|
From: Dmitri T. <dm...@ne...> - 2003-09-09 01:20:40
|
Issue 1 (patch at the end of the message):
I've found a logical error in file_lock() (from speedy_file.c). Note how
the test inside the for loop decrements the variable after the check is
performed. Right after the loop, there's if (!tries). If file could not
be locked, 'tries' is -1 at that point, not zero. The easiest fix is of
course to change when decrement takes place.
Issue 2:
I found this bug because I found a box after power failure that segfaulted
apache each time a CGI handled by SpeedyCGI was requested. Turns out, a
stale state file (/tmp/speedy.6.f.F), had file_removed byte = 1.
Apparently, the power went right after the flag was set but before unlink
could do its evil thing.
Now comes the question: is there a way to modify SpeedyCGI's algorithm so
that it could recover from these conditions itself, without having to
manually delete the offending file? Right now, if this flag is set
(manually or after a power failure, as it was in my case), SpeedyCGI is
taken out of commission. Maybe, besides being a boolean flag,
file_removed could specify a PID of the process that removed it (but that
raises several more questions)?
My setup:
Linux 2.4.21
Apache 2.0.46
SpeedyCGI 2.21
Thanks,
- Dmitri.
*** speedy_file.c.orig Mon Sep 8 18:54:37 2003
--- speedy_file.c.fixed Mon Sep 8 18:54:33 2003
***************
*** 183,189 ****
file_close2();
}
! for (tries = 5; tries--;) {
/* If file is not open, open it */
if (file_fd == -1) {
str_replace(&saved_tmpbase,
speedy_util_strdup(OPTVAL_TMPBASE));
--- 183,189 ----
file_close2();
}
! for (tries = 5; tries; --tries) {
/* If file is not open, open it */
if (file_fd == -1) {
str_replace(&saved_tmpbase,
speedy_util_strdup(OPTVAL_TMPBASE));
|