summaryrefslogtreecommitdiff
path: root/indra/llcommon/llprocess.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2012-02-20 14:22:32 -0500
committerNat Goodspeed <nat@lindenlab.com>2012-02-20 14:22:32 -0500
commit999484a60896b11df1af9a44e58ccae6fa6ecbed (patch)
tree7dc5662cf6957bbb677191c23f701bc3947c2ca2 /indra/llcommon/llprocess.cpp
parent8b5d5f9652499103b966524e1c0ceef869e29eeb (diff)
Let LLProcess consumer specify desired description for logging.
If caller runs (e.g.) a Python script, it's not very helpful to a human log reader to keep seeing LLProcess instances logged as /pathname/to/python (pid). If caller is aware, the code can at least use the script name as the desc -- or maybe even a hint as to the script's purpose. If caller doesn't explicitly pass a desc, at least shorten to just the basename of the executable.
Diffstat (limited to 'indra/llcommon/llprocess.cpp')
-rw-r--r--indra/llcommon/llprocess.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/indra/llcommon/llprocess.cpp b/indra/llcommon/llprocess.cpp
index 9799ed1938..b4c6a647d7 100644
--- a/indra/llcommon/llprocess.cpp
+++ b/indra/llcommon/llprocess.cpp
@@ -50,6 +50,7 @@
static const char* whichfile[] = { "stdin", "stdout", "stderr" };
static std::string empty;
static LLProcess::Status interpret_status(int status);
+static std::string getDesc(const LLProcess::Params& params);
/**
* Ref-counted "mainloop" listener. As long as there are still outstanding
@@ -404,7 +405,7 @@ LLProcessPtr LLProcess::create(const LLSDOrParams& params)
LLEventPumps::instance().obtain(params.postend)
.post(LLSDMap
// no "id"
- ("desc", std::string(params.executable))
+ ("desc", getDesc(params))
("state", LLProcess::UNSTARTED)
// no "data"
("string", e.what())
@@ -561,8 +562,8 @@ LLProcess::LLProcess(const LLSDOrParams& params):
sProcessListener.addPoll(*this);
mStatus.mState = RUNNING;
- mDesc = STRINGIZE(LLStringUtil::quote(params.executable) << " (" << mProcess.pid << ')');
- LL_INFOS("LLProcess") << "Launched " << params << " (" << mProcess.pid << ")" << LL_ENDL;
+ mDesc = STRINGIZE(getDesc(params) << " (" << mProcess.pid << ')');
+ LL_INFOS("LLProcess") << mDesc << ": launched " << params << LL_ENDL;
// Unless caller explicitly turned off autokill (child should persist),
// take steps to terminate the child. This is all suspenders-and-belt: in
@@ -604,6 +605,29 @@ LLProcess::LLProcess(const LLSDOrParams& params):
}
}
+// Helper to obtain a description string, given a Params block
+static std::string getDesc(const LLProcess::Params& params)
+{
+ // If caller specified a description string, by all means use it.
+ std::string desc(params.desc);
+ if (! desc.empty())
+ return desc;
+
+ // Caller didn't say. Use the executable name -- but use just the filename
+ // part. On Mac, for instance, full pathnames get cumbersome.
+ // If there are Linden utility functions to manipulate pathnames, I
+ // haven't found them -- and for this usage, Boost.Filesystem seems kind
+ // of heavyweight.
+ std::string executable(params.executable);
+ std::string::size_type delim = executable.find_last_of("\\/");
+ // If executable contains no pathname delimiters, return the whole thing.
+ if (delim == std::string::npos)
+ return executable;
+
+ // Return just the part beyond the last delimiter.
+ return executable.substr(delim + 1);
+}
+
LLProcess::~LLProcess()
{
// Only in state RUNNING are we registered for callback. In UNSTARTED we