[MINOR] log: add support for passing the forwarded hostname

Haproxy does not include the hostname rather the IP of the machine in
the syslog headers it sends. Unfortunately this means that for each log
line rsyslog does a reverse dns on the client IP and in the case of
non-routable IPs one gets the public hostname not the internal one.

While this is valid according to RFC3164 as one might imagine this is
troublsome if you have some machines with public IPs, internal IPs, no
reverse DNS entries, etc and you want a standardized hostname based log
directory structure. The rfc says the preferred value is the hostname.

This patch adds a global "log-send-hostname" statement which accepts an
optional string to force the host name. If unset, the local host name
is used.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 9d3e2fc..ddfbe42 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -966,6 +966,28 @@
 			err_code |= ERR_ALERT | ERR_FATAL;
 		}
 	}
+	else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */
+		char *name;
+		int len;
+
+		if (global.log_send_hostname != NULL) {
+			Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
+			err_code |= ERR_ALERT;
+			goto out;
+		}
+
+		if (*(args[1]))
+			name = args[1];
+		else
+			name = hostname;
+
+		len = strlen(name);
+
+		/* We'll add a space after the name to respect the log format */
+		free(global.log_send_hostname);
+		global.log_send_hostname = malloc(len + 2);
+		snprintf(global.log_send_hostname, len + 2, "%s ", name);
+	}
 	else if (!strcmp(args[0], "spread-checks")) {  /* random time between checks (0-50) */
 		if (global.spread_checks != 0) {
 			Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
diff --git a/src/haproxy.c b/src/haproxy.c
index c5aa3cc..9ba0820 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -867,6 +867,7 @@
 
 	protocol_unbind_all();
 
+	free(global.log_send_hostname); global.log_send_hostname = NULL;
 	free(global.chroot);  global.chroot = NULL;
 	free(global.pidfile); global.pidfile = NULL;
 	free(global.node);    global.node = NULL;
diff --git a/src/log.c b/src/log.c
index d1387b5..d52727b 100644
--- a/src/log.c
+++ b/src/log.c
@@ -189,9 +189,10 @@
 		get_localtime(tvsec, &tm);
 
 		hdr_len = snprintf(logmsg, sizeof(logmsg),
-				   "<<<<>%s %2d %02d:%02d:%02d %s[%d]: ",
+				   "<<<<>%s %2d %02d:%02d:%02d %s%s[%d]: ",
 				   monthname[tm.tm_mon],
 				   tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
+				   global.log_send_hostname ? global.log_send_hostname : "",
 				   progname, pid);
 		/* WARNING: depending upon implementations, snprintf may return
 		 * either -1 or the number of bytes that would be needed to store