public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: fhandler_netdrive: improve debug output
Date: Mon, 22 Nov 2021 11:52:13 +0000 (GMT)	[thread overview]
Message-ID: <20211122115213.916B0385803B@sourceware.org> (raw)

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;


                 reply	other threads:[~2021-11-22 11:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211122115213.916B0385803B@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).