From f67d6ed25cc6860d5d9d8edf1698d458591db174 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 23 Feb 2018 09:24:19 -0800 Subject: [PATCH] conmon: Use strerror(errno) instead of %m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid: $ make clean && make CFLAGS=-Wpedantic 2>&1 | head -n5 rm -f conmon.o cmsg.o ../bin/conmon cc -Wpedantic -std=c99 -Os -Wall -Wextra -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -c -o conmon.o conmon.c conmon.c: In function ‘write_k8s_log’: conmon.c:32:19: warning: ISO C does not support the ‘%m’ gnu_printf format [-Wformat=] fprintf(stderr, "[conmon:e]: %s %m\n", s); \ ^ from printf(3) [1]: m (Glibc extension; supported by uClibc and musl.) Print output of strerror(errno). No argument is required. strerror, on the other hand, is in POSIX [2]. [1]: http://man7.org/linux/man-pages/man3/printf.3.html [2]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html Signed-off-by: W. Trevor King --- conmon/conmon.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/conmon/conmon.c b/conmon/conmon.c index 407f64fd..61eeee20 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -27,18 +27,18 @@ #include "cmsg.h" -#define pexit(s) \ - do { \ - fprintf(stderr, "[conmon:e]: %s %m\n", s); \ - syslog(LOG_ERR, "conmon : %s %m\n", s); \ - exit(EXIT_FAILURE); \ +#define pexit(s) \ + do { \ + fprintf(stderr, "[conmon:e]: %s %s\n", s, strerror(errno)); \ + syslog(LOG_ERR, "conmon : %s %s\n", s, strerror(errno)); \ + exit(EXIT_FAILURE); \ } while (0) -#define pexitf(fmt, ...) \ - do { \ - fprintf(stderr, "[conmon:e]: " fmt " %m\n", ##__VA_ARGS__); \ - syslog(LOG_ERR, "conmon : " fmt ": %m\n", ##__VA_ARGS__); \ - exit(EXIT_FAILURE); \ +#define pexitf(fmt, ...) \ + do { \ + fprintf(stderr, "[conmon:e]: " fmt " %s\n", ##__VA_ARGS__, strerror(errno)); \ + syslog(LOG_ERR, "conmon : " fmt ": %s\n", ##__VA_ARGS__, strerror(errno)); \ + exit(EXIT_FAILURE); \ } while (0) #define nexit(s) \