Blame SOURCES/sendmail-8.15.2-libmilter-socket-activation.patch

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