From: Josh Stone Date: Sat, 12 Feb 2011 00:29:18 +0000 (-0800) Subject: Build the staprun command as an argument vector X-Git-Tag: release-1.5~241 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=5eea6ed171431c484ff57ed1f97308f9712e1517;p=systemtap.git Build the staprun command as an argument vector * 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. --- diff --git a/buildrun.cxx b/buildrun.cxx index 33f033294..9643539a0 100644 --- a/buildrun.cxx +++ b/buildrun.cxx @@ -463,43 +463,67 @@ uprobes_pass (systemtap_session& s) return rc; } -string +vector 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 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 make_run_command (systemtap_session& s, + const std::string& module=""); int make_tracequery(systemtap_session& s, std::string& name, const std::vector& headers); diff --git a/remote.cxx b/remote.cxx index a766d4216..23440707a 100644 --- a/remote.cxx +++ b/remote.cxx @@ -76,13 +76,7 @@ class direct : public remote { int start() { - // TODO: flip make_run_command to return a vector for us - vector 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 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; diff --git a/util.cxx b/util.cxx index 699bb4d34..2679f7a86 100644 --- a/util.cxx +++ b/util.cxx @@ -395,6 +395,21 @@ const string cmdstr_quoted(const string& cmd) } +const string +cmdstr_join(const vector& 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 7216b0027..fa5fe7426 100644 --- a/util.h +++ b/util.h @@ -25,6 +25,7 @@ void tokenize(const std::string& str, std::vector& 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& 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& args);