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 3e758ca
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "logger.h"
#include "transport.h"
#include "vfs.h"
#ifdef HAVE_SYS_UCRED_H
#include <sys/ucred.h>
#endif

/* Special ID for the bootstrap node. Equals to raft_digest("1", 0). */
#define BOOTSTRAP_ID 0x2dc171858c3155be
Expand Down Expand Up @@ -211,10 +214,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,6 +435,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) {
#if HAVE_DECL_LOCAL_PEERCRED
struct xucred cred;
socklen_t len;
int fd;
fd = stream->io_watcher.fd;
len = sizeof cred;
rv = getsockopt(fd, SOL_SOCKET, LOCAL_PEERCRED, &cred, &len);
if (rv != 0) {
goto err;
}
if (cred.cr_pid != getpid()) {
goto err;
}
#elif HAVE_DECL_SO_PEERCRED
struct ucred cred;
socklen_t len;
int fd;
Expand All @@ -443,6 +461,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 3e758ca

Please sign in to comment.