From f2a2fddcd5c3700e31872d7e67c3a72e67e4f916 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 12 Jun 2023 01:38:59 +0200 Subject: log: thread-safe logging --- src/log.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/log.h b/src/log.h index 9b0c945..da12efe 100644 --- a/src/log.h +++ b/src/log.h @@ -56,20 +56,26 @@ static inline void log_prefix(FILE *dest) #define log(...) \ do { \ + flockfile(stdout); \ log_prefix(stdout); \ printf(__VA_ARGS__); \ + funlockfile(stdout); \ } while (0) #define log_err(...) \ do { \ + flockfile(stderr); \ log_err_prefix(); \ fprintf(stderr, __VA_ARGS__); \ + funlockfile(stderr); \ } while (0) #define log_errno(s) \ do { \ + flockfile(stderr); \ log_err_prefix(); \ perror(s); \ + funlockfile(stderr); \ } while (0) #define log_errno_if(expr, s) \ -- cgit v1.2.3