From dd3e110a707fc9ac5653969b22e6489f7e100d50 Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Sun, 20 Dec 2020 20:03:55 +0100 Subject: [PATCH] reorder & fmt --- gmid.c | 62 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/gmid.c b/gmid.c index e9f90f5..1e57bca 100644 --- a/gmid.c +++ b/gmid.c @@ -37,11 +37,11 @@ #ifndef __OpenBSD__ # define pledge(a, b) 0 # define unveil(a, b) 0 -#endif /* __OpenBSD__ */ +#endif #ifndef INFTIM # define INFTIM -1 -#endif /* INFTIM */ +#endif #define GEMINI_URL_LEN (1024+3) /* URL max len + \r\n + \0 */ @@ -64,6 +64,35 @@ setenv((var), _tmp, 1); \ } while(0) +#define LOG(priority, c, fmt, ...) \ + do { \ + char buf[INET_ADDRSTRLEN]; \ + if (inet_ntop((c)->af, &(c)->addr, \ + buf, sizeof(buf)) == NULL) \ + FATAL("inet_ntop: %s", strerror(errno)); \ + if (foreground) \ + fprintf(stderr, \ + "%s " fmt "\n", buf, __VA_ARGS__); \ + else \ + syslog((priority) | LOG_DAEMON, \ + "%s " fmt, buf, __VA_ARGS__); \ + } while (0) + +#define LOGE(c, fmt, ...) LOG(LOG_ERR, c, fmt, __VA_ARGS__) +#define LOGN(c, fmt, ...) LOG(LOG_NOTICE, c, fmt, __VA_ARGS__) +#define LOGI(c, fmt, ...) LOG(LOG_INFO, c, fmt, __VA_ARGS__) +#define LOGD(c, fmt, ...) LOG(LOG_DEBUG, c, fmt, __VA_ARGS__) + +#define FATAL(fmt, ...) \ + do { \ + if (foreground) \ + fprintf(stderr, fmt "\n", __VA_ARGS__); \ + else \ + syslog(LOG_DAEMON | LOG_CRIT, \ + fmt, __VA_ARGS__); \ + exit(1); \ + } while (0) + enum { S_OPEN, S_INITIALIZING, @@ -114,35 +143,6 @@ struct etm { /* file extension to mime */ {NULL, NULL} }; -#define LOG(priority, c, fmt, ...) \ - do { \ - char buf[INET_ADDRSTRLEN]; \ - if (inet_ntop((c)->af, &(c)->addr, \ - buf, sizeof(buf)) == NULL) \ - FATAL("inet_ntop: %s", strerror(errno)); \ - if (foreground) \ - fprintf(stderr, \ - "%s " fmt "\n", buf, __VA_ARGS__); \ - else \ - syslog((priority) | LOG_DAEMON, \ - "%s " fmt, buf, __VA_ARGS__); \ - } while (0) - -#define LOGE(c, fmt, ...) LOG(LOG_ERR, c, fmt, __VA_ARGS__) -#define LOGN(c, fmt, ...) LOG(LOG_NOTICE, c, fmt, __VA_ARGS__) -#define LOGI(c, fmt, ...) LOG(LOG_INFO, c, fmt, __VA_ARGS__) -#define LOGD(c, fmt, ...) LOG(LOG_DEBUG, c, fmt, __VA_ARGS__) - -#define FATAL(fmt, ...) \ - do { \ - if (foreground) \ - fprintf(stderr, fmt "\n", __VA_ARGS__); \ - else \ - syslog(LOG_DAEMON | LOG_CRIT, \ - fmt, __VA_ARGS__); \ - exit(1); \ - } while (0) - const char *dir, *cgi; int dirfd; int port;