Commit 064aa161 authored by stevenjb@chromium.org's avatar stevenjb@chromium.org

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
parent 3d73bce1
...@@ -64,7 +64,11 @@ typedef pthread_mutex_t* MutexHandle; ...@@ -64,7 +64,11 @@ typedef pthread_mutex_t* MutexHandle;
namespace logging { namespace logging {
DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS;
namespace {
VlogInfo* g_vlog_info = NULL; VlogInfo* g_vlog_info = NULL;
VlogInfo* g_vlog_info_prev = NULL;
const char* const log_severity_names[LOG_NUM_SEVERITIES] = { const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
"INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" }; "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" };
...@@ -350,6 +354,9 @@ bool InitializeLogFileHandle() { ...@@ -350,6 +354,9 @@ bool InitializeLogFileHandle() {
return true; return true;
} }
} // namespace
bool BaseInitLoggingImpl(const PathChar* new_log_file, bool BaseInitLoggingImpl(const PathChar* new_log_file,
LoggingDestination logging_dest, LoggingDestination logging_dest,
LogLockingState lock_log, LogLockingState lock_log,
...@@ -357,12 +364,17 @@ bool BaseInitLoggingImpl(const PathChar* new_log_file, ...@@ -357,12 +364,17 @@ bool BaseInitLoggingImpl(const PathChar* new_log_file,
DcheckState dcheck_state) { DcheckState dcheck_state) {
CommandLine* command_line = CommandLine::ForCurrentProcess(); CommandLine* command_line = CommandLine::ForCurrentProcess();
g_dcheck_state = dcheck_state; 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 // Don't bother initializing g_vlog_info unless we use one of the
// vlog switches. // vlog switches.
if (command_line->HasSwitch(switches::kV) || if (command_line->HasSwitch(switches::kV) ||
command_line->HasSwitch(switches::kVModule)) { 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 = g_vlog_info =
new VlogInfo(command_line->GetSwitchValueASCII(switches::kV), new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
command_line->GetSwitchValueASCII(switches::kVModule), command_line->GetSwitchValueASCII(switches::kVModule),
...@@ -410,8 +422,11 @@ int GetVlogVerbosity() { ...@@ -410,8 +422,11 @@ int GetVlogVerbosity() {
int GetVlogLevelHelper(const char* file, size_t N) { int GetVlogLevelHelper(const char* file, size_t N) {
DCHECK_GT(N, 0U); DCHECK_GT(N, 0U);
return g_vlog_info ? // Note: g_vlog_info may change on a different thread during startup
g_vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) : // (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(); GetVlogVerbosity();
} }
......
...@@ -210,6 +210,10 @@ BASE_EXPORT bool BaseInitLoggingImpl(const PathChar* log_file, ...@@ -210,6 +210,10 @@ BASE_EXPORT bool BaseInitLoggingImpl(const PathChar* log_file,
// The default log file is initialized to "debug.log" in the application // The default log file is initialized to "debug.log" in the application
// directory. You probably don't want this, especially since the program // directory. You probably don't want this, especially since the program
// directory may not be writable on an enduser's system. // 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, inline bool InitLogging(const PathChar* log_file,
LoggingDestination logging_dest, LoggingDestination logging_dest,
LogLockingState lock_log, LogLockingState lock_log,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment