You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2012/08/09 10:27:53 UTC

svn commit: r1371087 - in /subversion/trunk: build.conf subversion/libsvn_subr/opt.c subversion/libsvn_subr/sysinfo.c

Author: brane
Date: Thu Aug  9 08:27:53 2012
New Revision: 1371087

URL: http://svn.apache.org/viewvc?rev=1371087&view=rev
Log:
Display list of loaded DLLs with "svn --version --verbose" on Windows.

* subversion/libsvn_subr/opt.c (svn_opt__print_version_info):
  Update output for loaded module list.

* subversion/libsvn_subr/sysinfo.c [WIN32]: Import psapi.h
  Import apr_file_info.h.
  (win32_shared_libs, enum_loaded_modules, FNENUMPROCESSMODULES): New.
  (svn_sysinfo__loaded_libs) [WIN32]: Call win32_shared_libs.

Modified:
    subversion/trunk/build.conf
    subversion/trunk/subversion/libsvn_subr/opt.c
    subversion/trunk/subversion/libsvn_subr/sysinfo.c

Modified: subversion/trunk/build.conf
URL: http://svn.apache.org/viewvc/subversion/trunk/build.conf?rev=1371087&r1=1371086&r2=1371087&view=diff
==============================================================================
--- subversion/trunk/build.conf (original)
+++ subversion/trunk/build.conf Thu Aug  9 08:27:53 2012
@@ -296,7 +296,8 @@ type = lib
 install = fsmod-lib
 path = subversion/libsvn_subr
 libs = aprutil apriconv apr xml zlib apr_memcache sqlite magic
-msvc-libs = kernel32.lib advapi32.lib shfolder.lib ole32.lib crypt32.lib version.lib
+msvc-libs = kernel32.lib advapi32.lib shfolder.lib ole32.lib
+            crypt32.lib version.lib psapi.lib
 msvc-export = 
         svn_auth.h svn_base64.h svn_cache_config.h svn_checksum.h svn_cmdline.h
         svn_compat.h svn_config.h svn_ctype.h svn_dirent_uri.h svn_dso.h 

Modified: subversion/trunk/subversion/libsvn_subr/opt.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/opt.c?rev=1371087&r1=1371086&r2=1371087&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/opt.c (original)
+++ subversion/trunk/subversion/libsvn_subr/opt.c Thu Aug  9 08:27:53 2012
@@ -1146,9 +1146,9 @@ svn_opt__print_version_info(const char *
 
       if (dlibs)
         {
-          SVN_ERR(svn_cmdline_fputs(_("\nLoaded shared libraries:\n"),
+          SVN_ERR(svn_cmdline_fputs(_("* loaded shared libraries:\n"),
                                     stdout, pool));
-          SVN_ERR(svn_cmdline_printf(pool, "\n%s\n", dlibs));
+          SVN_ERR(svn_cmdline_fputs(dlibs, stdout, pool));
         }
     }
 

Modified: subversion/trunk/subversion/libsvn_subr/sysinfo.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sysinfo.c?rev=1371087&r1=1371086&r2=1371087&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sysinfo.c (original)
+++ subversion/trunk/subversion/libsvn_subr/sysinfo.c Thu Aug  9 08:27:53 2012
@@ -25,7 +25,9 @@
 
 #ifdef WIN32
 #define WIN32_LEAN_AND_MEAN
+#define PSAPI_VERSION 1
 #include <windows.h>
+#include <psapi.h>
 #endif
 
 #define APR_WANT_STRFUNC
@@ -33,6 +35,7 @@
 
 #include <apr_lib.h>
 #include <apr_pools.h>
+#include <apr_file_info.h>
 
 #include "svn_ctype.h"
 #include "svn_error.h"
@@ -52,6 +55,7 @@ static const char* canonical_host_from_u
 #ifdef WIN32
 static const char * win32_canonical_host(apr_pool_t *pool);
 static const char * win32_release_name(apr_pool_t *pool);
+static const char * win32_shared_libs(apr_pool_t *pool);
 #endif /* WIN32 */
 
 
@@ -82,7 +86,11 @@ svn_sysinfo__release_name(apr_pool_t *po
 const char *
 svn_sysinfo__loaded_libs(apr_pool_t *pool)
 {
+#ifdef WIN32
+  return win32_shared_libs(pool);
+#else
   return NULL;
+#endif
 }
 
 
@@ -140,6 +148,7 @@ canonical_host_from_uname(apr_pool_t *po
 
 #ifdef WIN32
 typedef DWORD (WINAPI *FNGETNATIVESYSTEMINFO)(LPSYSTEM_INFO);
+typedef BOOL (WINAPI *FNENUMPROCESSMODULES) (HANDLE, HMODULE, DWORD, LPDWORD);
 
 /* Get sysstem and version info, and try to tell the difference
    between the native system type and the runtime environment of the
@@ -349,4 +358,61 @@ win32_release_name(apr_pool_t *pool)
                       (unsigned int)osinfo.dwMinorVersion,
                       (unsigned int)osinfo.dwBuildNumber);
 }
+
+
+/* Get a list of handles of shared libs loaded by the current
+   process. Returns a NULL-terminated array alocated from POOL. */
+static HMODULE *
+enum_loaded_modules(apr_pool_t *pool)
+{
+  HANDLE current = GetCurrentProcess();
+  HMODULE dummy[1];
+  HMODULE *handles;
+  DWORD size;
+
+  if (!EnumProcessModules(current, dummy, sizeof(dummy), &size))
+    return NULL;
+
+  handles = apr_palloc(pool, size + sizeof *handles);
+  if (!EnumProcessModules(current, handles, size, &size))
+    return NULL;
+  handles[size / sizeof *handles] = NULL;
+  return handles;
+}
+
+
+/* List the shared libraries loaded by the current process. */
+const char *
+win32_shared_libs(apr_pool_t *pool)
+{
+  wchar_t buffer[MAX_PATH + 1];
+  HMODULE *handles = enum_loaded_modules(pool);
+  char *libinfo = "";
+  HMODULE *module;
+
+  for (module = handles; module && *module; ++module)
+    {
+      const char *filename;
+      if (GetModuleFileNameW(*module, buffer, MAX_PATH))
+        {
+          buffer[MAX_PATH] = 0;
+          filename = wcs_to_utf8(buffer, pool);
+          if (filename)
+            {
+              char *truename;
+              if (0 == apr_filepath_merge(&truename, "", filename,
+                                          APR_FILEPATH_NATIVE
+                                          | APR_FILEPATH_TRUENAME,
+                                          pool))
+                filename = truename;
+              libinfo = apr_pstrcat(pool, libinfo, "  - ",
+                                    filename, "\n", NULL);
+            }
+        }
+    }
+
+  if (*libinfo)
+    return libinfo;
+  return NULL;
+}
 #endif /* WIN32 */