diff mbox

[ndctl] ndctl, log: save errno over calls to emit log messages

Message ID 149704503297.35935.12657932919759124474.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit ef230a15fb56
Headers show

Commit Message

Dan Williams June 9, 2017, 9:50 p.m. UTC
Some ndctl routines return errno after logging a result. Given the log
message may have updated errno save and restore it over calls to
->log_fn().

Suggested-by: Andy Rudoff <andy.rudoff@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 util/log.c |    3 +++
 1 file changed, 3 insertions(+)
diff mbox

Patch

diff --git a/util/log.c b/util/log.c
index 8ecaf11d3d64..cc4d7d8aad7c 100644
--- a/util/log.c
+++ b/util/log.c
@@ -14,16 +14,19 @@ 
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
+#include <errno.h>
 #include <util/log.h>
 
 void do_log(struct log_ctx *ctx, int priority, const char *file,
 		int line, const char *fn, const char *format, ...)
 {
 	va_list args;
+	int errno_save = errno;
 
 	va_start(args, format);
 	ctx->log_fn(ctx, priority, file, line, fn, format, args);
 	va_end(args);
+	errno = errno_save;
 }
 
 static void log_stderr(struct log_ctx *ctx, int priority, const char *file,