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++) {
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)
--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;;
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
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;