As this symbol is never exported from the server, don't call it "nbdkit_vfprintf". Also move it to a new file to make forthcoming changes easier. Fixes commit 1c230358462c349533062eda9e4072054fda0e21. --- server/Makefile.am | 1 + server/internal.h | 14 +++++----- server/log.c | 24 ----------------- server/vfprintf.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 30 deletions(-) diff --git a/server/Makefile.am b/server/Makefile.am index 9351fefc..4c789934 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -64,6 +64,7 @@ nbdkit_SOURCES = \ sockets.c \ threadlocal.c \ usergroup.c \ + vfprintf.c \ $(top_srcdir)/include/nbdkit-plugin.h \ $(top_srcdir)/include/nbdkit-filter.h \ $(NULL) diff --git a/server/internal.h b/server/internal.h index e39db8a8..e5c7f514 100644 --- a/server/internal.h +++ b/server/internal.h @@ -298,16 +298,18 @@ extern void apply_debug_flags (void *dl, const char *name); extern void free_debug_flags (void); /* log-*.c */ +extern void log_stderr_verror (const char *fs, va_list args) + __attribute__((__format__ (printf, 1, 0))); +extern void log_syslog_verror (const char *fs, va_list args) + __attribute__((__format__ (printf, 1, 0))); + +/* vfprintf.c */ #if !HAVE_VFPRINTF_PERCENT_M #include <stdio.h> -#define vfprintf nbdkit_vfprintf -extern int nbdkit_vfprintf (FILE *f, const char *fmt, va_list args) +#define vfprintf replace_vfprintf +extern int replace_vfprintf (FILE *f, const char *fmt, va_list args) __attribute__((__format__ (printf, 2, 0))); #endif -extern void log_stderr_verror (const char *fs, va_list args) - __attribute__((__format__ (printf, 1, 0))); -extern void log_syslog_verror (const char *fs, va_list args) - __attribute__((__format__ (printf, 1, 0))); /* backend.c */ struct backend { diff --git a/server/log.c b/server/log.c index a801aa2e..73493563 100644 --- a/server/log.c +++ b/server/log.c @@ -77,27 +77,3 @@ nbdkit_error (const char *fs, ...) nbdkit_verror (fs, args); va_end (args); } - -#if !HAVE_VFPRINTF_PERCENT_M -/* Work around lack of %m in BSD */ -#undef vfprintf - -/* Call the real vfprintf after first changing %m into strerror(errno). */ -int -nbdkit_vfprintf(FILE *f, const char *fmt, va_list args) -{ - char *repl = NULL; - char *p = strstr (fmt, "%m"); /* assume strstr doesn't touch errno */ - int ret; - - /* We only handle the first %m; if a user passes more than one, they - * deserve broken output. - */ - if (p && asprintf (&repl, "%.*s%s%s", (int) (p - fmt), fmt, strerror (errno), - p + 2) > 0) - fmt = repl; - ret = vfprintf (f, fmt, args); - free (repl); - return ret; -} -#endif diff --git a/server/vfprintf.c b/server/vfprintf.c new file mode 100644 index 00000000..2d51456d --- /dev/null +++ b/server/vfprintf.c @@ -0,0 +1,65 @@ +/* nbdkit + * Copyright (C) 2013-2018 Red Hat Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Red Hat nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <errno.h> + +#include "internal.h" + +#if !HAVE_VFPRINTF_PERCENT_M +/* Work around lack of %m in BSD */ +#undef vfprintf + +/* Call the real vfprintf after first changing %m into strerror(errno). */ +int +replace_vfprintf (FILE *f, const char *fmt, va_list args) +{ + char *repl = NULL; + char *p = strstr (fmt, "%m"); /* assume strstr doesn't touch errno */ + int ret; + + /* We only handle the first %m; if a user passes more than one, they + * deserve broken output. + */ + if (p && asprintf (&repl, "%.*s%s%s", (int) (p - fmt), fmt, strerror (errno), + p + 2) > 0) + fmt = repl; + ret = vfprintf (f, fmt, args); + free (repl); + return ret; +} +#endif -- 2.25.0