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

Philippe Mathieu-Daudé posted 6 patches 5 years, 8 months ago
Maintainers: Stefan Hajnoczi <stefanha@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Stefan Weil <sw@weilnetz.de>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Michael Roth <mdroth@linux.vnet.ibm.com>
There is a newer version of this series
[PATCH v2 4/6] util/osdep: Improve error report by calling error_setg_win32()
Posted by Philippe Mathieu-Daudé 5 years, 8 months ago
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(-)

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


Re: [PATCH v2 4/6] util/osdep: Improve error report by calling error_setg_win32()
Posted by Marc-André Lureau 5 years, 8 months ago
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
>