summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 18:27:40 +0000
committertschmelcher@chromium.org <tschmelcher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 18:27:40 +0000
commit57b765671983005059e8be4523872796b9505428 (patch)
treec84b82b586cae2b39ef784f1ee1d58c1431bb140 /base
parentfd8d08436730ef67591de7665da88e995159b773 (diff)
downloadchromium_src-57b765671983005059e8be4523872796b9505428.zip
chromium_src-57b765671983005059e8be4523872796b9505428.tar.gz
chromium_src-57b765671983005059e8be4523872796b9505428.tar.bz2
Eliminate all uses of strerror() in code that uses src/base. strerror() is inherently unsafe in multi-threaded apps because it stores the string in a global buffer. It should never be used. If you want to log an error, use PLOG and friends, or if that's too high-level then use safe_strerror().
TEST=built on Linux in 32-bit and 64-bit mode; ran base_unittests in each case; ran Chromium itself in each case; try servers BUG=none Review URL: http://codereview.chromium.org/261055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/data_pack.cc3
-rw-r--r--base/debug_util_posix.cc3
-rw-r--r--base/directory_watcher_inotify.cc6
-rw-r--r--base/file_util_posix.cc7
-rw-r--r--base/process_util_linux.cc2
-rw-r--r--base/process_util_posix.cc5
-rw-r--r--base/shared_memory_posix.cc6
-rw-r--r--base/stats_table.cc8
8 files changed, 16 insertions, 24 deletions
diff --git a/base/data_pack.cc b/base/data_pack.cc
index 051fb4e..46f3cb4 100644
--- a/base/data_pack.cc
+++ b/base/data_pack.cc
@@ -50,8 +50,7 @@ DataPack::~DataPack() {
bool DataPack::Load(const FilePath& path) {
mmap_.reset(new file_util::MemoryMappedFile);
if (!mmap_->Initialize(path)) {
- CHECK(false) << "Failed to mmap " << path.value() << " errno: " <<
- strerror(errno);
+ PCHECK(false) << "Failed to mmap " << path.value();
}
// Parse the header of the file.
diff --git a/base/debug_util_posix.cc b/base/debug_util_posix.cc
index dc86c8c..4b79d73 100644
--- a/base/debug_util_posix.cc
+++ b/base/debug_util_posix.cc
@@ -21,6 +21,7 @@
#include "base/compat_execinfo.h"
#include "base/eintr_wrapper.h"
#include "base/logging.h"
+#include "base/safe_strerror_posix.h"
#include "base/scoped_ptr.h"
#include "base/string_piece.h"
@@ -150,7 +151,7 @@ void StackTrace::OutputToStream(std::ostream* os) {
// If we can't retrieve the symbols, print an error and just dump the raw
// addresses.
if (trace_symbols.get() == NULL) {
- (*os) << "Unable get symbols for backtrace (" << strerror(errno)
+ (*os) << "Unable get symbols for backtrace (" << safe_strerror(errno)
<< "). Dumping raw addresses in trace:\n";
for (int i = 0; i < count_; ++i) {
(*os) << "\t" << trace_[i] << "\n";
diff --git a/base/directory_watcher_inotify.cc b/base/directory_watcher_inotify.cc
index 44e4dcb..d171a7a 100644
--- a/base/directory_watcher_inotify.cc
+++ b/base/directory_watcher_inotify.cc
@@ -209,7 +209,7 @@ class InotifyReaderTask : public Task {
HANDLE_EINTR(select(std::max(inotify_fd_, shutdown_fd_) + 1,
&rfds, NULL, NULL, NULL));
if (select_result < 0) {
- DLOG(WARNING) << "select failed: " << strerror(errno);
+ DPLOG(WARNING) << "select failed";
return;
}
@@ -222,7 +222,7 @@ class InotifyReaderTask : public Task {
&buffer_size));
if (ioctl_result != 0) {
- DLOG(WARNING) << "ioctl failed: " << strerror(errno);
+ DPLOG(WARNING) << "ioctl failed";
return;
}
@@ -232,7 +232,7 @@ class InotifyReaderTask : public Task {
buffer_size));
if (bytes_read < 0) {
- DLOG(WARNING) << "read from inotify fd failed: " << strerror(errno);
+ DPLOG(WARNING) << "read from inotify fd failed";
return;
}
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 4d9e797..3ba351e 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -99,7 +99,7 @@ int CountFilesCreatedAfter(const FilePath& path,
stat_wrapper_t st;
int test = CallStat(path.Append(ent->d_name).value().c_str(), &st);
if (test != 0) {
- LOG(ERROR) << "stat64 failed: " << strerror(errno);
+ PLOG(ERROR) << "stat64 failed";
continue;
}
// Here, we use Time::TimeT(), which discards microseconds. This
@@ -634,9 +634,8 @@ bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries,
// Print the stat() error message unless it was ENOENT and we're
// following symlinks.
if (!(ret == ENOENT && !show_links)) {
- LOG(ERROR) << "Couldn't stat "
- << source.Append(dent->d_name).value() << ": "
- << strerror(errno);
+ PLOG(ERROR) << "Couldn't stat "
+ << source.Append(dent->d_name).value();
}
memset(&info.stat, 0, sizeof(info.stat));
}
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index 390a2b5..1160b48 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -367,7 +367,7 @@ static int GetProcessCPU(pid_t pid) {
DIR* dir = opendir(path.value().c_str());
if (!dir) {
- LOG(ERROR) << "opendir(" << path.value() << "): " << strerror(errno);
+ PLOG(ERROR) << "opendir(" << path.value() << ")";
return -1;
}
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index 235456b..61ecb7e 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -274,8 +274,7 @@ bool LaunchApp(const std::vector<std::string>& argv,
argv_cstr[i] = const_cast<char*>(argv[i].c_str());
argv_cstr[argv.size()] = NULL;
execvp(argv_cstr[0], argv_cstr.get());
- LOG(ERROR) << "LaunchApp: execvp(" << argv_cstr[0] << ") failed: "
- << strerror(errno);
+ PLOG(ERROR) << "LaunchApp: execvp(" << argv_cstr[0] << ") failed";
_exit(127);
} else {
// Parent process
@@ -333,7 +332,7 @@ bool DidProcessCrash(bool* child_exited, ProcessHandle handle) {
int status;
const int result = HANDLE_EINTR(waitpid(handle, &status, WNOHANG));
if (result == -1) {
- LOG(ERROR) << "waitpid(" << handle << "): " << strerror(errno);
+ PLOG(ERROR) << "waitpid(" << handle << ")";
if (child_exited)
*child_exited = false;
return false;
diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc
index 8828b10..34e7b72 100644
--- a/base/shared_memory_posix.cc
+++ b/base/shared_memory_posix.cc
@@ -13,6 +13,7 @@
#include "base/file_util.h"
#include "base/logging.h"
#include "base/platform_thread.h"
+#include "base/safe_strerror_posix.h"
#include "base/string_util.h"
namespace base {
@@ -188,8 +189,7 @@ bool SharedMemory::CreateOrOpen(const std::wstring &name,
if (fp == NULL) {
if (posix_flags & O_CREAT)
- LOG(ERROR) << "Creating shared memory in " << path.value() << " failed: "
- << strerror(errno);
+ PLOG(ERROR) << "Creating shared memory in " << path.value() << " failed";
return false;
}
@@ -291,7 +291,7 @@ void SharedMemory::LockOrUnlockCommon(int function) {
<< " function:" << function
<< " fd:" << mapped_file_
<< " errno:" << errno
- << " msg:" << strerror(errno);
+ << " msg:" << safe_strerror(errno);
}
}
}
diff --git a/base/stats_table.cc b/base/stats_table.cc
index 522db5a..2edbb44 100644
--- a/base/stats_table.cc
+++ b/base/stats_table.cc
@@ -257,14 +257,8 @@ StatsTable::StatsTable(const std::string& name, int max_threads,
impl_ = StatsTablePrivate::New(name, table_size, max_threads, max_counters);
- // TODO(port): clean up this error reporting.
-#if defined(OS_WIN)
if (!impl_)
- LOG(ERROR) << "StatsTable did not initialize:" << GetLastError();
-#elif defined(OS_POSIX)
- if (!impl_)
- LOG(ERROR) << "StatsTable did not initialize:" << strerror(errno);
-#endif
+ PLOG(ERROR) << "StatsTable did not initialize";
}
StatsTable::~StatsTable() {