]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix problem with infinite recursion between write_syslogger_file and
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 12 Mar 2005 01:55:15 +0000 (01:55 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 12 Mar 2005 01:55:15 +0000 (01:55 +0000)
elog if the former has trouble writing its file.  Code review for
Magnus' patch to redirect stderr to syslog on Windows (Bruce's version
seems right, but did some minor prettification).

Backpatch both changes to 8.0 branch.

src/backend/postmaster/syslogger.c
src/backend/utils/error/elog.c

index e057666370ad8d425eede873c12cce84958c922a..60d1337cabb37f5ce19ada63fabc632fdb928399 100644 (file)
@@ -18,7 +18,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.12 2005/01/01 20:44:16 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.12.4.1 2005/03/12 01:55:14 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -697,10 +697,9 @@ write_syslogger_file_binary(const char *buffer, int count)
        LeaveCriticalSection(&sysfileSection);
 #endif
 
+       /* can't use ereport here because of possible recursion */
        if (rc != count)
-               ereport(LOG,
-                               (errcode_for_file_access(),
-                                errmsg("could not write to log file: %m")));
+               write_stderr("could not write to log file: %s\n", strerror(errno));
 }
 
 #ifdef WIN32
index 5b709b04946c54ff4714ab386630251037f2cd05..88f3ec560a73a354abf6de9233959bbe6fa118f7 100644 (file)
@@ -42,7 +42,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.155 2004/12/31 22:01:27 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.155.4.1 2005/03/12 01:55:15 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1557,7 +1557,6 @@ send_message_to_server_log(ErrorData *edata)
                appendStringInfoChar(&buf, '\n');
        }
 
-
 #ifdef HAVE_SYSLOG
        /* Write to syslog, if enabled */
        if (Log_destination & LOG_DESTINATION_SYSLOG)
@@ -1597,7 +1596,9 @@ send_message_to_server_log(ErrorData *edata)
                write_syslog(syslog_level, buf.data);
        }
 #endif   /* HAVE_SYSLOG */
+
 #ifdef WIN32
+       /* Write to eventlog, if enabled */
        if (Log_destination & LOG_DESTINATION_EVENTLOG)
        {
                int                     eventlog_level;
@@ -1628,9 +1629,24 @@ send_message_to_server_log(ErrorData *edata)
                write_eventlog(eventlog_level, buf.data);
        }
 #endif   /* WIN32 */
+
        /* Write to stderr, if enabled */
        if ((Log_destination & LOG_DESTINATION_STDERR) || whereToSendOutput == Debug)
-               fprintf(stderr, "%s", buf.data);
+       {
+#ifdef WIN32
+               /*
+                * In a win32 service environment, there is no usable stderr. Capture
+                * anything going there and write it to the eventlog instead.
+                *
+                * If stderr redirection is active, it's ok to write to stderr
+                * because that's really a pipe to the syslogger process.
+                */
+               if ((!Redirect_stderr || am_syslogger) && pgwin32_is_service())
+                       write_eventlog(EVENTLOG_ERROR_TYPE, buf.data);
+               else
+#endif
+                       fprintf(stderr, "%s", buf.data);
+       }
 
        /* If in the syslogger process, try to write messages direct to file */
        if (am_syslogger)