lib/roken/syslog.c: Initialize hostname to avoid DNS lookups.

Previously, the hostname was initialized to `localhost'.  If it was
not cleared by init_syslog, init_logger_addr (via openlog) would
query gethostbyname to find the IP address of `localhost', which will
essentially always be 127.0.0.1.  But if it was cleared by
init_syslog, init_logger_addr would return 127.0.0.1 anyway.

This way, it always returns 127.0.0.1 in the event of no init_syslog
call, and avoids a DNS lookup.  You can always force a DNS lookup by
passing `localhost' to init_syslog explicitly, of course.

I'm not sure if anything even uses this as a fallback in Heimdal, but
let's avoid leaving a rake to step on.
This commit is contained in:
Taylor R Campbell
2023-06-09 00:28:41 +00:00
committed by Nico Williams
parent 19505537fd
commit e2c0d98965

View File

@@ -50,7 +50,7 @@ static SOCKADDR_IN syslog_hostaddr;
static SOCKET syslog_socket = INVALID_SOCKET; static SOCKET syslog_socket = INVALID_SOCKET;
static char local_hostname[ MAX_COMPUTERNAME_LENGTH + 1 ]; static char local_hostname[ MAX_COMPUTERNAME_LENGTH + 1 ];
static char syslog_hostname[ MAX_COMPUTERNAME_LENGTH + 1 ] = "localhost"; static char syslog_hostname[ MAX_COMPUTERNAME_LENGTH + 1 ];
static unsigned short syslog_port = SYSLOG_PORT; static unsigned short syslog_port = SYSLOG_PORT;
static int datagramm_size; static int datagramm_size;