Fix bad error reporting
authorJosé Bollo <jose.bollo@iot.bzh>
Wed, 28 Jun 2017 16:08:29 +0000 (18:08 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Wed, 28 Jun 2017 16:34:48 +0000 (18:34 +0200)
The use of %m was buggy due to the implementation
of 'vverbose': it always returned ENOTTY

   Inappropriate ioctl for device

Change-Id: Idedeefa44ec3cf301d75cd542c54c35a208886a1
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/verbose.c

index 5b2611a..2b00907 100644 (file)
@@ -77,6 +77,7 @@ void verbose_set_name(const char *name, int authority)
 #else
 
 #include <unistd.h>
+#include <errno.h>
 
 static const char *appname;
 
@@ -95,7 +96,9 @@ static const char *prefixes[] = {
 
 void vverbose(int level, const char *file, int line, const char *function, const char *fmt, va_list args)
 {
+       int saverr = errno;
        int tty = isatty(fileno(stderr));
+       errno = saverr;
 
        fprintf(stderr, "%s: ", prefixes[LEVEL(level)] + (tty ? 4 : 0));
        vfprintf(stderr, fmt, args);