--- ipc/unix_ipc.cc.orig 2012-09-07 10:21:32.692021977 +0900 +++ ipc/unix_ipc.cc 2012-09-07 10:38:01.136021395 +0900 @@ -41,7 +41,7 @@ #include #include #include -#ifdef OS_MACOSX +#if defined(OS_MACOSX) || defined(__FreeBSD__) #include #endif #include @@ -125,7 +125,7 @@ bool IsPeerValid(int socket, pid_t *pid) { *pid = 0; -#ifdef OS_MACOSX +#if defined(OS_MACOSX) || defined(__FreeBSD__) // If the OS is MAC, we should validate the peer by using LOCAL_PEERCRED. struct xucred peer_cred; socklen_t peer_cred_len = sizeof(struct xucred); @@ -147,7 +147,7 @@ *pid = 0; #endif -#ifdef OS_LINUX +#if defined(OS_LINUX) && !defined(__FreeBSD__) // On ARM Linux, we do nothing and just return true since the platform // sometimes doesn't support the getsockopt(sock, SOL_SOCKET, SO_PEERCRED) // system call. @@ -310,7 +310,7 @@ address.sun_family = AF_UNIX; ::memcpy(address.sun_path, server_address.data(), server_address_length); address.sun_path[server_address_length] = '\0'; -#ifdef OS_MACOSX +#if defined(OS_MACOSX) || defined(__FreeBSD__) address.sun_len = SUN_LEN(&address); const size_t sun_len = sizeof(address); #else @@ -435,21 +435,21 @@ SO_REUSEADDR, reinterpret_cast(&on), sizeof(on)); -#ifdef OS_MACOSX +#if defined(OS_MACOSX) || defined(__FreeBSD__) addr.sun_len = SUN_LEN(&addr); const size_t sun_len = sizeof(addr); #else const size_t sun_len = sizeof(addr.sun_family) + server_address_.size(); #endif - if (!IsAbstractSocket(server_address_)) { - // Linux does not use files for IPC. - ::chmod(server_address_.c_str(), 0600); - } if (::bind(socket_, reinterpret_cast(&addr), sun_len) != 0) { // The UNIX domain socket file (server_address_) already exists? LOG(FATAL) << "bind() failed: " << strerror(errno); return; } + if (!IsAbstractSocket(server_address_)) { + // Linux does not use files for IPC. + ::chmod(server_address_.c_str(), 0600); + } if (::listen(socket_, num_connections) < 0) { LOG(FATAL) << "listen() failed: " << strerror(errno);