[netperf-dev] netperf4 commit notice r112 - branches/glib_migration/src

raj at netperf.org raj at netperf.org
Wed Mar 29 18:00:37 PST 2006


Author: raj
Date: 2006-03-29 18:00:36 -0800 (Wed, 29 Mar 2006)
New Revision: 112

Modified:
   branches/glib_migration/src/netlib.c
Log:
Since g_module_open already knows about "la" files, write some new,
cleaner routines for trying to find the libraries to load.  Compiles,
but not yet used.


Modified: branches/glib_migration/src/netlib.c
===================================================================
--- branches/glib_migration/src/netlib.c	2006-03-30 00:56:12 UTC (rev 111)
+++ branches/glib_migration/src/netlib.c	2006-03-30 02:00:36 UTC (rev 112)
@@ -1269,6 +1269,94 @@
   if (ld_library_path) free(ld_library_path);
 }
 
+/* attempt to open a library file by prepending path components to
+   it */
+GModule *
+open_library_path(const gchar *library_name, const gchar *pathvar) {
+
+  const gchar *path;
+  gchar **path_elts;
+  int   index;
+  gchar *filename;
+  GModule *handle = NULL;
+
+  path = g_getenv(pathvar);
+
+  if (path) {
+    path_elts = g_strsplit(path,G_SEARCHPATH_SEPARATOR_S,0);
+    for (index = 0; ((path_elts[index] != NULL) 
+		     && (NULL == handle)); index++) {
+      if (debug) {
+	g_fprintf(where,
+		  "%s is trying path element %s with %s\n",
+		  __func__,
+		  path_elts[index],
+		  library_name);
+      }
+      filename = g_build_filename(path_elts[index], library_name,NULL);
+      handle = g_module_open(filename,0);
+    }
+  }
+
+  if (debug) {
+    g_fprintf(where,
+	      "%s is returning handle %p\n",
+	      __func__,
+	      handle);
+  }
+  return(handle);
+}
+
+/* attempt to open a library file, first "straight-up" and if that
+   fails, prepending various path components to it. */
+GModule *
+open_library(const gchar *library_name) {
+
+  GModule *handle;
+
+  if (debug) {
+    g_fprintf(where,
+	      "%s was asked to open a library based on the name %s\n",
+	      __func__,
+	      library_name);
+  }
+  handle = g_module_open(library_name,0);
+
+  /* so, if that didn't work, and the library_name was not an absolute
+     path, we will try to prepend some path components */
+
+  if ((NULL == handle) && 
+      !g_path_is_absolute(library_name)) {
+    handle = open_library_path(library_name,"NETPERF_LIBRARY_PATH");
+    if (NULL == handle)
+      handle = open_library_path(library_name,"LD_LIBRARY_PATH");
+    if (NULL == handle)
+      handle = open_library_path(library_name,"SHLIB_PATH");
+    if (NULL == handle)
+      handle = open_library_path(library_name,"Path");
+    if (NULL == handle)
+      handle = open_library_path(library_name,LIBDIR);
+  }
+
+  if (debug) {
+    g_fprintf(where,
+	      "%s's attempted open of library file '%s' returning %p",
+	      __func__,
+	      library_name,
+	      handle);
+    if (handle == NULL) {
+      g_fprintf(where,
+		" in failure g_module_open error '%s'\n",
+		g_module_error());
+    }
+    else {
+      g_fprintf(where,
+		" in success\n");
+    }
+  }
+  return(handle);
+}
+
 GenReport
 get_report_function(xmlNodePtr cmd)
 {



More information about the netperf-dev mailing list