From b79299b5e7b8f6ae5fbd86737d50b0056820ab19 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 20 Mar 2017 06:12:55 +0000 Subject: [PATCH] syslogd: try to print out a more helpful message in socksetup(..) if/when getaddrinfo fails If the asprintf call fails, fall back to the old code (as a last ditch effort to provide the end-user with helpful output). Sponsored by: Dell EMC Isilon --- usr.sbin/syslogd/syslogd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 9271ff51c2d..dea71b03cb4 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -2907,8 +2907,17 @@ socksetup(struct peer *pe) pe->pe_serv = "syslog"; error = getaddrinfo(pe->pe_name, pe->pe_serv, &hints, &res0); if (error) { - logerror(gai_strerror(error)); + char *msgbuf; + + asprintf(&msgbuf, "getaddrinfo failed for %s%s: %s", + pe->pe_name == NULL ? "" : pe->pe_name, pe->pe_serv, + gai_strerror(error)); errno = 0; + if (msgbuf == NULL) + logerror(gai_strerror(error)); + else + logerror(msgbuf); + free(msgbuf); die(0); } for (res = res0; res != NULL; res = res->ai_next) { -- 2.45.2