From 9356aa9dd8db864518e024bbbe05bc1a56db8497 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 23 Feb 2018 11:11:18 -0800 Subject: [PATCH] conmon/cmsg: Distinguish error(s) from errorf(fmt, ...) and replace %m The same as the last two commits, except for cmsg.c instead of conmon.c. Signed-off-by: W. Trevor King --- conmon/cmsg.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/conmon/cmsg.c b/conmon/cmsg.c index c44db2ef..6587a15c 100644 --- a/conmon/cmsg.c +++ b/conmon/cmsg.c @@ -26,11 +26,18 @@ #include "cmsg.h" -#define error(fmt, ...) \ - ({ \ - fprintf(stderr, "nsenter: " fmt ": %m\n", ##__VA_ARGS__); \ - errno = ECOMM; \ - goto err; /* return value */ \ +#define error(s) \ + ({ \ + fprintf(stderr, "nsenter: %s %s\n", s, strerror(errno)); \ + errno = ECOMM; \ + goto err; /* return value */ \ + }) + +#define errorf(fmt, ...) \ + ({ \ + fprintf(stderr, "nsenter: " fmt ": %s\n", ##__VA_ARGS__, strerror(errno)); \ + errno = ECOMM; \ + goto err; /* return value */ \ }) /* @@ -103,7 +110,7 @@ struct file_t recvfd(int sockfd) /* TODO: Make this dynamic with MSG_PEEK. */ file.name = malloc(TAG_BUFFER); if (!file.name) - error("recvfd: failed to allocate file.tag buffer\n"); + error("recvfd: failed to allocate file.tag buffer"); /* * We need to "recieve" the non-ancillary data even though we don't @@ -128,11 +135,11 @@ struct file_t recvfd(int sockfd) if (!cmsg) error("recvfd: got NULL from CMSG_FIRSTHDR"); if (cmsg->cmsg_level != SOL_SOCKET) - error("recvfd: expected SOL_SOCKET in cmsg: %d", cmsg->cmsg_level); + errorf("recvfd: expected SOL_SOCKET in cmsg: %d", cmsg->cmsg_level); if (cmsg->cmsg_type != SCM_RIGHTS) - error("recvfd: expected SCM_RIGHTS in cmsg: %d", cmsg->cmsg_type); + errorf("recvfd: expected SCM_RIGHTS in cmsg: %d", cmsg->cmsg_type); if (cmsg->cmsg_len != CMSG_LEN(sizeof(int))) - error("recvfd: expected correct CMSG_LEN in cmsg: %lu", cmsg->cmsg_len); + errorf("recvfd: expected correct CMSG_LEN in cmsg: %lu", cmsg->cmsg_len); fdptr = (int *) CMSG_DATA(cmsg); if (!fdptr || *fdptr < 0)