From: Ben Pfaff Date: Thu, 27 Mar 2008 21:28:01 +0000 (-0700) Subject: Make vlog preserve errno. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5875f5b634a856a94488d27a9801982882546b0f;p=openvswitch Make vlog preserve errno. This means that adding logging to code disturbs the program's state as little as possible. This is a precautionary measure, not in response to any particular bug. --- diff --git a/include/vlog.h b/include/vlog.h index 93f13a14..b324c4f5 100644 --- a/include/vlog.h +++ b/include/vlog.h @@ -92,6 +92,7 @@ void vlog(enum vlog_module, enum vlog_level, const char *format, ...) * expands to the module used by the current source file, e.g. * #include "vlog.h" * #define THIS_MODULE VLM_NETLINK + * Guaranteed to preserve errno. */ #define VLOG_EMER(...) vlog(THIS_MODULE, VLL_EMER, __VA_ARGS__) #define VLOG_ERR(...) vlog(THIS_MODULE, VLL_ERR, __VA_ARGS__) diff --git a/lib/vlog.c b/lib/vlog.c index 66d57101..c23b67a7 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -266,13 +266,16 @@ vlog_get_levels(void) } /* Writes 'message' to the log at the given 'level' and as coming from the - * given 'module'. */ + * given 'module'. + * + * Guaranteed to preserve errno. */ void vlog(enum vlog_module module, enum vlog_level level, const char *message, ...) { bool log_console = levels[module][VLF_CONSOLE] >= level; bool log_syslog = levels[module][VLF_SYSLOG] >= level; if (log_console || log_syslog) { + int save_errno = errno; static int msg_num; const char *module_name = vlog_get_module_name(module); const char *level_name = vlog_get_level_name(level); @@ -305,5 +308,6 @@ vlog(enum vlog_module module, enum vlog_level level, const char *message, ...) syslog(syslog_levels[level], "%s", s); } + errno = save_errno; } }