From 72602bcabe5de4852cb70b6d55b7bf7c24ded4f9 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 8 Oct 2015 17:22:37 +0100 Subject: [PATCH] Update socketpair utility function. --- src/libutil/util.c | 25 ++++++++++++++++++++----- src/libutil/util.h | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/libutil/util.c b/src/libutil/util.c index dae26a5c0..bc723464f 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -571,18 +571,30 @@ err: return NULL; } -gint +gboolean rspamd_socketpair (gint pair[2]) { - gint r; + gint r, serrno; - r = socketpair (AF_LOCAL, SOCK_STREAM, 0, pair); +#ifdef HAVE_SOCK_SEQPACKET + r = socketpair (AF_LOCAL, SOCK_SEQPACKET, 0, pair); + + if (r == -1) { + msg_warn ("seqpacket socketpair failed: %d, '%s'", + errno, + strerror (errno)); + r = socketpair (AF_LOCAL, SOCK_DGRAM, 0, pair); + } +#else + r = socketpair (AF_LOCAL, SOCK_DGRAM, 0, pair); +#endif if (r == -1) { msg_warn ("socketpair failed: %d, '%s'", errno, strerror ( errno), pair[0], pair[1]); return -1; } + /* Set close on exec */ if (fcntl (pair[0], F_SETFD, FD_CLOEXEC) == -1) { msg_warn ("fcntl failed: %d, '%s'", errno, strerror (errno)); @@ -593,12 +605,15 @@ rspamd_socketpair (gint pair[2]) goto out; } - return 0; + return TRUE; out: + serrno = errno; close (pair[0]); close (pair[1]); - return (-1); + errno = serrno; + + return FALSE; } gint diff --git a/src/libutil/util.h b/src/libutil/util.h index e563718f8..bf55f901f 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -74,7 +74,7 @@ GList * rspamd_sockets_list (const gchar *credits, /* * Create socketpair */ -gint rspamd_socketpair (gint pair[2]); +gboolean rspamd_socketpair (gint pair[2]); /* * Write pid to file -- 2.39.5