]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: logs: Use dedicated function to init/deinit log buffers
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 26 Jul 2017 13:33:35 +0000 (15:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 5 Sep 2017 08:29:31 +0000 (10:29 +0200)
Now, we use init_log_buffers and deinit_log_buffers to, respectively, initialize
and deinitialize log buffers used for syslog messages.

These functions have been introduced to be used by threads, to deal with
thread-local log buffers.

include/proto/log.h
src/cfgparse.c
src/haproxy.c
src/log.c

index 2d4ca84f175b8d1c85d52499f759d7ed12bc1bc2..72ff744fbbaab454cf273924ed97e78486f3b2dc 100644 (file)
@@ -53,6 +53,11 @@ extern char *logline_rfc5424;
  */
 void init_log();
 
+
+/* Initialize/Deinitialize log buffers used for syslog messages */
+int init_log_buffers();
+void deinit_log_buffers();
+
 /*
  * Builds a log line.
  */
index c2115e6a2b808a078f104aec99006c578377b87f..d49156056563318c2ec35a82d03326d4ce9730bf 100644 (file)
@@ -1420,10 +1420,11 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
 
                if (logsrv->maxlen > global.max_syslog_len) {
                        global.max_syslog_len = logsrv->maxlen;
-                       logheader = my_realloc2(logheader, global.max_syslog_len + 1);
-                       logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1);
-                       logline = my_realloc2(logline, global.max_syslog_len + 1);
-                       logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
+                       if (!init_log_buffers()) {
+                               Alert("parsing [%s:%d] : failed to initialize log buffers.\n", file, linenum);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
                }
 
                /* after the length, a format may be specified */
@@ -6082,10 +6083,11 @@ stats_error_parsing:
 
                        if (logsrv->maxlen > global.max_syslog_len) {
                                global.max_syslog_len = logsrv->maxlen;
-                               logheader = my_realloc2(logheader, global.max_syslog_len + 1);
-                               logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1);
-                               logline = my_realloc2(logline, global.max_syslog_len + 1);
-                               logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
+                               if (!init_log_buffers()) {
+                                       Alert("parsing [%s:%d] : failed to initialize log buffers.\n", file, linenum);
+                                       err_code |= ERR_ALERT | ERR_FATAL;
+                                       goto out;
+                               }
                        }
 
                        /* after the length, a format may be specified */
index efc4da552aa0893792685e10bb0e1b06db976310..7c925eaea7a27fb74e91826d818d1b13027e8df6 100644 (file)
@@ -2107,6 +2107,7 @@ void deinit(void)
 
        cfg_unregister_sections();
 
+       deinit_log_buffers();
        deinit_trash_buffers();
 
        protocol_unbind_all();
index e9a8a7d7c056906e502f555f9b50d7205a2ab444..5c42f6b2a2c601193273d59fe0fa07459150449f 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1322,6 +1322,31 @@ void init_log()
        }
 }
 
+/* Initialize log buffers used for syslog messages */
+int init_log_buffers()
+{
+       logheader = my_realloc2(logheader, global.max_syslog_len + 1);
+       logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1);
+       logline = my_realloc2(logline, global.max_syslog_len + 1);
+       logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
+       if (!logheader || !logline_rfc5424 || !logline || !logline_rfc5424)
+               return 0;
+       return 1;
+}
+
+/* Deinitialize log buffers used for syslog messages */
+void deinit_log_buffers()
+{
+       free(logheader);
+       free(logheader_rfc5424);
+       free(logline);
+       free(logline_rfc5424);
+       logheader         = NULL;
+       logheader_rfc5424 = NULL;
+       logline           = NULL;
+       logline_rfc5424   = NULL;
+}
+
 /* Builds a log line in <dst> based on <list_format>, and stops before reaching
  * <maxsize> characters. Returns the size of the output string in characters,
  * not counting the trailing zero which is always added if the resulting size