Remove am_syslogger global variable
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 11 Mar 2020 15:36:40 +0000 (16:36 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 13 Mar 2020 13:01:15 +0000 (14:01 +0100)
Use the new MyBackendType instead.  More similar changes for other "am
something" variables are possible.  This one was just particularly
simple.

Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>
Reviewed-by: Kuntal Ghosh <kuntalghosh.2007@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@2ndquadrant.com>
Discussion: https://www.postgresql.org/message-id/flat/c65e5196-4f04-4ead-9353-6088c19615a3@2ndquadrant.com

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

index 3b708c3f670a8e71d863e46e4c9e1a795747b5ab..ffcb54968f145a07be0d7e66dc96354549bf1710 100644 (file)
@@ -74,11 +74,6 @@ char    *Log_filename = NULL;
 bool       Log_truncate_on_rotation = false;
 int            Log_file_mode = S_IRUSR | S_IWUSR;
 
-/*
- * Globally visible state (used by elog.c)
- */
-bool       am_syslogger = false;
-
 extern bool redirection_done;
 
 /*
@@ -177,8 +172,6 @@ SysLoggerMain(int argc, char *argv[])
    syslogger_parseArgs(argc, argv);
 #endif                         /* EXEC_BACKEND */
 
-   am_syslogger = true;
-
    MyBackendType = B_LOGGER;
    init_ps_display(NULL);
 
@@ -1078,7 +1071,7 @@ flush_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
 /*
  * Write text to the currently open logfile
  *
- * This is exported so that elog.c can call it when am_syslogger is true.
+ * This is exported so that elog.c can call it when MyBackendType is B_LOGGER.
  * This allows the syslogger process to record elog messages of its own,
  * even though its stderr does not point at the syslog pipe.
  */
index f5b0211f66bd5fff12786be97eb16cddc19e3f08..f8ae94729cce335276d5b7c5eb91ec854c6080f2 100644 (file)
@@ -2923,7 +2923,7 @@ write_csvlog(ErrorData *edata)
    appendStringInfoChar(&buf, '\n');
 
    /* If in the syslogger process, try to write messages direct to file */
-   if (am_syslogger)
+   if (MyBackendType == B_LOGGER)
        write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_CSVLOG);
    else
        write_pipe_chunks(buf.data, buf.len, LOG_DESTINATION_CSVLOG);
@@ -3117,7 +3117,7 @@ send_message_to_server_log(ErrorData *edata)
         * catching stderr output, and we are not ourselves the syslogger.
         * Otherwise, just do a vanilla write to stderr.
         */
-       if (redirection_done && !am_syslogger)
+       if (redirection_done && MyBackendType != B_LOGGER)
            write_pipe_chunks(buf.data, buf.len, LOG_DESTINATION_STDERR);
 #ifdef WIN32
 
@@ -3136,13 +3136,13 @@ send_message_to_server_log(ErrorData *edata)
    }
 
    /* If in the syslogger process, try to write messages direct to file */
-   if (am_syslogger)
+   if (MyBackendType == B_LOGGER)
        write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_STDERR);
 
    /* Write to CSV log if enabled */
    if (Log_destination & LOG_DESTINATION_CSVLOG)
    {
-       if (redirection_done || am_syslogger)
+       if (redirection_done || MyBackendType == B_LOGGER)
        {
            /*
             * send CSV data if it's safe to do so (syslogger doesn't need the
index 9b7a386dbd1644832e24f929ac745cbc7deb97ed..f611bd14114374bbe5a1a8b1ca195a4d00b974f2 100644 (file)
@@ -70,8 +70,6 @@ extern PGDLLIMPORT char *Log_filename;
 extern bool Log_truncate_on_rotation;
 extern int Log_file_mode;
 
-extern bool am_syslogger;
-
 #ifndef WIN32
 extern int syslogPipe[2];
 #else