aboutsummaryrefslogtreecommitdiff
path: root/fileutil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'fileutil.cc')
-rw-r--r--fileutil.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/fileutil.cc b/fileutil.cc
index 42e81a2..a2a0d09 100644
--- a/fileutil.cc
+++ b/fileutil.cc
@@ -32,6 +32,7 @@
#include <unordered_map>
#include "log.h"
+#include "strutil.h"
bool Exists(StringPiece filename) {
CHECK(filename.size() < PATH_MAX);
@@ -62,6 +63,13 @@ double GetTimestamp(StringPiece filename) {
int RunCommand(const string& shell, const string& cmd,
RedirectStderr redirect_stderr,
string* s) {
+ string cmd_escaped = cmd;
+ EscapeShell(&cmd_escaped);
+ string cmd_with_shell = shell + " -c \"" + cmd_escaped + "\"";
+ const char* argv[] = {
+ "/bin/sh", "-c", cmd_with_shell.c_str(), NULL
+ };
+
int pipefd[2];
if (pipe(pipefd) != 0)
PERROR("pipe failed");
@@ -106,9 +114,6 @@ int RunCommand(const string& shell, const string& cmd,
PERROR("dup2 failed");
close(pipefd[1]);
- const char* argv[] = {
- shell.c_str(), "-c", cmd.c_str(), NULL
- };
execvp(argv[0], const_cast<char**>(argv));
PLOG("execvp for %s failed", argv[0]);
kill(getppid(), SIGTERM);