|
|
95f7f3 |
Description: systemd-like socket activation support for libmilter
|
|
|
95f7f3 |
Author: Mikhail Gusarov
|
|
|
95f7f3 |
diff --git a/libmilter/docs/smfi_setconn.html b/libmilter/docs/smfi_setconn.html
|
|
|
95f7f3 |
index eba7c5b..5b272a0 100644
|
|
|
95f7f3 |
--- a/libmilter/docs/smfi_setconn.html
|
|
|
95f7f3 |
+++ b/libmilter/docs/smfi_setconn.html
|
|
|
95f7f3 |
@@ -43,6 +43,7 @@ Set the socket through which this filter should communicate with sendmail.
|
|
|
95f7f3 |
{unix|local}:/path/to/file -- A named pipe.
|
|
|
95f7f3 |
inet:port@{hostname|ip-address} -- An IPV4 socket.
|
|
|
95f7f3 |
inet6:port@{hostname|ip-address} -- An IPV6 socket.
|
|
|
95f7f3 |
+ fd:number -- Pre-opened file descriptor.
|
|
|
95f7f3 |
|
|
|
95f7f3 |
|
|
|
95f7f3 |
|
|
|
95f7f3 |
diff --git a/libmilter/listener.c b/libmilter/listener.c
|
|
|
95f7f3 |
index 11d92bb..2ab533d 100644
|
|
|
95f7f3 |
--- a/libmilter/listener.c
|
|
|
95f7f3 |
+++ b/libmilter/listener.c
|
|
|
95f7f3 |
@@ -197,6 +197,11 @@ mi_milteropen(conn, backlog, rmsocket, name)
|
|
|
95f7f3 |
L_socksize = sizeof addr.sin6;
|
|
|
95f7f3 |
}
|
|
|
95f7f3 |
#endif /* NETINET6 */
|
|
|
95f7f3 |
+ else if (strcasecmp(p, "fd") == 0)
|
|
|
95f7f3 |
+ {
|
|
|
95f7f3 |
+ addr.sa.sa_family = AF_UNSPEC;
|
|
|
95f7f3 |
+ L_socksize = sizeof (_SOCK_ADDR);
|
|
|
95f7f3 |
+ }
|
|
|
95f7f3 |
else
|
|
|
95f7f3 |
{
|
|
|
95f7f3 |
smi_log(SMI_LOG_ERR, "%s: unknown socket type %s",
|
|
|
95f7f3 |
@@ -443,7 +448,21 @@ mi_milteropen(conn, backlog, rmsocket, name)
|
|
|
95f7f3 |
}
|
|
|
95f7f3 |
#endif /* NETINET || NETINET6 */
|
|
|
95f7f3 |
|
|
|
95f7f3 |
- sock = socket(addr.sa.sa_family, SOCK_STREAM, 0);
|
|
|
95f7f3 |
+ if (addr.sa.sa_family == AF_UNSPEC)
|
|
|
95f7f3 |
+ {
|
|
|
95f7f3 |
+ char *end;
|
|
|
95f7f3 |
+ sock = strtol(colon, &end, 10);
|
|
|
95f7f3 |
+ if (*end != '\0' || sock < 0)
|
|
|
95f7f3 |
+ {
|
|
|
95f7f3 |
+ smi_log(SMI_LOG_ERR, "%s: expected positive integer as fd, got %s", name, colon);
|
|
|
95f7f3 |
+ return INVALID_SOCKET;
|
|
|
95f7f3 |
+ }
|
|
|
95f7f3 |
+ }
|
|
|
95f7f3 |
+ else
|
|
|
95f7f3 |
+ {
|
|
|
95f7f3 |
+ sock = socket(addr.sa.sa_family, SOCK_STREAM, 0);
|
|
|
95f7f3 |
+ }
|
|
|
95f7f3 |
+
|
|
|
95f7f3 |
if (!ValidSocket(sock))
|
|
|
95f7f3 |
{
|
|
|
95f7f3 |
smi_log(SMI_LOG_ERR,
|
|
|
95f7f3 |
@@ -466,6 +485,7 @@ mi_milteropen(conn, backlog, rmsocket, name)
|
|
|
95f7f3 |
#if NETUNIX
|
|
|
95f7f3 |
addr.sa.sa_family != AF_UNIX &&
|
|
|
95f7f3 |
#endif /* NETUNIX */
|
|
|
95f7f3 |
+ addr.sa.sa_family != AF_UNSPEC &&
|
|
|
95f7f3 |
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &sockopt,
|
|
|
95f7f3 |
sizeof(sockopt)) == -1)
|
|
|
95f7f3 |
{
|
|
|
95f7f3 |
@@ -511,7 +531,8 @@ mi_milteropen(conn, backlog, rmsocket, name)
|
|
|
95f7f3 |
}
|
|
|
95f7f3 |
#endif /* NETUNIX */
|
|
|
95f7f3 |
|
|
|
95f7f3 |
- if (bind(sock, &addr.sa, L_socksize) < 0)
|
|
|
95f7f3 |
+ if (addr.sa.sa_family != AF_UNSPEC &&
|
|
|
95f7f3 |
+ bind(sock, &addr.sa, L_socksize) < 0)
|
|
|
95f7f3 |
{
|
|
|
95f7f3 |
smi_log(SMI_LOG_ERR,
|
|
|
95f7f3 |
"%s: Unable to bind to port %s: %s",
|
|
|
95f7f3 |
@@ -818,7 +839,7 @@ mi_listener(conn, dbg, smfi, timeout, backlog)
|
|
|
95f7f3 |
# ifdef BSD4_4_SOCKADDR
|
|
|
95f7f3 |
cliaddr.sa.sa_len == 0 ||
|
|
|
95f7f3 |
# endif /* BSD4_4_SOCKADDR */
|
|
|
95f7f3 |
- cliaddr.sa.sa_family != L_family))
|
|
|
95f7f3 |
+ (L_family != AF_UNSPEC && cliaddr.sa.sa_family != L_family)))
|
|
|
95f7f3 |
{
|
|
|
95f7f3 |
(void) closesocket(connfd);
|
|
|
95f7f3 |
connfd = INVALID_SOCKET;
|