aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-08-23 05:44:02 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-08-23 08:07:08 +0000
commitc779a5ec7deecf91cb9aca298af90cbc2d9c04d7 (patch)
tree0894ee40fb2f5db9013b8172e4b4ed4312a4edcc
parentdon't use empty struct initializers (diff)
log: include 'fmt' in __VA_ARGS__
This ensures all calls have at least one __VA_ARGS__ argument, thus making them ISO C99 compliant.
-rw-r--r--config.c20
-rw-r--r--log.h26
-rw-r--r--slave.c5
-rw-r--r--spawn.c2
4 files changed, 27 insertions, 26 deletions
diff --git a/config.c b/config.c
index 3112f422..34398216 100644
--- a/config.c
+++ b/config.c
@@ -105,10 +105,10 @@ static const char *const search_binding_action_map[] = {
static_assert(ALEN(search_binding_action_map) == BIND_ACTION_SEARCH_COUNT,
"search binding action map size mismatch");
-#define LOG_AND_NOTIFY_ERR(fmt, ...) \
+#define LOG_AND_NOTIFY_ERR(...) \
do { \
- LOG_ERR(fmt, ## __VA_ARGS__); \
- char *text = xasprintf(fmt, ## __VA_ARGS__); \
+ LOG_ERR(__VA_ARGS__); \
+ char *text = xasprintf(__VA_ARGS__); \
struct user_notification notif = { \
.kind = USER_NOTIFICATION_ERROR, \
.text = text, \
@@ -116,10 +116,10 @@ static_assert(ALEN(search_binding_action_map) == BIND_ACTION_SEARCH_COUNT,
tll_push_back(conf->notifications, notif); \
} while (0)
-#define LOG_AND_NOTIFY_WARN(fmt, ...) \
+#define LOG_AND_NOTIFY_WARN(...) \
do { \
- LOG_WARN(fmt, ## __VA_ARGS__); \
- char *text = xasprintf(fmt, ## __VA_ARGS__); \
+ LOG_WARN(__VA_ARGS__); \
+ char *text = xasprintf(__VA_ARGS__); \
struct user_notification notif = { \
.kind = USER_NOTIFICATION_WARNING, \
.text = text, \
@@ -127,14 +127,14 @@ static_assert(ALEN(search_binding_action_map) == BIND_ACTION_SEARCH_COUNT,
tll_push_back(conf->notifications, notif); \
} while (0)
-#define LOG_AND_NOTIFY_ERRNO(fmt, ...) \
+#define LOG_AND_NOTIFY_ERRNO(...) \
do { \
int _errno = errno; \
- LOG_ERRNO(fmt, ## __VA_ARGS__); \
- int len = snprintf(NULL, 0, fmt, ## __VA_ARGS__); \
+ LOG_ERRNO(__VA_ARGS__); \
+ int len = snprintf(NULL, 0, __VA_ARGS__); \
int errno_len = snprintf(NULL, 0, ": %s", strerror(_errno)); \
char *text = xmalloc(len + errno_len + 1); \
- snprintf(text, len + errno_len + 1, fmt, ## __VA_ARGS__); \
+ snprintf(text, len + errno_len + 1, __VA_ARGS__); \
snprintf(&text[len], errno_len + 1, ": %s", strerror(_errno)); \
struct user_notification notif = { \
.kind = USER_NOTIFICATION_ERROR, \
diff --git a/log.h b/log.h
index 34713d2a..656a8ca0 100644
--- a/log.h
+++ b/log.h
@@ -23,21 +23,21 @@ void log_errno_provided(
const char *file, int lineno, int _errno,
const char *fmt, ...) PRINTF(6);
-#define LOG_ERR(fmt, ...) \
- log_msg(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
-#define LOG_ERRNO(fmt, ...) \
- log_errno(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
-#define LOG_ERRNO_P(fmt, _errno, ...) \
+#define LOG_ERR(...) \
+ log_msg(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, __VA_ARGS__)
+#define LOG_ERRNO(...) \
+ log_errno(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, __VA_ARGS__)
+#define LOG_ERRNO_P(_errno, ...) \
log_errno_provided(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, \
- _errno, fmt, ## __VA_ARGS__)
-#define LOG_WARN(fmt, ...) \
- log_msg(LOG_CLASS_WARNING, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
-#define LOG_INFO(fmt, ...) \
- log_msg(LOG_CLASS_INFO, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
+ _errno, __VA_ARGS__)
+#define LOG_WARN(...) \
+ log_msg(LOG_CLASS_WARNING, LOG_MODULE, __FILE__, __LINE__, __VA_ARGS__)
+#define LOG_INFO(...) \
+ log_msg(LOG_CLASS_INFO, LOG_MODULE, __FILE__, __LINE__, __VA_ARGS__)
#if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG
- #define LOG_DBG(fmt, ...) \
- log_msg(LOG_CLASS_DEBUG, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
+ #define LOG_DBG(...) \
+ log_msg(LOG_CLASS_DEBUG, LOG_MODULE, __FILE__, __LINE__, __VA_ARGS__)
#else
- #define LOG_DBG(fmt, ...)
+ #define LOG_DBG(...)
#endif
diff --git a/slave.c b/slave.c
index b104a8d7..eaa21060 100644
--- a/slave.c
+++ b/slave.c
@@ -281,7 +281,7 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
sigprocmask(SIG_SETMASK, &mask, NULL) < 0)
{
const int _errno = errno;
- LOG_ERRNO_P("failed to restore signals", errno);
+ LOG_ERRNO_P(errno, "failed to restore signals");
(void)!write(fork_pipe[1], &_errno, sizeof(_errno));
_exit(_errno);
}
@@ -332,7 +332,8 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
return -1;
} else if (ret == sizeof(_errno)) {
LOG_ERRNO_P(
- "%s: failed to execute", _errno, argc == 0 ? conf_shell : argv[0]);
+ _errno, "%s: failed to execute",
+ argc == 0 ? conf_shell : argv[0]);
return -1;
} else
LOG_DBG("%s: successfully started", conf_shell);
diff --git a/spawn.c b/spawn.c
index b268bfe5..cc4755f4 100644
--- a/spawn.c
+++ b/spawn.c
@@ -61,7 +61,7 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
LOG_ERRNO("failed to read from pipe");
return false;
} else {
- LOG_ERRNO_P("%s: failed to spawn", _errno, argv[0]);
+ LOG_ERRNO_P(_errno, "%s: failed to spawn", argv[0]);
errno = _errno;
waitpid(pid, NULL, 0);
return false;