Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: base/nss_util.cc

Issue 6185005: NSS: don't set environment variables when multi-threaded. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/nss_util.h ('k') | chrome/app/chrome_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/nss_util.h" 5 #include "base/nss_util.h"
6 #include "base/nss_util_internal.h" 6 #include "base/nss_util_internal.h"
7 7
8 #include <nss.h> 8 #include <nss.h>
9 #include <plarena.h> 9 #include <plarena.h>
10 #include <prerror.h> 10 #include <prerror.h>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 // NSS creates a local cache of the sqlite database if it detects that the 93 // NSS creates a local cache of the sqlite database if it detects that the
94 // filesystem the database is on is much slower than the local disk. The 94 // filesystem the database is on is much slower than the local disk. The
95 // detection doesn't work with the latest versions of sqlite, such as 3.6.22 95 // detection doesn't work with the latest versions of sqlite, such as 3.6.22
96 // (NSS bug https://bugzilla.mozilla.org/show_bug.cgi?id=578561). So we set 96 // (NSS bug https://bugzilla.mozilla.org/show_bug.cgi?id=578561). So we set
97 // the NSS environment variable NSS_SDB_USE_CACHE to "yes" to override NSS's 97 // the NSS environment variable NSS_SDB_USE_CACHE to "yes" to override NSS's
98 // detection when database_dir is on NFS. See http://crbug.com/48585. 98 // detection when database_dir is on NFS. See http://crbug.com/48585.
99 // 99 //
100 // TODO(wtc): port this function to other USE_NSS platforms. It is defined 100 // TODO(wtc): port this function to other USE_NSS platforms. It is defined
101 // only for OS_LINUX simply because the statfs structure is OS-specific. 101 // only for OS_LINUX simply because the statfs structure is OS-specific.
102 //
103 // Because this function sets an environment variable it must be run before we
104 // go multi-threaded.
102 void UseLocalCacheOfNSSDatabaseIfNFS(const FilePath& database_dir) { 105 void UseLocalCacheOfNSSDatabaseIfNFS(const FilePath& database_dir) {
103 #if defined(OS_LINUX) 106 #if defined(OS_LINUX)
104 struct statfs buf; 107 struct statfs buf;
105 if (statfs(database_dir.value().c_str(), &buf) == 0) { 108 if (statfs(database_dir.value().c_str(), &buf) == 0) {
106 if (buf.f_type == NFS_SUPER_MAGIC) { 109 if (buf.f_type == NFS_SUPER_MAGIC) {
107 scoped_ptr<Environment> env(Environment::Create()); 110 scoped_ptr<Environment> env(Environment::Create());
108 const char* use_cache_env_var = "NSS_SDB_USE_CACHE"; 111 const char* use_cache_env_var = "NSS_SDB_USE_CACHE";
109 if (!env->HasVar(use_cache_env_var)) 112 if (!env->HasVar(use_cache_env_var))
110 env->SetVar(use_cache_env_var, "yes"); 113 env->SetVar(use_cache_env_var, "yes");
111 } 114 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 #if !defined(USE_NSS) 236 #if !defined(USE_NSS)
234 // Use the system certificate store, so initialize NSS without database. 237 // Use the system certificate store, so initialize NSS without database.
235 status = NSS_NoDB_Init(NULL); 238 status = NSS_NoDB_Init(NULL);
236 if (status != SECSuccess) { 239 if (status != SECSuccess) {
237 LOG(ERROR) << "Error initializing NSS without a persistent " 240 LOG(ERROR) << "Error initializing NSS without a persistent "
238 "database: NSS error code " << PR_GetError(); 241 "database: NSS error code " << PR_GetError();
239 } 242 }
240 #else 243 #else
241 FilePath database_dir = GetInitialConfigDirectory(); 244 FilePath database_dir = GetInitialConfigDirectory();
242 if (!database_dir.empty()) { 245 if (!database_dir.empty()) {
246 // This duplicates the work which should have been done in
247 // EarlySetupForNSSInit. However, this function is idempotent so there's
248 // no harm done.
243 UseLocalCacheOfNSSDatabaseIfNFS(database_dir); 249 UseLocalCacheOfNSSDatabaseIfNFS(database_dir);
244 250
245 // Initialize with a persistent database (likely, ~/.pki/nssdb). 251 // Initialize with a persistent database (likely, ~/.pki/nssdb).
246 // Use "sql:" which can be shared by multiple processes safely. 252 // Use "sql:" which can be shared by multiple processes safely.
247 std::string nss_config_dir = 253 std::string nss_config_dir =
248 StringPrintf("sql:%s", database_dir.value().c_str()); 254 StringPrintf("sql:%s", database_dir.value().c_str());
249 #if defined(OS_CHROMEOS) 255 #if defined(OS_CHROMEOS)
250 status = NSS_Init(nss_config_dir.c_str()); 256 status = NSS_Init(nss_config_dir.c_str());
251 #else 257 #else
252 status = NSS_InitReadWrite(nss_config_dir.c_str()); 258 status = NSS_InitReadWrite(nss_config_dir.c_str());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // is fixed, we will no longer need the lock. 343 // is fixed, we will no longer need the lock.
338 Lock write_lock_; 344 Lock write_lock_;
339 #endif // defined(USE_NSS) 345 #endif // defined(USE_NSS)
340 }; 346 };
341 347
342 LazyInstance<NSSInitSingleton, LeakyLazyInstanceTraits<NSSInitSingleton> > 348 LazyInstance<NSSInitSingleton, LeakyLazyInstanceTraits<NSSInitSingleton> >
343 g_nss_singleton(LINKER_INITIALIZED); 349 g_nss_singleton(LINKER_INITIALIZED);
344 350
345 } // namespace 351 } // namespace
346 352
353 #if defined(USE_NSS)
354 void EarlySetupForNSSInit() {
355 FilePath database_dir = GetInitialConfigDirectory();
356 if (!database_dir.empty())
357 UseLocalCacheOfNSSDatabaseIfNFS(database_dir);
358 }
359 #endif
360
347 void EnsureNSPRInit() { 361 void EnsureNSPRInit() {
348 g_nspr_singleton.Get(); 362 g_nspr_singleton.Get();
349 } 363 }
350 364
351 void EnsureNSSInit() { 365 void EnsureNSSInit() {
352 // Initializing SSL causes us to do blocking IO. 366 // Initializing SSL causes us to do blocking IO.
353 // Temporarily allow it until we fix 367 // Temporarily allow it until we fix
354 // http://code.google.com/p/chromium/issues/detail?id=59847 368 // http://code.google.com/p/chromium/issues/detail?id=59847
355 ThreadRestrictions::ScopedAllowIO allow_io; 369 ThreadRestrictions::ScopedAllowIO allow_io;
356 g_nss_singleton.Get(); 370 g_nss_singleton.Get();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 exploded.millisecond = prxtime.tm_usec / 1000; 424 exploded.millisecond = prxtime.tm_usec / 1000;
411 425
412 return Time::FromUTCExploded(exploded); 426 return Time::FromUTCExploded(exploded);
413 } 427 }
414 428
415 PK11SlotInfo* GetDefaultNSSKeySlot() { 429 PK11SlotInfo* GetDefaultNSSKeySlot() {
416 return g_nss_singleton.Get().GetDefaultKeySlot(); 430 return g_nss_singleton.Get().GetDefaultKeySlot();
417 } 431 }
418 432
419 } // namespace base 433 } // namespace base
OLDNEW
« no previous file with comments | « base/nss_util.h ('k') | chrome/app/chrome_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698