commit 980d8b7: [Minor] Explicitly specify af for socketpair
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Jun 10 12:14:06 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-06-10 13:02:59 +0100
URL: https://github.com/rspamd/rspamd/commit/980d8b7d6b4369491bd99df633a8ad88100e9986
[Minor] Explicitly specify af for socketpair
---
src/libserver/rspamd_control.c | 2 +-
src/libserver/worker_util.c | 4 ++--
src/libutil/util.c | 14 ++++++--------
src/libutil/util.h | 2 +-
src/lua/lua_worker.c | 2 +-
5 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 2670263f3..f1de1d29c 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -914,7 +914,7 @@ rspamd_srv_handler (EV_P_ ev_io *w, int revents)
if (spair == NULL) {
spair = g_malloc (sizeof (gint) * 2);
- if (rspamd_socketpair (spair, 0) == -1) {
+ if (rspamd_socketpair (spair, cmd.cmd.spair.af) == -1) {
rdata->rep.reply.spair.code = errno;
msg_err ("cannot create socket pair: %s", strerror (errno));
}
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 1c7069521..4c82cb330 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -1136,12 +1136,12 @@ rspamd_fork_worker (struct rspamd_main *rspamd_main,
/* Starting worker process */
wrk = (struct rspamd_worker *) g_malloc0 (sizeof (struct rspamd_worker));
- if (!rspamd_socketpair (wrk->control_pipe, 0)) {
+ if (!rspamd_socketpair (wrk->control_pipe, SOCK_DGRAM)) {
msg_err ("socketpair failure: %s", strerror (errno));
rspamd_hard_terminate (rspamd_main);
}
- if (!rspamd_socketpair (wrk->srv_pipe, 0)) {
+ if (!rspamd_socketpair (wrk->srv_pipe, SOCK_DGRAM)) {
msg_err ("socketpair failure: %s", strerror (errno));
rspamd_hard_terminate (rspamd_main);
}
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 3dc1adea1..60328df32 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -442,23 +442,21 @@ rspamd_socket (const gchar *credits, guint16 port,
}
gboolean
-rspamd_socketpair (gint pair[2], gboolean is_stream)
+rspamd_socketpair (gint pair[2], gint af)
{
- gint r, serrno;
+ gint r = -1, serrno;
- if (!is_stream) {
#ifdef HAVE_SOCK_SEQPACKET
+ if (af == SOCK_SEQPACKET) {
r = socketpair (AF_LOCAL, SOCK_SEQPACKET, 0, pair);
if (r == -1) {
r = socketpair (AF_LOCAL, SOCK_DGRAM, 0, pair);
}
-#else
- r = socketpair (AF_LOCAL, SOCK_DGRAM, 0, pair);
-#endif
}
- else {
- r = socketpair (AF_LOCAL, SOCK_STREAM, 0, pair);
+#endif
+ if (r == -1) {
+ r = socketpair (AF_LOCAL, af, 0, pair);
}
if (r == -1) {
diff --git a/src/libutil/util.h b/src/libutil/util.h
index 367e280f1..c1c29ab30 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -66,7 +66,7 @@ gint rspamd_socket (const gchar *credits, guint16 port, gint type,
/*
* Create socketpair
*/
-gboolean rspamd_socketpair (gint pair[2], gboolean is_stream);
+gboolean rspamd_socketpair (gint pair[2], gint af);
/*
* Make specified socket non-blocking
diff --git a/src/lua/lua_worker.c b/src/lua/lua_worker.c
index badc50a72..c11e49f2e 100644
--- a/src/lua/lua_worker.c
+++ b/src/lua/lua_worker.c
@@ -786,7 +786,7 @@ lua_worker_spawn_process (lua_State *L)
cbdata->out_pos = 0;
}
- if (rspamd_socketpair (cbdata->sp, TRUE) == -1) {
+ if (rspamd_socketpair (cbdata->sp, SOCK_STREAM) == -1) {
msg_err ("cannot spawn socketpair: %s", strerror (errno));
luaL_unref (L, LUA_REGISTRYINDEX, cbdata->func_cbref);
luaL_unref (L, LUA_REGISTRYINDEX, cbdata->cb_cbref);
More information about the Commits
mailing list