diff mbox series

[v2,4/6] util/osdep: Improve error report by calling error_setg_win32()

Message ID 20200227163101.414-5-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series misc: Improve error reporting on Windows | expand

Commit Message

Philippe Mathieu-Daudé Feb. 27, 2020, 4:30 p.m. UTC
Use error_setg_win32() which adds a hint similar to strerror(errno)).

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 util/osdep.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Marc-André Lureau Feb. 27, 2020, 5:22 p.m. UTC | #1
On Thu, Feb 27, 2020 at 5:32 PM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> Use error_setg_win32() which adds a hint similar to strerror(errno)).
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  util/osdep.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/util/osdep.c b/util/osdep.c
> index ef40ae512a..144e217cb9 100644
> --- a/util/osdep.c
> +++ b/util/osdep.c
> @@ -82,8 +82,8 @@ static int qemu_mprotect__osdep(void *addr, size_t size, int prot)
>      DWORD old_protect;
>
>      if (!VirtualProtect(addr, size, prot, &old_protect)) {
> -        error_report("%s: VirtualProtect failed with error code %ld",
> -                     __func__, GetLastError());
> +        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
> +        error_report("%s: VirtualProtect failed: %s", __func__, emsg);
>          return -1;
>      }
>      return 0;
> @@ -506,12 +506,12 @@ int socket_init(void)
>  {
>  #ifdef _WIN32
>      WSADATA Data;
> -    int ret, err;
> +    int ret;
>
>      ret = WSAStartup(MAKEWORD(2, 2), &Data);
>      if (ret != 0) {
> -        err = WSAGetLastError();
> -        error_report("WSAStartup: %d", err);
> +        g_autofree gchar *emsg = g_win32_error_message(WSAGetLastError());
> +        error_report("WSAStartup: %s", emsg);
>          return -1;
>      }
>      atexit(socket_cleanup);
> --
> 2.21.1
>
diff mbox series

Patch

diff --git a/util/osdep.c b/util/osdep.c
index ef40ae512a..144e217cb9 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -82,8 +82,8 @@  static int qemu_mprotect__osdep(void *addr, size_t size, int prot)
     DWORD old_protect;
 
     if (!VirtualProtect(addr, size, prot, &old_protect)) {
-        error_report("%s: VirtualProtect failed with error code %ld",
-                     __func__, GetLastError());
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
+        error_report("%s: VirtualProtect failed: %s", __func__, emsg);
         return -1;
     }
     return 0;
@@ -506,12 +506,12 @@  int socket_init(void)
 {
 #ifdef _WIN32
     WSADATA Data;
-    int ret, err;
+    int ret;
 
     ret = WSAStartup(MAKEWORD(2, 2), &Data);
     if (ret != 0) {
-        err = WSAGetLastError();
-        error_report("WSAStartup: %d", err);
+        g_autofree gchar *emsg = g_win32_error_message(WSAGetLastError());
+        error_report("WSAStartup: %s", emsg);
         return -1;
     }
     atexit(socket_cleanup);