BUG/MEDIUM: logs: segfault writing to log from Lua
Michael Ezzell reported a bug causing haproxy to segfault during startup
when trying to send syslog message from Lua. The function __send_log() can
be called with *p that is NULL and/or when the configuration is not fully
parsed, as is the case with Lua.
This patch fixes this problem by using individual vectors instead of the
pre-generated strings log_htp and log_htp_rfc5424.
Also, this patch fixes a problem causing haproxy to write the wrong pid in
the logs -- the log_htp(_rfc5424) strings were generated at the haproxy
start, but "pid" value would be changed after haproxy is started in
daemon/systemd mode.
diff --git a/include/proto/log.h b/include/proto/log.h
index dcc5ae4..02e01f7 100644
--- a/include/proto/log.h
+++ b/include/proto/log.h
@@ -148,11 +148,6 @@
*/
char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node);
-/*
- * Write hostname, log_tag and pid to the log string
- */
-char *lf_host_tag_pid(char *dst, int format, const char *hostname, const char *log_tag, int pid, size_t size);
-
#endif /* _PROTO_LOG_H */
diff --git a/include/types/global.h b/include/types/global.h
index ea5c387..ca96193 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -126,7 +126,7 @@
char *chroot;
char *pidfile;
char *node, *desc; /* node name & description */
- char *log_tag; /* name for syslog */
+ struct chunk log_tag; /* name for syslog */
struct list logsrvs;
char *log_send_hostname; /* set hostname in syslog header */
char *server_state_base; /* path to a directory where server state files can be found */
diff --git a/include/types/log.h b/include/types/log.h
index 411ba8f..35c1228 100644
--- a/include/types/log.h
+++ b/include/types/log.h
@@ -30,7 +30,7 @@
#define NB_LOG_FACILITIES 24
#define NB_LOG_LEVELS 8
-#define NB_MSG_IOVEC_ELEMENTS 5
+#define NB_MSG_IOVEC_ELEMENTS 8
#define SYSLOG_PORT 514
#define UNIQUEID_LEN 128
diff --git a/include/types/proxy.h b/include/types/proxy.h
index 49debc6..e18ae72 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -346,9 +346,7 @@
struct list logsrvs;
struct list logformat; /* log_format linked list */
struct list logformat_sd; /* log_format linked list for the RFC5424 structured-data part */
- char *log_tag; /* override default syslog tag */
- struct chunk log_htp; /* a syslog header part that contains hostname, log_tag and pid (RFC3164 format) */
- struct chunk log_htp_rfc5424; /* a syslog header part that contains hostname, log_tag and pid (RFC5424 format) */
+ struct chunk log_tag; /* override default syslog tag */
char *header_unique_id; /* unique-id header */
struct list format_unique_id; /* unique-id format */
int to_log; /* things to be logged (LW_*) */