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
This commit is contained in:
Enji Cooper 2017-03-20 06:12:55 +00:00
parent 2a016de1a5
commit b79299b5e7
1 changed files with 10 additions and 1 deletions

View File

@ -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) {