daemon-helper: use _nm_strerror_r() to avoid non-thread-safe strerror()

Yes, there probably are not multiple threads here. It's a matter of principle to
not use smelly functions.

Also, copy the "errno" value we want to print, before calling various functions.
This commit is contained in:
Thomas Haller 2023-08-18 14:59:29 +02:00 committed by Beniamino Galvani
parent 59251cae45
commit c42f6f0997

View file

@ -94,12 +94,15 @@ cmd_resolve_address(void)
NI_NAMEREQD); NI_NAMEREQD);
if (ret != 0) { if (ret != 0) {
if (ret == EAI_SYSTEM) { if (ret == EAI_SYSTEM) {
int errsv = errno;
char buf[1024];
fprintf(stderr, fprintf(stderr,
"getnameinfo() failed: %d (%s), system error: %d (%s)\n", "getnameinfo() failed: %d (%s), system error: %d (%s)\n",
ret, ret,
gai_strerror(ret), gai_strerror(ret),
errno, errsv,
strerror(errno)); _nm_strerror_r(errsv, buf, sizeof(buf)));
} else { } else {
fprintf(stderr, "getnameinfo() failed: %d (%s)\n", ret, gai_strerror(ret)); fprintf(stderr, "getnameinfo() failed: %d (%s)\n", ret, gai_strerror(ret));
} }