summaryrefslogtreecommitdiffstats
path: root/chrome/browser/process_singleton_linux.cc
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 /chrome/browser/process_singleton_linux.cc
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 'chrome/browser/process_singleton_linux.cc')
-rw-r--r--chrome/browser/process_singleton_linux.cc31
1 files changed, 16 insertions, 15 deletions
diff --git a/chrome/browser/process_singleton_linux.cc b/chrome/browser/process_singleton_linux.cc
index bfff289..094c86a 100644
--- a/chrome/browser/process_singleton_linux.cc
+++ b/chrome/browser/process_singleton_linux.cc
@@ -52,6 +52,7 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/process_util.h"
+#include "base/safe_strerror_posix.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
@@ -110,7 +111,7 @@ int SetCloseOnExec(int fd) {
// Close a socket and check return value.
void CloseSocket(int fd) {
int rv = HANDLE_EINTR(close(fd));
- DCHECK_EQ(0, rv) << "Error closing socket: " << strerror(errno);
+ DCHECK_EQ(0, rv) << "Error closing socket: " << safe_strerror(errno);
}
// Write a message to a socket fd.
@@ -128,7 +129,7 @@ bool WriteToSocket(int fd, const char *message, size_t length) {
LOG(ERROR) << "ProcessSingleton would block on write(), so it gave up.";
return false;
}
- LOG(ERROR) << "write() failed: " << strerror(errno);
+ PLOG(ERROR) << "write() failed";
return false;
}
bytes_written += rv;
@@ -167,7 +168,7 @@ ssize_t ReadFromSocket(int fd, char *buf, size_t bufsize, int timeout) {
ssize_t rv = HANDLE_EINTR(read(fd, buf + bytes_read, bufsize - bytes_read));
if (rv < 0) {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
- LOG(ERROR) << "read() failed: " << strerror(errno);
+ PLOG(ERROR) << "read() failed";
return rv;
} else {
// It would block, so we just return what has been read.
@@ -187,7 +188,7 @@ ssize_t ReadFromSocket(int fd, char *buf, size_t bufsize, int timeout) {
// Set up a socket and sockaddr appropriate for messaging.
void SetupSocket(const std::string& path, int* sock, struct sockaddr_un* addr) {
*sock = socket(PF_UNIX, SOCK_STREAM, 0);
- CHECK(*sock >= 0) << "socket() failed: " << strerror(errno);
+ PCHECK(*sock >= 0) << "socket() failed";
int rv = SetNonBlocking(*sock);
DCHECK_EQ(0, rv) << "Failed to make non-blocking socket.";
@@ -216,7 +217,7 @@ std::string ReadLink(const std::string& path) {
buf[len] = '\0';
return std::string(buf);
} else {
- LOG(ERROR) << "readlink(" << path << ") failed: " << strerror(errno);
+ PLOG(ERROR) << "readlink(" << path << ") failed";
}
}
@@ -227,7 +228,7 @@ std::string ReadLink(const std::string& path) {
bool UnlinkPath(const std::string& path) {
int rv = unlink(path.c_str());
if (rv < 0 && errno != ENOENT)
- LOG(ERROR) << "Failed to unlink " << path << ": " << strerror(errno);
+ PLOG(ERROR) << "Failed to unlink " << path;
return rv == 0;
}
@@ -304,7 +305,7 @@ bool KillProcessByLockPath(const std::string& path) {
if (pid >= 0) {
// TODO(james.su@gmail.com): Is SIGKILL ok?
int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL);
- DCHECK_EQ(0, rv) << "Error killing process:" << strerror(errno);
+ DCHECK_EQ(0, rv) << "Error killing process: " << safe_strerror(errno);
return true;
}
@@ -453,7 +454,7 @@ void ProcessSingleton::LinuxWatcher::OnFileCanReadWithoutBlocking(int fd) {
int connection_socket = HANDLE_EINTR(accept(
fd, reinterpret_cast<sockaddr*>(&from), &from_len));
if (-1 == connection_socket) {
- LOG(ERROR) << "accept() failed: " << strerror(errno);
+ PLOG(ERROR) << "accept() failed";
return;
}
int rv = SetNonBlocking(connection_socket);
@@ -542,7 +543,7 @@ void ProcessSingleton::LinuxWatcher::SocketReader::OnFileCanReadWithoutBlocking(
read(fd, buf_ + bytes_read_, sizeof(buf_) - bytes_read_));
if (rv < 0) {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
- LOG(ERROR) << "read() failed: " << strerror(errno);
+ PLOG(ERROR) << "read() failed";
CloseSocket(fd);
return;
} else {
@@ -606,7 +607,7 @@ void ProcessSingleton::LinuxWatcher::SocketReader::FinishWithACK(
}
if (shutdown(fd_, SHUT_WR) < 0)
- LOG(ERROR) << "shutdown() failed: " << strerror(errno);
+ PLOG(ERROR) << "shutdown() failed";
parent_->RemoveSocketReader(this);
// We are deleted beyond this point.
@@ -684,7 +685,7 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessWithTimeout(
}
if (shutdown(socket, SHUT_WR) < 0)
- LOG(ERROR) << "shutdown() failed: " << strerror(errno);
+ PLOG(ERROR) << "shutdown() failed";
// Read ACK message from the other process. It might be blocked for a certain
// timeout, to make sure the other process has enough time to return ACK.
@@ -735,8 +736,8 @@ void ProcessSingleton::Create() {
// startup race.
// TODO(mattm): If the other instance is on the same host, we could try
// to notify it rather than just failing.
- LOG(FATAL) << "Failed to create " << lock_path_.value() << ": "
- << strerror(saved_errno);
+ errno = saved_errno;
+ PLOG(FATAL) << "Failed to create " << lock_path_.value();
}
}
@@ -745,7 +746,7 @@ void ProcessSingleton::Create() {
UnlinkPath(socket_path_.value());
if (bind(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0) {
- LOG(ERROR) << "bind() failed: " << strerror(errno);
+ PLOG(ERROR) << "bind() failed";
LOG(ERROR) << "SingletonSocket failed to create a socket in your home "
"directory. This means that running multiple instances of "
"the Chrome binary will start multiple browser process "
@@ -755,7 +756,7 @@ void ProcessSingleton::Create() {
}
if (listen(sock, 5) < 0)
- NOTREACHED() << "listen failed: " << strerror(errno);
+ NOTREACHED() << "listen failed: " << safe_strerror(errno);
// Normally we would use ChromeThread, but the IO thread hasn't started yet.
// Using g_browser_process, we start the thread so we can listen on the