Hi, attached patch will fix segfault in log.c. Segfault arise while reopening of "shared" files. The solusion for this is: while reopening of log files walk logfiles reverse and seek for allready reopened one, if found then point FILE pointer to already reopened and try the same with next log file...
Comments and votes please ... -- Best Regards / Mit besten Gr��en aus K�ln Dipl.-Ing. Alexander Malysh ___________________________________ Centrium GmbH Ehrenstrasse 2 50672 K�ln Fon: +49 (0221) 277 49 240 Fax: +49 (0221) 277 49 109 email: [EMAIL PROTECTED] web: http://www.centrium.de msn: [EMAIL PROTECTED]
--- ../../gateway/gwlib/log.c 2003-03-22 18:51:31.000000000 +0100
+++ gwlib/log.c 2003-03-25 20:38:08.000000000 +0100
@@ -142,11 +142,22 @@
void log_reopen(void)
{
- int i;
+ int i, j, found;
for (i = 0; i < num_logfiles; ++i) {
if (logfiles[i].file != stderr) {
- fclose(logfiles[i].file);
+ found = 0;
+ /* reverse seek for allready reopened logfile */
+ for (j=i-1; j >= 0 && found == 0; j--) {
+ if (strcmp(logfiles[i].filename, logfiles[j].filename) == 0) {
+ logfiles[i].file = logfiles[j].file;
+ found = 1;
+ }
+ }
+ if (found == 1)
+ continue;
+ if (logfiles[i].file != NULL)
+ fclose(logfiles[i].file);
logfiles[i].file = fopen(logfiles[i].filename, "a");
if (logfiles[i].file == NULL) {
error(errno, "Couldn't re-open logfile `%s'.",
@@ -161,7 +172,8 @@
{
while (num_logfiles > 0) {
--num_logfiles;
- if (logfiles[num_logfiles].file != stderr)
+ if (logfiles[num_logfiles].file != stderr &&
+ logfiles[num_logfiles].file != NULL)
fclose(logfiles[num_logfiles].file);
logfiles[num_logfiles].file = NULL;
}
@@ -185,17 +197,12 @@
return -1;
}
- /*
- * Check if the file is already opened for logging.
- * If there is an open file, then assign the file descriptor
- * that is already existing for this log file.
- */
- for (i = 0; i < num_logfiles && f == NULL; ++i) {
+ /* check if file already opened for logging */
+ for (i=0; i < num_logfiles && f == NULL; ++i) {
if (strcmp(logfiles[i].filename, filename) == 0)
- f = logfiles[i].file;
+ f = logfiles[i].file;
}
-
- /* if not previously opened, then open it now */
+ /* if nothing found open log file */
if (f == NULL) {
f = fopen(filename, "a");
if (f == NULL) {
@@ -334,7 +341,8 @@
format(buf, level, place, e, fmt); \
for (i = 0; i < num_logfiles; ++i) { \
if (logfiles[i].exclusive == GW_NON_EXCL && \
- level >= logfiles[i].minimum_output_level) { \
+ level >= logfiles[i].minimum_output_level && \
+ logfiles[i].file != NULL) { \
va_start(args, fmt); \
output(logfiles[i].file, buf, args); \
va_end(args); \
@@ -355,7 +363,8 @@
add_stderr(); \
format(buf, level, place, 0, fmt); \
if (logfiles[e].exclusive == GW_EXCL && \
- level >= logfiles[e].minimum_output_level) { \
+ level >= logfiles[e].minimum_output_level && \
+ logfiles[e].file != NULL) { \
va_start(args, fmt); \
output(logfiles[e].file, buf, args); \
va_end(args); \
smime.p7s
Description: signature
