From cc7d9cc2edb0d325d2d17c49726dcf8c249b5783 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 29 Jan 2020 15:57:03 +0100 Subject: [PATCH] flog: Save & restore errno In some cases on some platforms this could clobber errno, so doing something like aThingThatFailsWithErrno(); FLOG(category, "Some message"); wperror("something"); would print the wrong error (presumably if that category was enabled). In our case it was our (very) old friend RHEL6 returning ESPIPE instead of EISDIR. Fixes #6545. --- src/flog.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/flog.h b/src/flog.h index ed9988cb8..358afc7be 100644 --- a/src/flog.h +++ b/src/flog.h @@ -171,11 +171,14 @@ std::vector get_flog_categories(); void log_extra_to_flog_file(const wcstring &s); /// Output to the fish log a sequence of arguments, separated by spaces, and ending with a newline. +/// We save and restore errno because we don't want this to affect other code. #define FLOG(wht, ...) \ do { \ if (flog_details::category_list_t::g_instance->wht.enabled) { \ + auto old_errno = errno; \ flog_details::g_logger.acquire()->log_args( \ flog_details::category_list_t::g_instance->wht, __VA_ARGS__); \ + errno = old_errno; \ } \ } while (0) @@ -183,8 +186,10 @@ void log_extra_to_flog_file(const wcstring &s); #define FLOGF(wht, ...) \ do { \ if (flog_details::category_list_t::g_instance->wht.enabled) { \ + auto old_errno = errno; \ flog_details::g_logger.acquire()->log_fmt( \ flog_details::category_list_t::g_instance->wht, __VA_ARGS__); \ + errno = old_errno; \ } \ } while (0)