summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-03 00:30:08 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-03 00:30:08 +0000
commit064aa1618863d6d4d015b0b862b37483d26dbe9f (patch)
tree0bd2866009cf5bc820c10f248709ff1e0392ddf6 /base
parent3d73bce15bd0465842fa79a3e6c5c66219a8d38d (diff)
downloadchromium_src-064aa1618863d6d4d015b0b862b37483d26dbe9f.zip
chromium_src-064aa1618863d6d4d015b0b862b37483d26dbe9f.tar.gz
chromium_src-064aa1618863d6d4d015b0b862b37483d26dbe9f.tar.bz2
Don't delete g_vlog_info
Fixes a race on startup. See issue for details. BUG=chromium-os:20865 TEST=Ensure logging, including VLOG, works. TBR=willchen@chromium.org Review URL: http://codereview.chromium.org/8757002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112828 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/logging.cc23
-rw-r--r--base/logging.h4
2 files changed, 23 insertions, 4 deletions
diff --git a/base/logging.cc b/base/logging.cc
index 27754af..149bdda 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -64,7 +64,11 @@ typedef pthread_mutex_t* MutexHandle;
namespace logging {
DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS;
+
+namespace {
+
VlogInfo* g_vlog_info = NULL;
+VlogInfo* g_vlog_info_prev = NULL;
const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
"INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" };
@@ -350,6 +354,9 @@ bool InitializeLogFileHandle() {
return true;
}
+} // namespace
+
+
bool BaseInitLoggingImpl(const PathChar* new_log_file,
LoggingDestination logging_dest,
LogLockingState lock_log,
@@ -357,12 +364,17 @@ bool BaseInitLoggingImpl(const PathChar* new_log_file,
DcheckState dcheck_state) {
CommandLine* command_line = CommandLine::ForCurrentProcess();
g_dcheck_state = dcheck_state;
- delete g_vlog_info;
- g_vlog_info = NULL;
+
// Don't bother initializing g_vlog_info unless we use one of the
// vlog switches.
if (command_line->HasSwitch(switches::kV) ||
command_line->HasSwitch(switches::kVModule)) {
+ // NOTE: If g_vlog_info has already been initialized, it might be in use
+ // by another thread. Don't delete the old VLogInfo, just create a second
+ // one. We keep track of both to avoid memory leak warnings.
+ CHECK(!g_vlog_info_prev);
+ g_vlog_info_prev = g_vlog_info;
+
g_vlog_info =
new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
command_line->GetSwitchValueASCII(switches::kVModule),
@@ -410,8 +422,11 @@ int GetVlogVerbosity() {
int GetVlogLevelHelper(const char* file, size_t N) {
DCHECK_GT(N, 0U);
- return g_vlog_info ?
- g_vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) :
+ // Note: g_vlog_info may change on a different thread during startup
+ // (but will always be valid or NULL).
+ VlogInfo* vlog_info = g_vlog_info;
+ return vlog_info ?
+ vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) :
GetVlogVerbosity();
}
diff --git a/base/logging.h b/base/logging.h
index ae67eac..94a82ad 100644
--- a/base/logging.h
+++ b/base/logging.h
@@ -210,6 +210,10 @@ BASE_EXPORT bool BaseInitLoggingImpl(const PathChar* log_file,
// The default log file is initialized to "debug.log" in the application
// directory. You probably don't want this, especially since the program
// directory may not be writable on an enduser's system.
+//
+// This function may be called a second time to re-direct logging (e.g after
+// loging in to a user partition), however it should never be called more than
+// twice.
inline bool InitLogging(const PathChar* log_file,
LoggingDestination logging_dest,
LogLockingState lock_log,