Bug 1390736 - Add RUST_LOG_CHILD for child-only logging. r=froydnj
For certain use cases, it's nice to be able to target Rust debug logging to only
child processes (so you focus on web content vs. chrome running in the parent).
This adds `RUST_LOG_CHILD` which is copied to `RUST_LOG` when launching child
processes.
MozReview-Commit-ID: BWAZ4f51AW
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -569,56 +569,69 @@ GeckoChildProcessHost::SetChildLogName(c
PR_SetEnv(buffer.BeginReading());
}
bool
GeckoChildProcessHost::PerformAsyncLaunch(std::vector<std::string> aExtraOpts, base::ProcessArchitecture arch)
{
AutoSetProfilerEnvVarsForChildProcess profilerEnvironment;
- // If NSPR log files are not requested, we're done.
const char* origNSPRLogName = PR_GetEnv("NSPR_LOG_FILE");
const char* origMozLogName = PR_GetEnv("MOZ_LOG_FILE");
- if (!origNSPRLogName && !origMozLogName) {
- return PerformAsyncLaunchInternal(aExtraOpts, arch);
- }
+ const char* origRustLog = PR_GetEnv("RUST_LOG");
+ const char* childRustLog = PR_GetEnv("RUST_LOG_CHILD");
// - Note: this code is not called re-entrantly, nor are restoreOrig*LogName
// or mChildCounter touched by any other thread, so this is safe.
++mChildCounter;
// Must keep these on the same stack where from we call PerformAsyncLaunchInternal
// so that PR_DuplicateEnvironment() still sees a valid memory.
nsAutoCString nsprLogName;
nsAutoCString mozLogName;
+ nsAutoCString rustLog;
if (origNSPRLogName) {
if (mRestoreOrigNSPRLogName.IsEmpty()) {
mRestoreOrigNSPRLogName.AssignLiteral("NSPR_LOG_FILE=");
mRestoreOrigNSPRLogName.Append(origNSPRLogName);
}
SetChildLogName("NSPR_LOG_FILE=", origNSPRLogName, nsprLogName);
}
if (origMozLogName) {
if (mRestoreOrigMozLogName.IsEmpty()) {
mRestoreOrigMozLogName.AssignLiteral("MOZ_LOG_FILE=");
mRestoreOrigMozLogName.Append(origMozLogName);
}
SetChildLogName("MOZ_LOG_FILE=", origMozLogName, mozLogName);
}
+ // `RUST_LOG_CHILD` is meant for logging child processes only.
+ if (childRustLog) {
+ if (mRestoreOrigRustLog.IsEmpty()) {
+ mRestoreOrigRustLog.AssignLiteral("RUST_LOG=");
+ mRestoreOrigRustLog.Append(origRustLog);
+ }
+ rustLog.AssignLiteral("RUST_LOG=");
+ rustLog.Append(childRustLog);
+ PR_SetEnv(rustLog.get());
+ }
+
bool retval = PerformAsyncLaunchInternal(aExtraOpts, arch);
// Revert to original value
if (origNSPRLogName) {
PR_SetEnv(mRestoreOrigNSPRLogName.get());
}
if (origMozLogName) {
PR_SetEnv(mRestoreOrigMozLogName.get());
}
+ if (origRustLog) {
+ PR_SetEnv(mRestoreOrigRustLog.get());
+ }
return retval;
}
bool
GeckoChildProcessHost::RunPerformAsyncLaunch(std::vector<std::string> aExtraOpts,
base::ProcessArchitecture aArch)
{
--- a/ipc/glue/GeckoChildProcessHost.h
+++ b/ipc/glue/GeckoChildProcessHost.h
@@ -204,16 +204,17 @@ private:
// FIXME/cjones: this strongly indicates bad design. Shame on us.
std::queue<IPC::Message> mQueue;
// Remember original env values so we can restore it (there is no other
// simple way how to change environment of a child process than to modify
// the current environment).
nsCString mRestoreOrigNSPRLogName;
nsCString mRestoreOrigMozLogName;
+ nsCString mRestoreOrigRustLog;
static uint32_t sNextUniqueID;
static bool sRunSelfAsContentProc;
#if defined(MOZ_WIDGET_ANDROID)
void LaunchAndroidService(const char* type,
const std::vector<std::string>& argv,