]> sourceware.org Git - systemtap.git/commitdiff
Build the staprun command as an argument vector
authorJosh Stone <jistone@redhat.com>
Sat, 12 Feb 2011 00:29:18 +0000 (16:29 -0800)
committerJosh Stone <jistone@redhat.com>
Sat, 12 Feb 2011 00:29:18 +0000 (16:29 -0800)
* buildrun.cxx (make_run_command): Build the command as a vector.
* util.cxx (cmdstr_join): New, join a vector as quoted strings.
* remote.cxx (direct::start): Use make_run_command directly.
  (ssh_remote::start): Pass cmdstr_join(make_run_command(...)) to
  ssh, so all args survive intact to the remote side.

buildrun.cxx
buildrun.h
remote.cxx
util.cxx
util.h

index 33f033294c570d85f6a6975d04a13c0501a332e6..9643539a0d434d69c6381a6ef863ad048f662800 100644 (file)
@@ -463,43 +463,67 @@ uprobes_pass (systemtap_session& s)
   return rc;
 }
 
-string
+vector<string>
 make_run_command (systemtap_session& s, const string& module)
 {
   // for now, just spawn staprun
-  string staprun_cmd = string(getenv("SYSTEMTAP_STAPRUN") ?: BINDIR "/staprun")
-    + " "
-    + (s.verbose>1 ? "-v " : "")
-    + (s.verbose>2 ? "-v " : "")
-    + (s.suppress_warnings ? "-w " : "")
-    + (s.output_file.empty() ? "" : "-o " + s.output_file + " ");
+  vector<string> staprun_cmd;
+  staprun_cmd.push_back(getenv("SYSTEMTAP_STAPRUN") ?: BINDIR "/staprun");
+  if (s.verbose>1)
+    staprun_cmd.push_back("-v");
+  if (s.verbose>2)
+    staprun_cmd.push_back("-v");
+  if (s.suppress_warnings)
+    staprun_cmd.push_back("-w");
+
+  if (!s.output_file.empty())
+    {
+      staprun_cmd.push_back("-o");
+      staprun_cmd.push_back(s.output_file);
+    }
 
-  if (s.cmd != "")
-    staprun_cmd += "-c " + cmdstr_quoted(s.cmd) + " ";
+  if (!s.cmd.empty())
+    {
+      staprun_cmd.push_back("-c");
+      staprun_cmd.push_back(s.cmd);
+    }
 
   if (s.target_pid)
-    staprun_cmd += "-t " + lex_cast(s.target_pid) + " ";
+    {
+      staprun_cmd.push_back("-t");
+      staprun_cmd.push_back(lex_cast(s.target_pid));
+    }
 
   if (s.buffer_size)
-    staprun_cmd += "-b " + lex_cast(s.buffer_size) + " ";
+    {
+      staprun_cmd.push_back("-b");
+      staprun_cmd.push_back(lex_cast(s.buffer_size));
+    }
 
   if (s.need_uprobes)
-    staprun_cmd += "-u" + s.uprobes_path + " ";
+    {
+      staprun_cmd.push_back("-u");
+      if (!s.uprobes_path.empty())
+        staprun_cmd.push_back(s.uprobes_path);
+    }
 
   if (s.load_only)
-    staprun_cmd += (s.output_file.empty() ? "-L " : "-D ");
+    staprun_cmd.push_back(s.output_file.empty() ? "-L" : "-D");
 
   if (!s.size_option.empty())
-    staprun_cmd += "-S " + s.size_option + " ";
+    {
+      staprun_cmd.push_back("-S");
+      staprun_cmd.push_back(s.size_option);
+    }
 
   if (module.empty())
-    staprun_cmd += s.tmpdir + "/" + s.module_name + ".ko";
+    staprun_cmd.push_back(s.tmpdir + "/" + s.module_name + ".ko");
   else
-    staprun_cmd += module;
+    staprun_cmd.push_back(module);
 
   // add module arguments
-  for (unsigned i=0; i<s.globalopts.size(); i++)
-    staprun_cmd += " " + s.globalopts[i];
+  staprun_cmd.insert(staprun_cmd.end(),
+                     s.globalopts.begin(), s.globalopts.end());
 
   return staprun_cmd;
 }
index 4f950dd7289b3943598c703471bca44a3d7325e6..4a2f828d5c588cf3bc25453150c07b958d7a2d43 100644 (file)
@@ -12,8 +12,8 @@
 #include "elaborate.h"
 
 int compile_pass (systemtap_session& s);
-std::string make_run_command (systemtap_session& s,
-                              const std::string& module="");
+std::vector<std::string> make_run_command (systemtap_session& s,
+                                           const std::string& module="");
 
 int make_tracequery(systemtap_session& s, std::string& name,
                     const std::vector<std::string>& headers);
index a766d4216fd49b2c349cbcd0667a8c78c34085c6..23440707af06563b45559fea1d0ca008827d645b 100644 (file)
@@ -76,13 +76,7 @@ class direct : public remote {
 
     int start()
       {
-        // TODO: flip make_run_command to return a vector for us
-        vector<string> cmd;
-        cmd.push_back("/bin/sh");
-        cmd.push_back("-c");
-        cmd.push_back(make_run_command (*s));
-
-        pid_t pid = stap_spawn (s->verbose, cmd);
+        pid_t pid = stap_spawn (s->verbose, make_run_command (*s));
         if (pid <= 0)
           return 1;
         child = pid;
@@ -271,7 +265,7 @@ class ssh_remote : public remote {
         if (rc == 0) {
           vector<string> cmd = ssh_args;
           cmd.push_back("-t");
-          cmd.push_back(make_run_command(*s, tmpmodule));
+          cmd.push_back(cmdstr_join(make_run_command(*s, tmpmodule)));
           pid_t pid = stap_spawn(s->verbose, cmd);
           if (pid > 0)
             child = pid;
index 699bb4d346a631771e5ad48be93b9ef9320ddc6b..2679f7a86dae9621c34a6c8239f3dfed7eb72d48 100644 (file)
--- a/util.cxx
+++ b/util.cxx
@@ -395,6 +395,21 @@ const string cmdstr_quoted(const string& cmd)
 }
 
 
+const string
+cmdstr_join(const vector<string>& cmds)
+{
+  if (cmds.empty())
+    throw runtime_error("cmdstr_join called with an empty command!");
+
+  stringstream cmd;
+  cmd << cmdstr_quoted(cmds[0]);
+  for (size_t i = 1; i < cmds.size(); ++i)
+    cmd << " " << cmdstr_quoted(cmds[i]);
+
+  return cmd.str();
+}
+
+
 string
 git_revision(const string& path)
 {
diff --git a/util.h b/util.h
index 7216b00279d7bd2e6c7fe5a9472e079c7bf686e3..fa5fe7426f244e5e9580d04fd5b9d25b6729990a 100644 (file)
--- a/util.h
+++ b/util.h
@@ -25,6 +25,7 @@ void tokenize(const std::string& str, std::vector<std::string>& tokens,
 std::string find_executable(const std::string& name,
                            const std::string& env_path = "PATH");
 const std::string cmdstr_quoted(const std::string& cmd);
+const std::string cmdstr_join(const std::vector<std::string>& cmds);
 std::string git_revision(const std::string& path);
 int stap_waitpid(int verbose, pid_t pid);
 pid_t stap_spawn(int verbose, const std::vector<std::string>& args);
This page took 0.038096 seconds and 5 git commands to generate.