commit - e24c4959f1105965cf2ae2d245d6f83c6531a43e
commit + febe25b7cf7410d2a34c127b3981acd3b98edc2d
blob - 2d7781684ee5bfed430739283d2efa55ad0ffc30
blob + cf7de518223cce9d4733af55713e0c91684c2358
--- gotd/Makefile.am
+++ gotd/Makefile.am
gotd_SOURCES = gotd.c \
auth.c \
imsg.c \
+ listen.c \
log.c \
parse.y \
privsep_stub.c \
repo_imsg.c \
repo_read.c \
repo_write.c \
+ session.c \
$(top_srcdir)/lib/bloom.c \
$(top_srcdir)/lib/buf.c \
$(top_srcdir)/lib/date.c \
blob - af44a052722a32c66a572c1d58b97b65193706e1
blob + 9ed19e79b8bd0a7e69cf184b6a0bb5abfaa87fc3
--- gotd/gotd.c
+++ gotd/gotd.c
struct gotd_imsgev *session_iev = &client->session->iev;
struct gotd_imsg_connect_repo_child ireq;
int pipe[2];
+ int sock_flags = SOCK_STREAM | SOCK_NONBLOCK;
+
+#ifdef SOCK_CLOEXEC
+ sock_flags |= SOCK_CLOEXEC;
+#endif
if (client->state != GOTD_CLIENT_STATE_ACCESS_GRANTED)
return got_error_msg(GOT_ERR_BAD_REQUEST,
"unexpected repo child ready signal received");
- if (socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK,
- PF_UNSPEC, pipe) == -1)
+ if (socketpair(AF_UNIX, sock_flags, PF_UNSPEC, pipe) == -1)
fatal("socketpair");
memset(&ireq, 0, sizeof(ireq));
proc->type = PROC_LISTEN;
- if (socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK,
+ if (socketpair(AF_UNIX, sock_flags,
PF_UNSPEC, proc->pipe) == -1)
fatal("socketpair");
char *argv0, const char *confpath, int daemonize, int verbosity)
{
struct gotd_child_proc *proc;
+ int sock_flags = SOCK_STREAM | SOCK_NONBLOCK;
+#ifdef SOCK_CLOEXEC
+ sock_flags |= SOCK_CLOEXEC;
+#endif
+
proc = calloc(1, sizeof(*proc));
if (proc == NULL)
return got_error_from_errno("calloc");
if (strlcpy(proc->repo_path, repo->path, sizeof(proc->repo_path)) >=
sizeof(proc->repo_path))
fatalx("repository path too long: %s", repo->path);
- if (socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK,
- PF_UNSPEC, proc->pipe) == -1)
+ if (socketpair(AF_UNIX, sock_flags, PF_UNSPEC, proc->pipe) == -1)
fatal("socketpair");
proc->pid = start_child(proc->type, proc->repo_path, argv0,
confpath, proc->pipe[1], daemonize, verbosity);
int daemonize, int verbosity)
{
struct gotd_child_proc *proc;
+ int sock_flags = SOCK_STREAM|SOCK_NONBLOCK;
+#ifdef SOCK_CLOEXEC
+ sock_flags |= SOCK_CLOEXEC;
+#endif
+
if (proc_type != PROC_REPO_READ && proc_type != PROC_REPO_WRITE)
return got_error_msg(GOT_ERR_NOT_IMPL, "bad process type");
fatalx("repository name too long: %s", repo->name);
log_debug("starting %s for repository %s",
proc->type == PROC_REPO_READ ? "reader" : "writer", repo->name);
+
if (strlcpy(proc->repo_path, repo->path, sizeof(proc->repo_path)) >=
sizeof(proc->repo_path))
fatalx("repository path too long: %s", repo->path);
- if (socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK,
+ if (realpath(repo->path, proc->repo_path) == NULL)
+ fatal("%s", repo->path);
+ if (socketpair(AF_UNIX, sock_flags,
PF_UNSPEC, proc->pipe) == -1)
fatal("socketpair");
proc->pid = start_child(proc->type, proc->repo_path, argv0,
struct gotd_child_proc *proc;
struct gotd_imsg_auth iauth;
int fd;
+ int sock_flags = SOCK_STREAM|SOCK_NONBLOCK;
+#ifdef SOCK_CLOEXEC
+ sock_flags |= SOCK_CLOEXEC;
+#endif
+
memset(&iauth, 0, sizeof(iauth));
fd = dup(client->fd);
if (strlcpy(proc->repo_path, repo->path, sizeof(proc->repo_path)) >=
sizeof(proc->repo_path))
fatalx("repository path too long: %s", repo->path);
- if (socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK,
+ if (realpath(repo->path, proc->repo_path) == NULL)
+ fatal("%s", repo->path);
+ if (socketpair(AF_UNIX, sock_flags,
PF_UNSPEC, proc->pipe) == -1)
fatal("socketpair");
proc->pid = start_child(proc->type, proc->repo_path, argv0,
blob - 5a4ee87d85e91b5837d1d53b64706a661b1a359e
blob + 45bdfb39b3e27a99426467c5a42b68c88a4111a8
--- gotd/listen.c
+++ gotd/listen.c
#include <errno.h>
#include <event.h>
-#include <siphash.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "got_error.h"
#include "got_path.h"
+#include "got_compat.h"
+
#include "gotd.h"
#include "log.h"
#include "listen.h"
int reserve, volatile int *counter)
{
int ret;
+ int sock_flags = SOCK_NONBLOCK;
+#ifdef SOCK_CLOEXEC
+ sock_flags |= SOCK_CLOEXEC;
+#endif
+
if (getdtablecount() + reserve +
((*counter + 1) * GOTD_FD_NEEDED) >= getdtablesize()) {
log_debug("inflight fds exceeded");
errno = EMFILE;
return -1;
}
+#ifdef __APPLE__
+ /* TA: silence warning from GCC. */
+ (void)sock_flags;
+ ret = accept(fd, addr, addrlen);
+#else
+ ret = accept4(fd, addr, addrlen, sock_flags);
+#endif
- if ((ret = accept4(fd, addr, addrlen,
- SOCK_NONBLOCK | SOCK_CLOEXEC)) > -1) {
+ if (ret > -1) {
(*counter)++;
}
blob - 129aebf9ca0fd4335e15f41ac3374ac4670aa9e2
blob + 9b290cc8fb986baa3dc9b69f48d52e94740ac1e0
--- gotd/repo_write.c
+++ gotd/repo_write.c
static struct repo_write_client {
uint32_t id;
int fd;
- int pack_pipe[2];
+ int pack_pipe;
struct got_pack pack;
uint8_t pack_sha1[SHA1_DIGEST_LENGTH];
int packidx_fd;
tempfiles[i] = f;
}
- /* Send pack file pipe to gotsh(1). */
- if (imsg_compose(&ibuf, GOTD_IMSG_RECV_PACKFILE, PROC_REPO_WRITE,
- repo_write.pid, (*client)->pack_pipe[1], NULL, 0) == -1) {
- (*client)->pack_pipe[1] = -1;
- err = got_error_from_errno("imsg_compose ACK");
- if (err)
- goto done;
- }
- (*client)->pack_pipe[1] = -1;
err = gotd_imsg_flush(&ibuf);
if (err)
goto done;
blob - ae96f8dd8c3df35dfde0827d038a3fec4e55a08a
blob + 108bfe188d7d51323ad7f6323506dba066f9bba0
--- gotd/session.c
+++ gotd/session.c
#include <string.h>
#include <imsg.h>
#include <unistd.h>
+
+#include "got_compat.h"
#include "got_error.h"
#include "got_repository.h"