1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
--- ipc/unix_ipc.cc.org 2010-10-16 12:01:47.982178217 +0900
+++ ipc/unix_ipc.cc 2010-10-16 12:04:36.610176748 +0900
@@ -41,7 +41,7 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
-#ifdef OS_MACOSX
+#if defined(OS_MACOSX) || defined(__FreeBSD__)
#include <sys/ucred.h>
#endif
#include <sys/wait.h>
@@ -124,7 +124,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);
@@ -146,7 +146,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 (at
// least the qemu emulator) doesn't support the getsockopt(sock, SOL_SOCKET,
// SO_PEERCRED) system call.
@@ -311,7 +311,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
@@ -431,21 +431,21 @@
SO_REUSEADDR,
reinterpret_cast<char *>(&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<sockaddr *>(&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);
|