public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: fhandler_netdrive: improve debug output
@ 2021-11-22 11:52 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2021-11-22 11:52 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=f03222f242c5d1b94156ea91639c18de9197152a

commit f03222f242c5d1b94156ea91639c18de9197152a
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Nov 19 12:19:31 2021 +0100

    Cygwin: fhandler_netdrive: improve debug output
    
    Add debug output for errors when calling WNet functions.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/autoload.cc          |  1 +
 winsup/cygwin/fhandler_netdrive.cc | 41 ++++++++++++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index e25439725..2b862b5e6 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -630,6 +630,7 @@ LoadDLLfunc (LdapMapErrorToWin32, 0, wldap32)
 
 LoadDLLfunc (WNetCloseEnum, 4, mpr)
 LoadDLLfunc (WNetEnumResourceW, 16, mpr)
+LoadDLLfunc (WNetGetLastErrorW, 20, mpr)
 LoadDLLfunc (WNetGetProviderNameW, 12, mpr)
 LoadDLLfunc (WNetGetResourceInformationW, 16, mpr)
 LoadDLLfunc (WNetOpenEnumW, 20, mpr)
diff --git a/winsup/cygwin/fhandler_netdrive.cc b/winsup/cygwin/fhandler_netdrive.cc
index b924b1876..636535635 100644
--- a/winsup/cygwin/fhandler_netdrive.cc
+++ b/winsup/cygwin/fhandler_netdrive.cc
@@ -42,6 +42,27 @@ struct net_hdls
     HANDLE dom;
   };
 
+static void
+wnet_dbg_out (const char *func, DWORD ndi_ret)
+{
+  DWORD gle_ret;
+  DWORD error;
+  WCHAR errorbuf[MAX_PATH];
+  WCHAR namebuf[MAX_PATH];
+
+  if (ndi_ret != ERROR_EXTENDED_ERROR)
+    {
+      debug_printf ("%s failed: %u", func, ndi_ret);
+      return;
+    }
+  gle_ret = WNetGetLastErrorW (&error, errorbuf, MAX_PATH, namebuf, MAX_PATH);
+  if (gle_ret == NO_ERROR)
+    debug_printf ("%s failed: %u --> %u from '%W': '%W'",
+		  func, ndi_ret, error, namebuf, errorbuf);
+  else
+    debug_printf ("WNetGetLastError failed: %u", gle_ret);
+}
+
 static DWORD WINAPI
 thread_netdrive (void *arg)
 {
@@ -61,7 +82,10 @@ thread_netdrive (void *arg)
       ndi->ret = WNetGetProviderNameW (WNNC_NET_LANMAN, provider,
 				       (size = 256, &size));
       if (ndi->ret != NO_ERROR)
-	break;
+	{
+	  wnet_dbg_out ("WNetGetProviderNameW", ndi->ret);
+	  break;
+	}
       memset (nro, 0, sizeof *nro);
       nro->dwScope = RESOURCE_GLOBALNET;
       nro->dwType = RESOURCETYPE_ANY;
@@ -72,7 +96,10 @@ thread_netdrive (void *arg)
       ndi->ret = WNetOpenEnumW (RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
 				RESOURCEUSAGE_ALL, nro, &nh->net);
       if (ndi->ret != NO_ERROR)
-	break;
+	{
+	  wnet_dbg_out ("WNetOpenEnumW", ndi->ret);
+	  break;
+	}
       while ((ndi->ret = WNetEnumResourceW (nh->net, (cnt = 1, &cnt), nro,
 					    (size = NT_MAX_PATH, &size)))
 	     == NO_ERROR)
@@ -89,13 +116,19 @@ thread_netdrive (void *arg)
       ndi->ret = WNetGetProviderNameW (WNNC_NET_LANMAN, provider,
 				      (size = 256, &size));
       if (ndi->ret != NO_ERROR)
-	break;
+	{
+	  wnet_dbg_out ("WNetGetProviderNameW", ndi->ret);
+	  break;
+	}
       ((LPNETRESOURCEW) ndi->in)->lpProvider = provider;
       ndi->ret = WNetGetResourceInformationW ((LPNETRESOURCEW) ndi->in, nro,
 					      (size = NT_MAX_PATH, &size),
 					      &dummy);
       if (ndi->ret != NO_ERROR)
-	break;
+	{
+	  wnet_dbg_out ("WNetGetResourceInformationW", ndi->ret);
+	  break;
+	}
       ndi->ret = WNetOpenEnumW (RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
 				RESOURCEUSAGE_ALL, nro, &nh->dom);
       break;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-22 11:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 11:52 [newlib-cygwin] Cygwin: fhandler_netdrive: improve debug output Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).