]> sourceware.org Git - systemtap.git/commitdiff
2007-08-20 Martin Hunt <hunt@redhat.com>
authorhunt <hunt>
Mon, 20 Aug 2007 17:55:03 +0000 (17:55 +0000)
committerhunt <hunt>
Mon, 20 Aug 2007 17:55:03 +0000 (17:55 +0000)
PR2424
From Lai Jiangshan <laijs@cn.fujitsu.com>

* util.cxx (cmdstr_quoted): New. Properly quote
command string.
* buildrun.cxx (run_pass): Call cmdstr_quoted().

ChangeLog
buildrun.cxx
util.cxx
util.h

index 6362979175829e0662415a3ea7e861be1745e819..462c1f4247d985af88503a589a233330370f62e5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-08-20  Martin Hunt  <hunt@redhat.com>
+       PR2424
+       From Lai Jiangshan <laijs@cn.fujitsu.com>
+       
+       * util.cxx (cmdstr_quoted): New. Properly quote 
+       command string.
+       * buildrun.cxx (run_pass): Call cmdstr_quoted().
+
 2007-08-20  Frank Ch. Eigler  <fche@elastic.org>
 
        From Satoru MORIYA <satoru.moriya.br@hitachi.com>
index 221d04631fc4ae430201a142186079ddb4793857..2fb3439caad4801f386adbac3eb9c3436b4920c7 100644 (file)
@@ -139,7 +139,7 @@ run_pass (systemtap_session& s)
   staprun_cmd += "-d " + stringify(getpid()) + " ";
   
   if (s.cmd != "")
-    staprun_cmd += "-c \"" + s.cmd + "\" ";
+    staprun_cmd += "-c " + cmdstr_quoted(s.cmd) + " ";
   
   if (s.target_pid)
     staprun_cmd += "-t " + stringify(s.target_pid) + " ";
index af9533957bcfde387b9a5b90be51de8cf8a4cab6..97425d763dd8a8768c35eac4d1f53e01d405609f 100644 (file)
--- a/util.cxx
+++ b/util.cxx
@@ -197,3 +197,34 @@ find_executable(const char *name, string& retpath)
 
   return false;
 }
+
+const string cmdstr_quoted(const string& cmd)
+{
+       // original cmd : substr1
+       //           or : substr1'substr2
+       //           or : substr1'substr2'substr3......
+       // after quoted :
+       // every substr(even it's empty) is quoted by ''
+       // every single-quote(') is quoted by ""
+       // examples: substr1 --> 'substr1'
+       //           substr1'substr2 --> 'substr1'"'"'substr2'
+
+       string quoted_cmd;
+       string quote("'");
+       string replace("'\"'\"'");
+       string::size_type pos = 0;
+
+       quoted_cmd += quote;
+       for (string::size_type quote_pos = cmd.find(quote, pos); 
+                       quote_pos != string::npos; 
+                       quote_pos = cmd.find(quote, pos)) {
+               quoted_cmd += cmd.substr(pos, quote_pos - pos);
+               quoted_cmd += replace;
+               pos = quote_pos + 1;
+       }
+       quoted_cmd += cmd.substr(pos, cmd.length() - pos);
+       quoted_cmd += quote;
+
+       return quoted_cmd;
+}
+
diff --git a/util.h b/util.h
index f9c298ec85a57c41ca2b9237705dc943fe463f60..97fa7062d9970c778633cd0458d75d236fb1910c 100644 (file)
--- a/util.h
+++ b/util.h
@@ -11,6 +11,7 @@ int create_dir(const char *dir);
 void tokenize(const std::string& str, std::vector<std::string>& tokens,
              const std::string& delimiters);
 bool find_executable(const char *name, std::string& retpath);
+const std::string cmdstr_quoted(const std::string& cmd);
 
 
 // stringification generics
This page took 0.036338 seconds and 5 git commands to generate.