Skip to content

Commit

Permalink
Support compile with clang on BSD
Browse files Browse the repository at this point in the history
A couple of changes to make the code compile on BSD systems with clang
  • Loading branch information
rabits committed Feb 17, 2021
1 parent a89301a commit 7f87f8f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ int dqlite_node_set_bind_address(dqlite_node *t, const char *address)
len += sizeof(sa_family_t);
addr = (struct sockaddr *)&addr_un;
}
fd = socket(domain, SOCK_STREAM | SOCK_CLOEXEC, 0);
fd = socket(domain, SOCK_STREAM, 0);
if (fd == -1) {
return DQLITE_ERROR;
}
fcntl(fd, O_CLOEXEC);
if (domain == AF_INET) {
int reuse = 1;
rv = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
Expand Down Expand Up @@ -431,10 +432,20 @@ static void listenCb(uv_stream_t *listener, int status)

/* We accept unix socket connections only from the same process. */
if (listener->type == UV_NAMED_PIPE) {
int fd = stream->io_watcher.fd;
#if defined(__FreeBSD__) || defined(__APPLE__)
pid_t pid = -1;
socklen_t len = sizeof(pid);
rv = getsockopt(fd, SOL_SOCKET, LOCAL_PEERPID, &pid, &len);
if (rv != 0) {
goto err;
}
if (pid != getpid()) {
goto err;
}
#else
struct ucred cred;
socklen_t len;
int fd;
fd = stream->io_watcher.fd;
len = sizeof cred;
rv = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len);
if (rv != 0) {
Expand All @@ -443,6 +454,7 @@ static void listenCb(uv_stream_t *listener, int status)
if (cred.pid != getpid()) {
goto err;
}
#endif
}

conn = sqlite3_malloc(sizeof *conn);
Expand Down

0 comments on commit 7f87f8f

Please sign in to comment.