diff --git a/src/file_watch.c b/src/file_watch.c index ed8b5c3..dcd0e1d 100644 --- a/src/file_watch.c +++ b/src/file_watch.c @@ -45,8 +45,7 @@ static void file_watch_ev_cb(EV_P attr_unused, struct ev_io *w, int revent attr_ auto ret = read(w->fd, &inotify_event, sizeof(struct inotify_event)); if (ret < 0) { if (errno != EAGAIN) { - log_error("Failed to read from inotify fd: %s", - strerror(errno)); + log_error_errno("Failed to read from inotify fd"); } break; } @@ -57,7 +56,7 @@ static void file_watch_ev_cb(EV_P attr_unused, struct ev_io *w, int revent attr_ int ret = kevent(fwr->w.fd, NULL, 0, &ev, 1, &timeout); if (ret <= 0) { if (ret < 0) { - log_error("Failed to get kevent: %s", strerror(errno)); + log_error_errno("Failed to get kevent"); } break; } @@ -82,13 +81,13 @@ void *file_watch_init(EV_P) { #ifdef HAS_INOTIFY fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); if (fd < 0) { - log_error("inotify_init1 failed: %s", strerror(errno)); + log_error_errno("inotify_init1 failed"); return NULL; } #elif HAS_KQUEUE fd = kqueue(); if (fd < 0) { - log_error("Failed to create kqueue: %s", strerror(errno)); + log_error_errno("Failed to create kqueue"); return NULL; } #else @@ -131,14 +130,13 @@ bool file_watch_add(void *_fwr, const char *filename, file_watch_cb_t cb, void * wd = inotify_add_watch(fwr->w.fd, filename, IN_CLOSE_WRITE | IN_MOVE_SELF | IN_DELETE_SELF); if (wd < 0) { - log_error("Failed to watch file \"%s\": %s", filename, strerror(errno)); + log_error_errno("Failed to watch file \"%s\"", filename); return false; } #elif HAS_KQUEUE wd = open(filename, O_RDONLY); if (wd < 0) { - log_error("Cannot open file \"%s\" for watching: %s", filename, - strerror(errno)); + log_error_errno("Cannot open file \"%s\" for watching", filename); return false; } @@ -160,7 +158,7 @@ bool file_watch_add(void *_fwr, const char *filename, file_watch_cb_t cb, void * .udata = NULL, }; if (kevent(fwr->w.fd, &ev, 1, NULL, 0, NULL) < 0) { - log_error("Failed to register kevent: %s", strerror(errno)); + log_error_errno("Failed to register kevent"); close(wd); return false; } diff --git a/src/log.h b/src/log.h index 1d16b0d..e40fe3c 100644 --- a/src/log.h +++ b/src/log.h @@ -37,6 +37,8 @@ enum log_level { #define log_error(x, ...) LOG(ERROR, x, ##__VA_ARGS__) #define log_fatal(x, ...) LOG(FATAL, x, ##__VA_ARGS__) +#define log_error_errno(x, ...) LOG(ERROR, x ": %s", ##__VA_ARGS__, strerror(errno)) + struct log; struct log_target;