summaryrefslogtreecommitdiff
path: root/indra/llcommon/llprocess.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2012-01-23 16:24:33 -0500
committerNat Goodspeed <nat@lindenlab.com>2012-01-23 16:24:33 -0500
commit507e136f9a25179992b2093e10ade1093cc71698 (patch)
tree53b557b7294bfefa8898a8340ce8c9d61124cd31 /indra/llcommon/llprocess.cpp
parent738483e6302af5a9ad00fa3df17efe5336a03a41 (diff)
Per Richard: close unusable Job Object; move quote() to LLStringUtil.
If LLProcess can't set the right flag on a Windows Job Object, the object isn't useful to us, so we might as well discard it. quote() is sufficiently general that it belongs in LLStringUtil instead of buried as a static helper function in llprocess.cpp.
Diffstat (limited to 'indra/llcommon/llprocess.cpp')
-rw-r--r--indra/llcommon/llprocess.cpp49
1 files changed, 13 insertions, 36 deletions
diff --git a/indra/llcommon/llprocess.cpp b/indra/llcommon/llprocess.cpp
index eb7ce4129b..2c7512419d 100644
--- a/indra/llcommon/llprocess.cpp
+++ b/indra/llcommon/llprocess.cpp
@@ -28,6 +28,7 @@
#include "llprocess.h"
#include "llsdserialize.h"
#include "llsingleton.h"
+#include "llstring.h"
#include "stringize.h"
#include <boost/foreach.hpp>
@@ -102,7 +103,6 @@ std::ostream& operator<<(std::ostream& out, const LLProcess::Params& params)
#if LL_WINDOWS
static std::string WindowsErrorString(const std::string& operation);
-static std::string quote(const std::string&);
/**
* Wrap a Windows Job Object for use in managing child-process lifespan.
@@ -157,6 +157,10 @@ private:
if (! SetInformationJobObject(mJob, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli)))
{
LL_WARNS("LLProcess") << WindowsErrorString("SetInformationJobObject()") << LL_ENDL;
+ // This Job Object is useless to us
+ CloseHandle(mJob);
+ // prevent assignProcess() from trying to use it
+ mJob = 0;
}
}
@@ -168,11 +172,17 @@ void LLProcess::launch(const LLSDParamAdapter<Params>& params)
PROCESS_INFORMATION pinfo;
STARTUPINFOA sinfo = { sizeof(sinfo) };
- std::string args = quote(params.executable);
+ // LLProcess::create()'s caller passes a Unix-style array of strings for
+ // command-line arguments. Our caller can and should expect that these will be
+ // passed to the child process as individual arguments, regardless of content
+ // (e.g. embedded spaces). But because Windows invokes any child process with
+ // a single command-line string, this means we must quote each argument behind
+ // the scenes.
+ std::string args = LLStringUtil::quote(params.executable);
BOOST_FOREACH(const std::string& arg, params.args)
{
args += " ";
- args += quote(arg);
+ args += LLStringUtil::quote(arg);
}
// So retarded. Windows requires that the second parameter to
@@ -236,39 +246,6 @@ bool LLProcess::kill(void)
return ! isRunning();
}
-/**
- * Double-quote an argument string, unless it's already double-quoted. If we
- * quote it, escape any embedded double-quote with backslash.
- *
- * LLProcess::create()'s caller passes a Unix-style array of strings for
- * command-line arguments. Our caller can and should expect that these will be
- * passed to the child process as individual arguments, regardless of content
- * (e.g. embedded spaces). But because Windows invokes any child process with
- * a single command-line string, this means we must quote each argument behind
- * the scenes.
- */
-static std::string quote(const std::string& str)
-{
- std::string::size_type len(str.length());
- // If the string is already quoted, assume user knows what s/he's doing.
- if (len >= 2 && str[0] == '"' && str[len-1] == '"')
- {
- return str;
- }
-
- // Not already quoted: do it.
- std::string result("\"");
- for (std::string::const_iterator ci(str.begin()), cend(str.end()); ci != cend; ++ci)
- {
- if (*ci == '"')
- {
- result.append("\\");
- }
- result.push_back(*ci);
- }
- return result + "\"";
-}
-
/// GetLastError()/FormatMessage() boilerplate
static std::string WindowsErrorString(const std::string& operation)
{