From: Roy Marples Date: Fri, 23 Oct 2015 20:28:53 +0000 (+0000) Subject: Revert prior and add note why we use strerror(). X-Git-Tag: v6.9.4~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc1f5830446a19cb67d85cf0a56c7fc771ce1afa;p=thirdparty%2Fdhcpcd.git Revert prior and add note why we use strerror(). --- diff --git a/common.c b/common.c index ec123784..43c99b1a 100644 --- a/common.c +++ b/common.c @@ -132,7 +132,7 @@ logger(struct dhcpcd_ctx *ctx, int pri, const char *fmt, ...) if (ctx == NULL || !(ctx->options & DHCPCD_QUIET) || ctx->log_fd != -1) { const char *p; - char *fp = fmt_cpy, *serr = NULL, serr_buf[128]; + char *fp = fmt_cpy, *serr = NULL; size_t fmt_left = sizeof(fmt_cpy) - 1, fmt_wrote; for (p = fmt; *p != '\0'; p++) { @@ -145,12 +145,13 @@ logger(struct dhcpcd_ctx *ctx, int pri, const char *fmt, ...) p++; } else if (p[0] == '%' && p[1] == 'm') { if (serr == NULL) { - if (strerror_r(serrno, serr_buf, - sizeof(serr_buf))) - snprintf(serr_buf, - sizeof(serr_buf), - "Error %d", serrno); - serr = serr_buf; + /* strerror_r isn't portable. + * strerror_l isn't widely found + * and also problematic to use. + * dhcpcd is only threaded in RTEMS + * where strerror is threadsafe, + * so this should be fine. */ + serr = strerror(serrno); } fmt_wrote = strlcpy(fp, serr, fmt_left); if (fmt_wrote > fmt_left) diff --git a/configure b/configure index e3d03828..a517fd71 100755 --- a/configure +++ b/configure @@ -66,6 +66,8 @@ for x do --without-closefrom) CLOSEFROM=no;; --without-getline) GETLINE=no;; --without-strlcpy) STRLCPY=no;; + --with-printf_m) HAVE_PRINTF_M=yes;; + --without-printf_m) HAVE_PRINTF_M=no;; --without-posix_spawn) POSIX_SPAWN=no;; --without-md5) MD5=no;; --without-sha2) SHA2=no;; @@ -706,6 +708,39 @@ if [ "$DPRINTF" = no ]; then echo "#include \"compat/dprintf.h\"" >>$CONFIG_H fi +if [ -z "$HAVE_PRINTF_M" ]; then + printf "Testing for printf %%m support ..." + cat <_printf_m.c +#include +#include +#ifdef __GLIBC__ +/* glibc has always had it */ +#elif defined(__UCLIBC_HAS_PRINTF_M_SPEC__) +/* test uClibc +#elif defined(__NetBSD_Version__) && __NetBSD_Version__ >= 799002100 +/* NetBSD libc has had it since 7.99.22 */ +#else +/* If you're using musl libc (or any other libc with printf %m support), + * you'll have to pass --with-printf_m to configure to shrink the binary + * size. */ +#error libc does not support printf %m +#endif +int main(void) { + return printf("%m\n"); +} +EOF + if $XCC _printf_m.c -o _printf_m 2>&3; then + HAVE_PRINTF_M=yes + else + HAVE_PRINTF_M=no + fi + echo "$HAVE_PRINTF_M" + rm -f _printf_m.c _printf_m +fi +if [ "$HAVE_PRINTF_M" = yes ]; then + echo "#define HAVE_PRINTF_M" >>$CONFIG_H +fi + if [ -z "$TAILQ_FOREACH_SAFE" ]; then printf "Testing for TAILQ_FOREACH_SAFE ... " cat <_queue.c diff --git a/dhcpcd.c b/dhcpcd.c index 9675d2f7..45955662 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1915,6 +1915,7 @@ exit1: if (ctx.options & DHCPCD_STARTED && !(ctx.options & DHCPCD_FORKED)) logger(&ctx, LOG_INFO, PACKAGE " exited"); + logger(&ctx, LOG_INFO, "error : %m"); logger_close(&ctx); free(ctx.logfile); return i;