summaryrefslogtreecommitdiffstats
path: root/chrome/common/ipc_channel_posix.cc
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-17 01:48:35 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-17 01:48:35 +0000
commit02d665113d8deec5ccf5c3d645889d763d4aac6c (patch)
treef627b475dbac9d7a651c020d9a83165b4d1012ba /chrome/common/ipc_channel_posix.cc
parentba4363e6ca4c3667c4640666e66fbdf5ab162dec (diff)
downloadchromium_src-02d665113d8deec5ccf5c3d645889d763d4aac6c.zip
chromium_src-02d665113d8deec5ccf5c3d645889d763d4aac6c.tar.gz
chromium_src-02d665113d8deec5ccf5c3d645889d763d4aac6c.tar.bz2
Linux: remove the use of UNIX_PATH_MAX for systems which don't have it.
Not all kernel headers seem to include UNIX_PATH_MAX. Instead, use sizeof. Review URL: http://codereview.chromium.org/48047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/ipc_channel_posix.cc')
-rw-r--r--chrome/common/ipc_channel_posix.cc28
1 files changed, 9 insertions, 19 deletions
diff --git a/chrome/common/ipc_channel_posix.cc b/chrome/common/ipc_channel_posix.cc
index f637277..20d5f7a 100644
--- a/chrome/common/ipc_channel_posix.cc
+++ b/chrome/common/ipc_channel_posix.cc
@@ -10,11 +10,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
-#if defined(OS_LINUX)
-#include <linux/un.h>
-#elif defined(OS_MACOSX)
#include <sys/un.h>
-#endif
#include <string>
#include <map>
@@ -120,22 +116,16 @@ int ChannelNameToClientFD(const std::string& channel_id) {
}
//------------------------------------------------------------------------------
-// The -1 is to take the NULL terminator into account.
-#if defined(OS_LINUX)
-const size_t kMaxPipeNameLength = UNIX_PATH_MAX - 1;
-#elif defined(OS_MACOSX)
-// OS X doesn't define UNIX_PATH_MAX
-// Per the size specified for the sun_path structure of sockaddr_un in sys/un.h.
-const size_t kMaxPipeNameLength = 104 - 1;
-#endif
+sockaddr_un sizecheck;
+const size_t kMaxPipeNameLength = sizeof(sizecheck.sun_path);
// Creates a Fifo with the specified name ready to listen on.
bool CreateServerFifo(const std::string &pipe_name, int* server_listen_fd) {
DCHECK(server_listen_fd);
- DCHECK(pipe_name.length() > 0);
- DCHECK(pipe_name.length() < kMaxPipeNameLength);
+ DCHECK_GT(pipe_name.length(), 0u);
+ DCHECK_LT(pipe_name.length(), kMaxPipeNameLength);
- if (pipe_name.length() == 0 || pipe_name.length() > kMaxPipeNameLength) {
+ if (pipe_name.length() == 0 || pipe_name.length() >= kMaxPipeNameLength) {
return false;
}
@@ -158,7 +148,7 @@ bool CreateServerFifo(const std::string &pipe_name, int* server_listen_fd) {
struct sockaddr_un unix_addr;
memset(&unix_addr, 0, sizeof(unix_addr));
unix_addr.sun_family = AF_UNIX;
- snprintf(unix_addr.sun_path, kMaxPipeNameLength + 1, "%s", pipe_name.c_str());
+ snprintf(unix_addr.sun_path, kMaxPipeNameLength, "%s", pipe_name.c_str());
size_t unix_addr_len = offsetof(struct sockaddr_un, sun_path) +
strlen(unix_addr.sun_path) + 1;
@@ -198,7 +188,7 @@ bool ServerAcceptFifoConnection(int server_listen_fd, int* server_socket) {
bool ClientConnectToFifo(const std::string &pipe_name, int* client_socket) {
DCHECK(client_socket);
- DCHECK(pipe_name.length() < kMaxPipeNameLength);
+ DCHECK_LT(pipe_name.length(), kMaxPipeNameLength);
// Create socket.
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -209,7 +199,7 @@ bool ClientConnectToFifo(const std::string &pipe_name, int* client_socket) {
// Make socket non-blocking
if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
- LOG(ERROR) << "fcnt failed";
+ LOG(ERROR) << "fcntl failed";
close(fd);
return false;
}
@@ -218,7 +208,7 @@ bool ClientConnectToFifo(const std::string &pipe_name, int* client_socket) {
struct sockaddr_un server_unix_addr;
memset(&server_unix_addr, 0, sizeof(server_unix_addr));
server_unix_addr.sun_family = AF_UNIX;
- snprintf(server_unix_addr.sun_path, kMaxPipeNameLength + 1, "%s",
+ snprintf(server_unix_addr.sun_path, kMaxPipeNameLength, "%s",
pipe_name.c_str());
size_t server_unix_addr_len = offsetof(struct sockaddr_un, sun_path) +
strlen(server_unix_addr.sun_path) + 1;