[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/39] Do not use %m in common code to print error messages
From: |
Paolo Bonzini |
Subject: |
[PULL 05/39] Do not use %m in common code to print error messages |
Date: |
Thu, 24 Oct 2019 16:03:21 +0200 |
From: Thomas Huth <address@hidden>
The %m format specifier is an extension from glibc - and when compiling
QEMU for NetBSD, the compiler correctly complains, e.g.:
/home/qemu/qemu-test.ELjfrQ/src/util/main-loop.c: In function 'sigfd_handler':
/home/qemu/qemu-test.ELjfrQ/src/util/main-loop.c:64:13: warning: %m is only
allowed in syslog(3) like functions [-Wformat=]
printf("read from sigfd returned %zd: %m\n", len);
^
Let's use g_strerror() here instead, which is an easy-to-use wrapper
around the thread-safe strerror_r() function.
While we're at it, also convert the "printf()" in main-loop.c into
the preferred "error_report()".
Signed-off-by: Thomas Huth <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/misc/tmp421.c | 4 ++--
util/main-loop.c | 3 ++-
util/systemd.c | 4 ++--
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c
index 9f04470..c0bc150 100644
--- a/hw/misc/tmp421.c
+++ b/hw/misc/tmp421.c
@@ -120,7 +120,7 @@ static void tmp421_get_temperature(Object *obj, Visitor *v,
const char *name,
int tempid;
if (sscanf(name, "temperature%d", &tempid) != 1) {
- error_setg(errp, "error reading %s: %m", name);
+ error_setg(errp, "error reading %s: %s", name, g_strerror(errno));
return;
}
@@ -160,7 +160,7 @@ static void tmp421_set_temperature(Object *obj, Visitor *v,
const char *name,
}
if (sscanf(name, "temperature%d", &tempid) != 1) {
- error_setg(errp, "error reading %s: %m", name);
+ error_setg(errp, "error reading %s: %s", name, g_strerror(errno));
return;
}
diff --git a/util/main-loop.c b/util/main-loop.c
index e3eaa55..eda63fe 100644
--- a/util/main-loop.c
+++ b/util/main-loop.c
@@ -61,7 +61,8 @@ static void sigfd_handler(void *opaque)
}
if (len != sizeof(info)) {
- printf("read from sigfd returned %zd: %m\n", len);
+ error_report("read from sigfd returned %zd: %s", len,
+ g_strerror(errno));
return;
}
diff --git a/util/systemd.c b/util/systemd.c
index d22e86c..1dd0367 100644
--- a/util/systemd.c
+++ b/util/systemd.c
@@ -60,8 +60,8 @@ unsigned int check_socket_activation(void)
* and we should exit.
*/
error_report("Socket activation failed: "
- "invalid file descriptor fd = %d: %m",
- fd);
+ "invalid file descriptor fd = %d: %s",
+ fd, g_strerror(errno));
exit(EXIT_FAILURE);
}
}
--
1.8.3.1
- [PULL 00/39] Misc (mostly x86) patches for 2019-10-24, Paolo Bonzini, 2019/10/24
- [PULL 01/39] target/i386: log MCE guest and host addresses, Paolo Bonzini, 2019/10/24
- [PULL 06/39] memory-device: simplify Makefile.objs conditions, Paolo Bonzini, 2019/10/24
- [PULL 04/39] i386/kvm: add NoNonArchitecturalCoreSharing Hyper-V enlightenment, Paolo Bonzini, 2019/10/24
- [PULL 02/39] mc146818rtc: fix timer interrupt reinjection, Paolo Bonzini, 2019/10/24
- [PULL 05/39] Do not use %m in common code to print error messages,
Paolo Bonzini <=
- [PULL 03/39] Updated Bulgarian translation (19) - 4.1.0, Paolo Bonzini, 2019/10/24
- [PULL 08/39] hw/i386/pc: rename functions shared with non-PC machines, Paolo Bonzini, 2019/10/24
- [PULL 07/39] hw/virtio: Factorize virtio-mmio headers, Paolo Bonzini, 2019/10/24
- [PULL 10/39] hw/i386/pc: replace use of strtol with qemu_strtoui in x86_load_linux(), Paolo Bonzini, 2019/10/24
- [PULL 11/39] hw/i386/pc: avoid an assignment in if condition in x86_load_linux(), Paolo Bonzini, 2019/10/24
- [PULL 09/39] hw/i386/pc: fix code style issues on functions that will be moved out, Paolo Bonzini, 2019/10/24
- [PULL 17/39] hw/intc/apic: reject pic ints if isa_pic == NULL, Paolo Bonzini, 2019/10/24
- [PULL 21/39] MAINTAINERS: add microvm related files, Paolo Bonzini, 2019/10/24