mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 23:56:57 +02:00
MINOR: logs: Use dedicated function to init/deinit log buffers
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.
This commit is contained in:
parent
3ef2639870
commit
0132d06f68
@ -53,6 +53,11 @@ extern char *logline_rfc5424;
|
|||||||
*/
|
*/
|
||||||
void init_log();
|
void init_log();
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialize/Deinitialize log buffers used for syslog messages */
|
||||||
|
int init_log_buffers();
|
||||||
|
void deinit_log_buffers();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Builds a log line.
|
* Builds a log line.
|
||||||
*/
|
*/
|
||||||
|
@ -1420,10 +1420,11 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
|||||||
|
|
||||||
if (logsrv->maxlen > global.max_syslog_len) {
|
if (logsrv->maxlen > global.max_syslog_len) {
|
||||||
global.max_syslog_len = logsrv->maxlen;
|
global.max_syslog_len = logsrv->maxlen;
|
||||||
logheader = my_realloc2(logheader, global.max_syslog_len + 1);
|
if (!init_log_buffers()) {
|
||||||
logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1);
|
Alert("parsing [%s:%d] : failed to initialize log buffers.\n", file, linenum);
|
||||||
logline = my_realloc2(logline, global.max_syslog_len + 1);
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
|
goto out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* after the length, a format may be specified */
|
/* after the length, a format may be specified */
|
||||||
@ -6082,10 +6083,11 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
|||||||
|
|
||||||
if (logsrv->maxlen > global.max_syslog_len) {
|
if (logsrv->maxlen > global.max_syslog_len) {
|
||||||
global.max_syslog_len = logsrv->maxlen;
|
global.max_syslog_len = logsrv->maxlen;
|
||||||
logheader = my_realloc2(logheader, global.max_syslog_len + 1);
|
if (!init_log_buffers()) {
|
||||||
logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1);
|
Alert("parsing [%s:%d] : failed to initialize log buffers.\n", file, linenum);
|
||||||
logline = my_realloc2(logline, global.max_syslog_len + 1);
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
|
goto out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* after the length, a format may be specified */
|
/* after the length, a format may be specified */
|
||||||
|
@ -2107,6 +2107,7 @@ void deinit(void)
|
|||||||
|
|
||||||
cfg_unregister_sections();
|
cfg_unregister_sections();
|
||||||
|
|
||||||
|
deinit_log_buffers();
|
||||||
deinit_trash_buffers();
|
deinit_trash_buffers();
|
||||||
|
|
||||||
protocol_unbind_all();
|
protocol_unbind_all();
|
||||||
|
25
src/log.c
25
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
|
/* 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,
|
* <maxsize> characters. Returns the size of the output string in characters,
|
||||||
* not counting the trailing zero which is always added if the resulting size
|
* not counting the trailing zero which is always added if the resulting size
|
||||||
|
Loading…
Reference in New Issue
Block a user