Blob Blame History Raw
commit 438b5a402b6a93dd426f8c18de6fe3708c265328
Author: Stan Cox <scox@redhat.com>
Date:   Tue Mar 28 14:39:14 2017 -0400

    Adapt stapdyn to the dyninst 9.3.1 library search model.
    
    stapdyn/dynutil.cxx (check_dyninst_rt): Use DYNINST_REWRITER_PATHS
    and appendenv
    
    util.c, util.h:  New: appendenv.

diff --git a/stapdyn/dynutil.cxx b/stapdyn/dynutil.cxx
index cd2ae11..47a1e91 100644
--- a/stapdyn/dynutil.cxx
+++ b/stapdyn/dynutil.cxx
@@ -61,17 +61,28 @@ guess_dyninst_rt(void)
   return libdyninstAPI_RT;
 }
 
+
 // Check that environment DYNINSTAPI_RT_LIB exists and is a valid file.
 // If not, try to guess a good value and set it.
 bool
 check_dyninst_rt(void)
 {
   static const char rt_env_name[] = "DYNINSTAPI_RT_LIB";
-  const char* rt_env = getenv(rt_env_name);
+  static const char dyn_rw_env_name[] = "DYNINST_REWRITER_PATHS";
+
+  char* rt_env = getenv(rt_env_name);
   if (rt_env)
     {
       if (file_exists(rt_env))
-        return true;
+	{
+	  if (appendenv(dyn_rw_env_name, rt_env) != 0)
+	    {
+	      int olderrno = errno;
+	      staperror() << "Can't set " << dyn_rw_env_name << ": " << strerror(olderrno);
+	      return false;
+	    }
+	  return true;
+	}
       staperror() << "Invalid " << rt_env_name << ": \"" << rt_env << "\"" << endl;
     }
 
@@ -82,7 +93,7 @@ check_dyninst_rt(void)
       return false;
     }
 
-  if (setenv(rt_env_name, rt.c_str(), 1) != 0)
+  if (appendenv(dyn_rw_env_name, rt) != 0)
     {
       int olderrno = errno;
       staperror() << "Can't set " << rt_env_name << ": " << strerror(olderrno);
diff --git a/util.cxx b/util.cxx
index a1c8363..9157fb9 100644
--- a/util.cxx
+++ b/util.cxx
@@ -228,6 +228,23 @@ remove_file_or_dir (const char *name)
   return 0;
 }
 
+
+int
+appendenv (const char *env_name, const string source)
+{
+  string dirname = source.substr(0, source.rfind("/"));
+  char *env = getenv(env_name);
+  string new_env;
+  
+  if (env)
+    new_env = string (env) + ":" + dirname;
+  else
+    new_env = dirname;
+    
+  return setenv(env_name, new_env.c_str(), 1);
+}
+
+
 /* Obtain the gid of the given group. */
 gid_t get_gid (const char *group_name)
 {
diff --git a/util.h b/util.h
index d7e0cfb..482f719 100644
--- a/util.h
+++ b/util.h
@@ -77,6 +77,7 @@ bool copy_file(const std::string& src, const std::string& dest,
 int create_dir(const char *dir, int mode = 0777);
 int remove_file_or_dir(const char *dir);
 extern "C" gid_t get_gid (const char *group_name);
+int appendenv (const char *env_name, const std::string source);
 bool in_group_id (gid_t target_gid);
 std::string getmemusage ();
 void tokenize(const std::string& str, std::vector<std::string>& tokens,