Index: ipc/ipc_channel_posix.cc |
diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc |
index 4ccf71215bf0f7e2684315c048af20f5444017c1..5bda4c7d0b9b29c2cd52044cebead96644c1cf82 100644 |
--- a/ipc/ipc_channel_posix.cc |
+++ b/ipc/ipc_channel_posix.cc |
@@ -15,6 +15,7 @@ |
#include <string> |
#include <map> |
+#include "base/base_paths.h" |
#include "base/command_line.h" |
#include "base/eintr_wrapper.h" |
#include "base/file_path.h" |
@@ -23,6 +24,7 @@ |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/singleton.h" |
+#include "base/path_service.h" |
#include "base/process_util.h" |
#include "base/string_util.h" |
#include "base/synchronization/lock.h" |
@@ -142,11 +144,16 @@ COMPILE_ASSERT(sizeof(((sockaddr_un*)0)->sun_path) >= kMaxPipeNameLength, |
// for connections. |
bool CreateServerUnixDomainSocket(const std::string& pipe_name, |
int* server_listen_fd) { |
+ //Convert relative path of named pipe to absolute path |
sanjeevr
2011/06/20 22:27:26
Style nit: You need a space after the //. Same bel
|
+ //to allow IPC when processes have different working directories. |
+ FilePath temp_dir; |
+ PathService::Get(base::DIR_TEMP, &temp_dir); |
+ std::string pipe_path= temp_dir.Append(pipe_name).value(); |
sanjeevr
2011/06/20 22:27:26
Style nit: You need a space before the =
|
DCHECK(server_listen_fd); |
- DCHECK_GT(pipe_name.length(), 0u); |
- DCHECK_LT(pipe_name.length(), kMaxPipeNameLength); |
+ DCHECK_GT(pipe_path.length(), 0u); |
+ DCHECK_LT(pipe_path.length(), kMaxPipeNameLength); |
- if (pipe_name.length() == 0 || pipe_name.length() >= kMaxPipeNameLength) { |
+ if (pipe_path.length() == 0 || pipe_path.length() >= kMaxPipeNameLength) { |
return false; |
} |
@@ -158,17 +165,17 @@ bool CreateServerUnixDomainSocket(const std::string& pipe_name, |
// Make socket non-blocking |
if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { |
- PLOG(ERROR) << "fcntl(O_NONBLOCK) " << pipe_name; |
+ PLOG(ERROR) << "fcntl(O_NONBLOCK) " << pipe_path; |
if (HANDLE_EINTR(close(fd)) < 0) |
- PLOG(ERROR) << "close " << pipe_name; |
+ PLOG(ERROR) << "close " << pipe_path; |
return false; |
} |
// Delete any old FS instances. |
- unlink(pipe_name.c_str()); |
+ unlink(pipe_path.c_str()); |
// Make sure the path we need exists. |
- FilePath path(pipe_name); |
+ FilePath path(pipe_path); |
FilePath dir_path = path.DirName(); |
if (!file_util::CreateDirectory(dir_path)) { |
return false; |
@@ -179,26 +186,26 @@ bool CreateServerUnixDomainSocket(const std::string& pipe_name, |
memset(&unix_addr, 0, sizeof(unix_addr)); |
unix_addr.sun_family = AF_UNIX; |
int path_len = snprintf(unix_addr.sun_path, IPC::kMaxPipeNameLength, |
- "%s", pipe_name.c_str()); |
- DCHECK_EQ(static_cast<int>(pipe_name.length()), path_len); |
+ "%s", pipe_path.c_str()); |
+ DCHECK_EQ(static_cast<int>(pipe_path.length()), path_len); |
size_t unix_addr_len = offsetof(struct sockaddr_un, |
sun_path) + path_len + 1; |
// Bind the socket. |
if (bind(fd, reinterpret_cast<const sockaddr*>(&unix_addr), |
unix_addr_len) != 0) { |
- PLOG(ERROR) << "bind " << pipe_name; |
+ PLOG(ERROR) << "bind " << pipe_path; |
if (HANDLE_EINTR(close(fd)) < 0) |
- PLOG(ERROR) << "close " << pipe_name; |
+ PLOG(ERROR) << "close " << pipe_path; |
return false; |
} |
// Start listening on the socket. |
const int listen_queue_length = 1; |
if (listen(fd, listen_queue_length) != 0) { |
- PLOG(ERROR) << "listen " << pipe_name; |
+ PLOG(ERROR) << "listen " << pipe_path; |
if (HANDLE_EINTR(close(fd)) < 0) |
- PLOG(ERROR) << "close " << pipe_name; |
+ PLOG(ERROR) << "close " << pipe_path; |
return false; |
} |
@@ -226,26 +233,31 @@ bool ServerAcceptConnection(int server_listen_fd, int* server_socket) { |
bool CreateClientUnixDomainSocket(const std::string& pipe_name, |
int* client_socket) { |
+ //Convert relative path of named pipe to absolute path |
dmac
2011/06/20 22:30:23
spaces after //
|
+ //to allow IPC when processes have different working directories. |
+ FilePath temp_dir; |
+ PathService::Get(base::DIR_TEMP, &temp_dir); |
+ std::string pipe_path= temp_dir.Append(pipe_name).value(); |
dmac
2011/06/20 22:30:23
space before =
|
DCHECK(client_socket); |
- DCHECK_GT(pipe_name.length(), 0u); |
- DCHECK_LT(pipe_name.length(), kMaxPipeNameLength); |
+ DCHECK_GT(pipe_path.length(), 0u); |
+ DCHECK_LT(pipe_path.length(), kMaxPipeNameLength); |
- if (pipe_name.length() == 0 || pipe_name.length() >= kMaxPipeNameLength) { |
+ if (pipe_path.length() == 0 || pipe_path.length() >= kMaxPipeNameLength) { |
return false; |
} |
// Create socket. |
int fd = socket(AF_UNIX, SOCK_STREAM, 0); |
if (fd < 0) { |
- PLOG(ERROR) << "socket " << pipe_name; |
+ PLOG(ERROR) << "socket " << pipe_path; |
return false; |
} |
// Make socket non-blocking |
if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { |
- PLOG(ERROR) << "fcntl(O_NONBLOCK) " << pipe_name; |
+ PLOG(ERROR) << "fcntl(O_NONBLOCK) " << pipe_path; |
if (HANDLE_EINTR(close(fd)) < 0) |
- PLOG(ERROR) << "close " << pipe_name; |
+ PLOG(ERROR) << "close " << pipe_path; |
return false; |
} |
@@ -254,16 +266,16 @@ bool CreateClientUnixDomainSocket(const std::string& pipe_name, |
memset(&server_unix_addr, 0, sizeof(server_unix_addr)); |
server_unix_addr.sun_family = AF_UNIX; |
int path_len = snprintf(server_unix_addr.sun_path, IPC::kMaxPipeNameLength, |
- "%s", pipe_name.c_str()); |
- DCHECK_EQ(static_cast<int>(pipe_name.length()), path_len); |
+ "%s", pipe_path.c_str()); |
+ DCHECK_EQ(static_cast<int>(pipe_path.length()), path_len); |
size_t server_unix_addr_len = offsetof(struct sockaddr_un, |
sun_path) + path_len + 1; |
if (HANDLE_EINTR(connect(fd, reinterpret_cast<sockaddr*>(&server_unix_addr), |
server_unix_addr_len)) != 0) { |
- PLOG(ERROR) << "connect " << pipe_name; |
+ PLOG(ERROR) << "connect " << pipe_path; |
if (HANDLE_EINTR(close(fd)) < 0) |
- PLOG(ERROR) << "close " << pipe_name; |
+ PLOG(ERROR) << "close " << pipe_path; |
return false; |
} |