From d6c48c60effb382f6e376de641fc5e9ac5338119 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 8 Mar 2016 09:42:59 +0800 Subject: [PATCH] Fix renderdoccmd -c on Linux * argv[0] should always be set up * log an error when execve fails * logfile is always NULL and constructing a std::string from NULL throws * really apply EnvironmentModification --- renderdoc/os/linux/linux_process.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/renderdoc/os/linux/linux_process.cpp b/renderdoc/os/linux/linux_process.cpp index 5e0a95b72..bfda3e320 100644 --- a/renderdoc/os/linux/linux_process.cpp +++ b/renderdoc/os/linux/linux_process.cpp @@ -83,8 +83,8 @@ static pid_t RunProcess(const char *app, const char *workingDir, const char *cmd { if(!app) return (pid_t)0; - int argc = 0; - char *emptyargv[] = { NULL }; + // it is safe to use app directly as execve never modifies argv + char *emptyargv[] = { (char *) app, NULL }; char **argv = emptyargv; const char *c = cmdLine; @@ -92,7 +92,7 @@ static pid_t RunProcess(const char *app, const char *workingDir, const char *cmd // parse command line into argv[], similar to how bash would if(cmdLine) { - argc = 1; + int argc = 1; // get a rough upper bound on the number of arguments while(*c) @@ -212,6 +212,7 @@ static pid_t RunProcess(const char *app, const char *workingDir, const char *cmd } execve(app, argv, envp); + RDCERR("Failed to execute %s: %s", app, strerror(errno)); exit(0); } @@ -261,6 +262,9 @@ uint32_t Process::LaunchAndInjectIntoProcess(const char *app, const char *workin map env = EnvStringToEnvMap((const char **)environ); vector &modifications = GetEnvModifications(); + if (logfile == NULL) + logfile = ""; + string libpath; { FileIO::GetExecutableFilename(libpath); @@ -287,7 +291,7 @@ uint32_t Process::LaunchAndInjectIntoProcess(const char *app, const char *workin { EnvironmentModification &m = modifications[i]; - string value = env[m.name]; + string &value = env[m.name]; switch(m.type) {