Bug 1382910 - Consistently treat empty env var values the same as the env var not being set. r?njn
This is what prenv.h suggests:
When manipulating the environment there is no way to un-set
an environment variable across all platforms. We suggest
you interpret the return of a pointer to null-string to
mean the same as a return of NULL from PR_GetEnv().
I interpret "null-string" to mean "empty string".
MozReview-Commit-ID: 2mfVD1zULXL
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -2191,70 +2191,71 @@ profiler_init(void* aStackTop)
RegisterProfilerLabelEnterExit(MozGlueLabelEnter, MozGlueLabelExit);
// (Linux-only) We could create CorePS::mLul and read unwind info into it
// at this point. That would match the lifetime implied by destruction of
// it in profiler_shutdown() just below. However, that gives a big delay on
// startup, even if no profiling is actually to be done. So, instead, it is
// created on demand at the first call to PlatformStart().
- if (!getenv("MOZ_PROFILER_STARTUP")) {
+ const char* startupEnv = getenv("MOZ_PROFILER_STARTUP");
+ if (!startupEnv || startupEnv[0] == '\0') {
return;
}
LOG("- MOZ_PROFILER_STARTUP is set");
const char* startupEntries = getenv("MOZ_PROFILER_STARTUP_ENTRIES");
- if (startupEntries) {
+ if (startupEntries && startupEntries[0] != '\0') {
errno = 0;
entries = strtol(startupEntries, nullptr, 10);
if (errno == 0 && entries > 0) {
LOG("- MOZ_PROFILER_STARTUP_ENTRIES = %d", entries);
} else {
PrintUsageThenExit(1);
}
}
const char* startupInterval = getenv("MOZ_PROFILER_STARTUP_INTERVAL");
- if (startupInterval) {
+ if (startupInterval && startupInterval[0] != '\0') {
errno = 0;
interval = PR_strtod(startupInterval, nullptr);
if (errno == 0 && interval > 0.0 && interval <= 1000.0) {
LOG("- MOZ_PROFILER_STARTUP_INTERVAL = %f", interval);
} else {
PrintUsageThenExit(1);
}
}
const char* startupFeaturesBitfield =
getenv("MOZ_PROFILER_STARTUP_FEATURES_BITFIELD");
- if (startupFeaturesBitfield) {
+ if (startupFeaturesBitfield && startupFeaturesBitfield[0] != '\0') {
errno = 0;
features = strtol(startupFeaturesBitfield, nullptr, 10);
if (errno == 0 && features != 0) {
LOG("- MOZ_PROFILER_STARTUP_FEATURES_BITFIELD = %d", features);
} else {
PrintUsageThenExit(1);
}
} else {
const char* startupFeatures = getenv("MOZ_PROFILER_STARTUP_FEATURES");
- if (startupFeatures) {
+ if (startupFeatures && startupFeatures[0] != '\0') {
// Interpret startupFeatures as a list of feature strings, separated by
// commas.
UniquePtr<char[]> featureStringStorage;
nsTArray<const char*> featureStringArray =
SplitAtCommas(startupFeatures, featureStringStorage);
features = ParseFeaturesFromStringArray(featureStringArray.Elements(),
featureStringArray.Length());
LOG("- MOZ_PROFILER_STARTUP_FEATURES = %d", features);
}
}
const char* startupFilters = getenv("MOZ_PROFILER_STARTUP_FILTERS");
- if (startupFilters) {
+ if (startupFilters && startupFilters[0] != '\0') {
filters = SplitAtCommas(startupFilters, filterStorage);
LOG("- MOZ_PROFILER_STARTUP_FILTERS = %s", startupFilters);
}
locked_profiler_start(lock, entries, interval, features,
filters.Elements(), filters.Length());
}