You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@httpd.apache.org by bu...@apache.org on 2005/03/21 21:42:46 UTC
DO NOT REPLY [Bug 34114] New: -
Apache could interleave log entries when writing to a pipe.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=34114>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=34114
Summary: Apache could interleave log entries when writing to a
pipe.
Product: Apache httpd-1.3
Version: 1.3.31
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: mod_log_config
AssignedTo: bugs@httpd.apache.org
ReportedBy: matthew@digitalstratum.com
Affects all 1.x and 2.x versions of Apache when using the "reliable-pipe" option
for writing to log files.
According to POSIX and The Single UNIX Specification Version 3:
http://www.opengroup.org/onlinepubs/009695399/functions/write.html
"Write requests of {PIPE_BUF} bytes or less shall not be interleaved with data
from other processes doing writes on the same pipe. Writes of greater than
{PIPE_BUF} bytes may have data interleaved, on arbitrary boundaries, with writes
by other processes, whether or not the O_NONBLOCK flag of the file status flags
is set."
This is a problem since Apache has each child process log it's own entries
directly to the log file/pipe, and does not take any consideration for entries
larger than PIPE_BUF in length.
In the Apache 1.x branch, the actual writing to a log file uses this code (found
in mod_log_config.c, line 839):
str = ap_palloc(r->pool, len + 1);
for (i = 0, s = str; i < format->nelts; ++i) {
memcpy(s, strs[i], strl[i]);
s += strl[i];
}
write(cls->log_fd, str, len);
When writing to a pipe, if the length of the log entry is greater than PIPE_BUF,
it is possible the entry will be interleaved with other log entries being
written by other child processes which are writing their log entries at the same
time.
In the Apache 2.x branch, there is actually a mutex used when the *experimental*
BufferedLogs config option is used, but the normal logging code does not use the
mutex (nor is the mutex used if threads are not available, obviously.)
The normal logging code in 2.x (readwrite.c, line 194):
do {
rv = write(thefile->filedes, buf, *nbytes);
} while (rv == (apr_size_t)-1 && errno == EINTR);
Fixing the problem in the 2.x branch could be a simple matter of utilizing a
mutex in the apr_file_write() function, for both buffered and non-buffered
logging. The 1.x branch would require possibly using a semaphore or some other
locking solution to serialize the writing of log entires.
If no locking is performed, when writing to a pipe, to ensure that only one
process writes a log entry at a time, then the only other options are:
1. Truncate the log entry to PIPE_BUF and log an error to the error log.
2. Drop the entry completely and log an error to the error log.
The severity of this problem depends on how seriously one considers accurate
logging. For a commercial website I'm sure this is more serious than for a
personal web server.
I'm more than happy to provide any further information and/or assist with
testing/patching related to this problem.
Matthew
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org