This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fix 12099 -- quick review?


(Re-sending using my gmail account -- the original email did not get through)

I am going to check the code in if no one has complains about the fix.

Thanks,
Rayson


diff --git a/tapsets.cxx b/tapsets.cxx
index a8970bc..46aaddc 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -56,6 +56,8 @@ extern "C" {
 #include <math.h>
 #include <regex.h>
 #include <unistd.h>
+#include <limits.h>


 #define __STDC_FORMAT_MACROS
 #include <inttypes.h>
@@ -5823,6 +5825,76 @@ dwarf_builder::build(systemtap_session & sess,
         }

       user_path = find_executable (module_name); // canonicalize it
+
+
+      // if the executable starts with "#!", we look for the
interpreter of the script
+      {
+         FILE *fp = fopen (user_path.c_str(), "r");
+
+         if (fp != NULL)
+         {
+           char buffer[PATH_MAX + 1 + 2]; // max path len + \n + #!
+
+           if (fgets (buffer, PATH_MAX + 1 + 2, fp))
+           {
+             size_t plen = strlen (buffer);
+
+             if (plen > sizeof ("#!") && memcmp (buffer, "#!", sizeof
("#!")-1) == 0)
+             {
+                // remove white spaces at the end of the string
+                plen--;
+
+                while (buffer[plen] == '\n' || buffer[plen] == ' ' ||
buffer[plen] == '\t')
+                {
+                  buffer[plen] = '\0';
+                  plen--;
+                }
+
+                // move pass #! and white spaces at the beginning of the string
+                char *path = buffer+2;
+
+                while (*path == ' ' || *path == '\t')
+                  path++;
+
+                user_path = find_executable (string (path));
+
+                struct stat st;
+
+                if (access (user_path.c_str(), X_OK) == 0
+                  && stat (user_path.c_str(), &st) == 0
+                  && S_ISREG (st.st_mode)) // see find_executable()
+                {
+
+                  if (sess.verbose > 1)
+                    clog << "Expanded process(\"" << module_name << "\") to "
+                         << "process(\"" << user_path << "\")" << endl;
+
+                  assert (location->components.size() > 0);
+                  assert (location->components[0]->functor == TOK_PROCESS);
+                  assert (location->components[0]->arg);
+                  literal_string* lit =
dynamic_cast<literal_string*>(location->components[0]->arg);
+                  assert (lit);
+
+                  // synthesize a new probe_point, with the expanded string
+                  probe_point *pp = new probe_point (*location);
+                  probe_point::component* ppc = new
probe_point::component (TOK_PROCESS,
+
      new literal_string (user_path.c_str()));
+                  ppc->tok = location->components[0]->tok; //
overwrite [0] slot, pattern matched above
+                  pp->components[0] = ppc;
+
+                  probe* new_probe = new probe (*base, pp);
+
+                  derive_probes (sess, new_probe, finished_results);
+
+                  fclose (fp);
+                  return;
+                }
+             }
+           }
+           fclose (fp);
+         }
+      }
+
       if (get_param (parameters, TOK_LIBRARY, library_name))
 	{
 	  module_name = find_executable (library_name, "LD_LIBRARY_PATH");


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]