aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-06-09 14:36:07 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-06-09 14:36:07 +0100
commit903111c6cc2cbc07de9f84a8ad1b9cddc5dfaaeb (patch)
tree354c8a0122232003e707ddfa4d32aec35d0afa99 /src/libserver
parentae6f563623c765e574bd9a211be7524f7495ea28 (diff)
downloadrspamd-903111c6cc2cbc07de9f84a8ad1b9cddc5dfaaeb.tar.gz
rspamd-903111c6cc2cbc07de9f84a8ad1b9cddc5dfaaeb.zip
[Project] Do not listen sockets in the main process
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/worker_util.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index d5e603cfa..f1afcce0f 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -936,13 +936,24 @@ rspamd_main_heartbeat_start (struct rspamd_worker *wrk, struct ev_loop *event_lo
static bool
rspamd_maybe_reuseport_socket (struct rspamd_worker_listen_socket *ls)
{
- if (ls->fd == -1 || ls->is_systemd ||
- rspamd_inet_address_get_af (ls->addr) == AF_UNIX) {
- return false;
+ gint nfd = -1;
+
+ if (ls->fd == -1 || ls->is_systemd) {
+ /* No need to reuseport */
+ return true;
+ }
+
+ if (rspamd_inet_address_get_af (ls->addr) == AF_UNIX) {
+ /* Just try listen */
+
+ if (listen (ls->fd, -1) == -1) {
+ return false;
+ }
+
+ return true;
}
#if defined(SO_REUSEPORT) && defined(SO_REUSEADDR)
- gint nfd;
nfd = rspamd_inet_address_listen (ls->addr,
(ls->type == RSPAMD_WORKER_SOCKET_UDP ? SOCK_DGRAM : SOCK_STREAM),
@@ -952,16 +963,25 @@ rspamd_maybe_reuseport_socket (struct rspamd_worker_listen_socket *ls)
if (nfd == -1) {
msg_warn ("cannot create reuseport listen socket for %d: %s",
ls->fd, strerror (errno));
+ nfd = ls->fd;
}
else {
close (ls->fd);
ls->fd = nfd;
+ nfd = -1;
}
#else
-
+ nfd = ls->fd;
#endif
- return false;
+ /* This means that we have an fd with no listening enabled */
+ if (nfd != -1) {
+ if (listen (nfd, -1) == -1) {
+ return false;
+ }
+ }
+
+ return true;
}
/**