]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Revert prior and add note why we use strerror().
authorRoy Marples <roy@marples.name>
Fri, 23 Oct 2015 20:28:53 +0000 (20:28 +0000)
committerRoy Marples <roy@marples.name>
Fri, 23 Oct 2015 20:28:53 +0000 (20:28 +0000)
common.c
configure
dhcpcd.c

index ec12378436fcb112dad2646b9ce45b6e1b8753ef..43c99b1a425dd7deb020e4d7d3b86f0f7fe8205d 100644 (file)
--- 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)
index e3d038280123aef958c307f82ec15a89bf8ea48a..a517fd719c8d3f6cf88951ced3b25b4f202e6219 100755 (executable)
--- 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 <<EOF >_printf_m.c
+#include <sys/param.h>
+#include <stdio.h>
+#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 <<EOF >_queue.c
index 9675d2f79b113fa6a427ed30b503fce6a4d48f8b..459556627bd28ba242abebdee061531ffe6382ce 100644 (file)
--- 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;