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/09/07 07:27:57 UTC

svn commit: r1381880 - in /subversion/trunk: build/ac-macros/macosx.m4 configure.ac subversion/libsvn_subr/sysinfo.c

Author: brane
Date: Fri Sep  7 05:27:57 2012
New Revision: 1381880

URL: http://svn.apache.org/viewvc?rev=1381880&view=rev
Log:
List Mac OS shared libraries with svn --version --verbose.

* build/ac-macros/macosx.m4 (SVN_LIB_MACHO_ITERATE): New.
  Checks for availability of dyld runtime module iteration APIs.
  Defines SVN_HAVE_MACHO_ITERATE.
* configure.ac: Call SVN_LIB_MACHO_ITERATE.

* subversion/libsvn_subr/sysinfo.c:
  [SVN_LIB_MACHO_ITERATE] Include mach-o/dyld.h and mach-o/loader.h.
  (macos_shared_libs): New.
  (svn_sysinfo__loaded_libs): [SVN_LIB_MACHO_ITERATE] Call macos_shared_libs.

Modified:
    subversion/trunk/build/ac-macros/macosx.m4
    subversion/trunk/configure.ac
    subversion/trunk/subversion/libsvn_subr/sysinfo.c

Modified: subversion/trunk/build/ac-macros/macosx.m4
URL: http://svn.apache.org/viewvc/subversion/trunk/build/ac-macros/macosx.m4?rev=1381880&r1=1381879&r2=1381880&view=diff
==============================================================================
--- subversion/trunk/build/ac-macros/macosx.m4 (original)
+++ subversion/trunk/build/ac-macros/macosx.m4 Fri Sep  7 05:27:57 2012
@@ -19,6 +19,32 @@ dnl ====================================
 dnl
 dnl  Mac OS X specific checks
 
+dnl SVN_LIB_MACHO_ITERATE
+dnl Check for _dyld_image_name and _dyld_image_header availability
+AC_DEFUN(SVN_LIB_MACHO_ITERATE,
+[
+  AC_MSG_CHECKING([for Mach-O dynamic module iteration functions])
+
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+    #include <mach-o/dyld.h>
+    #include <mach-o/loader.h>
+    int check(void) {
+      const struct mach_header *header = _dyld_get_image_header(0);
+      const char *name = _dyld_get_image_name(0);
+      if (name && header) return 1;
+      return 0;
+    }
+  ]],[[]])],[have_macho_iterate=yes],[have_macho_iterate=no])
+
+  if test "$have_macho_iterate" = "yes"; then
+    AC_DEFINE([SVN_HAVE_MACHO_ITERATE], [1],
+              [Is Mach-O low-level _dyld API available?])
+    AC_MSG_RESULT([yes])
+  else
+    AC_MSG_RESULT([no])
+  fi
+])
+
 dnl SVN_LIB_MACOS_PLIST
 dnl Assign variables for Mac OS property list support
 AC_DEFUN(SVN_LIB_MACOS_PLIST,

Modified: subversion/trunk/configure.ac
URL: http://svn.apache.org/viewvc/subversion/trunk/configure.ac?rev=1381880&r1=1381879&r2=1381880&view=diff
==============================================================================
--- subversion/trunk/configure.ac (original)
+++ subversion/trunk/configure.ac Fri Sep  7 05:27:57 2012
@@ -479,8 +479,9 @@ if test "$svn_lib_sasl" = "yes"; then
             [Defined if Cyrus SASL v2 is present on the system])
 fi
 
-dnl Mac OS soecufuc features -------------------
+dnl Mac OS specific features -------------------
 
+SVN_LIB_MACHO_ITERATE
 SVN_LIB_MACOS_PLIST
 SVN_LIB_MACOS_KEYCHAIN
 

Modified: subversion/trunk/subversion/libsvn_subr/sysinfo.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sysinfo.c?rev=1381880&r1=1381879&r2=1381880&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sysinfo.c (original)
+++ subversion/trunk/subversion/libsvn_subr/sysinfo.c Fri Sep  7 05:27:57 2012
@@ -61,6 +61,11 @@
 #include <CoreFoundation/CoreFoundation.h>
 #endif
 
+#ifdef SVN_HAVE_MACHO_ITERATE
+#include <mach-o/dyld.h>
+#include <mach-o/loader.h>
+#endif
+
 #if HAVE_UNAME
 static const char *canonical_host_from_uname(apr_pool_t *pool);
 # ifndef SVN_HAVE_MACOS_PLIST
@@ -76,7 +81,12 @@ static const apr_array_header_t *win32_s
 
 #ifdef SVN_HAVE_MACOS_PLIST
 static const char *macos_release_name(apr_pool_t *pool);
-#endif  /* SVN_HAVE_MACOS_PLIST */
+#endif
+
+#ifdef SVN_HAVE_MACHO_ITERATE
+static const apr_array_header_t *macos_shared_libs(apr_pool_t *pool);
+#endif
+
 
 #if LINUX
 static const char *linux_release_name(apr_pool_t *pool);
@@ -144,6 +154,8 @@ svn_sysinfo__loaded_libs(apr_pool_t *poo
 {
 #ifdef WIN32
   return win32_shared_libs(pool);
+#elif defined(SVN_HAVE_MACHO_ITERATE)
+  return macos_shared_libs(pool);
 #else
   return NULL;
 #endif
@@ -841,6 +853,7 @@ win32_shared_libs(apr_pool_t *pool)
 }
 #endif /* WIN32 */
 
+
 #ifdef SVN_HAVE_MACOS_PLIST
 /* Load the SystemVersion.plist or ServerVersion.plist file into a
    property list. Set SERVER to TRUE if the file read was
@@ -1024,3 +1037,93 @@ macos_release_name(apr_pool_t *pool)
   return NULL;
 }
 #endif  /* SVN_HAVE_MACOS_PLIST */
+
+#ifdef SVN_HAVE_MACHO_ITERATE
+/* List the shared libraries loaded by the current process.
+   Ignore frameworks and system libraries, they're just clutter. */
+static const apr_array_header_t *
+macos_shared_libs(apr_pool_t *pool)
+{
+  static const char slb_prefix[] = "/usr/lib/system/";
+  static const char fwk_prefix[] = "/System/Library/Frameworks/";
+  static const char pfk_prefix[] = "/System/Library/PrivateFrameworks/";
+
+  const int slb_prefix_len = strlen(slb_prefix);
+  const int fwk_prefix_len = strlen(fwk_prefix);
+  const int pfk_prefix_len = strlen(pfk_prefix);
+
+  apr_array_header_t *result = NULL;
+  apr_array_header_t *dylibs = NULL;
+
+  uint32_t i;
+  for (i = 0;; ++i)
+    {
+      const struct mach_header *header = _dyld_get_image_header(i);
+      const char *filename = _dyld_get_image_name(i);
+      const char *version;
+      char *truename;
+      svn_sysinfo__loaded_lib_t *lib;
+
+      if (!(header && filename))
+        break;
+
+      switch (header->cputype)
+        {
+        case CPU_TYPE_I386:      version = _("Intel"); break;
+        case CPU_TYPE_X86_64:    version = _("Intel 64-bit"); break;
+        case CPU_TYPE_POWERPC:   version = _("PowerPC"); break;
+        case CPU_TYPE_POWERPC64: version = _("PowerPC 64-bit"); break;
+        default:
+          version = NULL;
+        }
+
+      if (0 == apr_filepath_merge(&truename, "", filename,
+                                  APR_FILEPATH_NATIVE
+                                  | APR_FILEPATH_TRUENAME,
+                                  pool))
+        filename = truename;
+      else
+        filename = apr_pstrdup(pool, filename);
+
+      if (0 == strncmp(filename, slb_prefix, slb_prefix_len)
+          || 0 == strncmp(filename, fwk_prefix, fwk_prefix_len)
+          || 0 == strncmp(filename, pfk_prefix, pfk_prefix_len))
+        {
+          /* Ignore frameworks and system libraries. */
+          continue;
+        }
+
+      if (header->filetype == MH_EXECUTE)
+        {
+          /* Make sure the program filename is first in the list */
+          if (!result)
+            {
+              result = apr_array_make(pool, 32, sizeof(*lib));
+            }
+          lib = &APR_ARRAY_PUSH(result, svn_sysinfo__loaded_lib_t);
+        }
+      else
+        {
+          if (!dylibs)
+            {
+              dylibs = apr_array_make(pool, 32, sizeof(*lib));
+            }
+          lib = &APR_ARRAY_PUSH(dylibs, svn_sysinfo__loaded_lib_t);
+        }
+
+      lib->name = filename;
+      lib->version = version;
+    }
+
+  /* Gather results into one array. */
+  if (dylibs)
+    {
+      if (result)
+        apr_array_cat(result, dylibs);
+      else
+        result = dylibs;
+    }
+
+  return result;
+}
+#endif  /* SVN_HAVE_MACHO_ITERATE */