3da827
diff -up rpcbind-0.2.0/configure.ac.orig rpcbind-0.2.0/configure.ac
3da827
--- rpcbind-0.2.0/configure.ac.orig	2015-05-04 08:15:10.394432254 -0400
3da827
+++ rpcbind-0.2.0/configure.ac	2015-05-04 08:48:36.463258254 -0400
3da827
@@ -36,6 +36,18 @@ AC_SUBST([nss_modules], [$with_nss_modul
3da827
 
3da827
 PKG_CHECK_MODULES([TIRPC], [libtirpc])
3da827
 
3da827
+PKG_PROG_PKG_CONFIG
3da827
+AC_ARG_WITH([systemdsystemunitdir],
3da827
+  AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
3da827
+  [], [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
3da827
+  if test "x$with_systemdsystemunitdir" != xno; then
3da827
+    AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
3da827
+     PKG_CHECK_MODULES([SYSTEMD], [libsystemd], [],
3da827
+	   [PKG_CHECK_MODULES([SYSTEMD], [libsystemd-daemon], [],
3da827
+	   AC_MSG_ERROR([libsystemd support requested but found]))])
3da827
+  fi
3da827
+AM_CONDITIONAL(SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
3da827
+
3da827
 AS_IF([test x$enable_libwrap = xyes], [
3da827
 	AC_CHECK_LIB([wrap], [hosts_access], ,
3da827
 		AC_MSG_ERROR([libwrap support requested but unable to find libwrap]))
3da827
diff -up rpcbind-0.2.0/Makefile.am.orig rpcbind-0.2.0/Makefile.am
3da827
--- rpcbind-0.2.0/Makefile.am.orig	2015-05-04 08:15:10.394432254 -0400
3da827
+++ rpcbind-0.2.0/Makefile.am	2015-05-04 08:48:36.463258254 -0400
3da827
@@ -39,6 +39,12 @@ rpcbind_SOURCES = \
3da827
 	src/warmstart.c
3da827
 rpcbind_LDADD = $(TIRPC_LIBS)
3da827
 
3da827
+if SYSTEMD
3da827
+AM_CPPFLAGS += $(SYSTEMD_CFLAGS) -DSYSTEMD
3da827
+
3da827
+rpcbind_LDADD += $(SYSTEMD_LIBS)
3da827
+endif
3da827
+
3da827
 rpcinfo_SOURCES =       src/rpcinfo.c
3da827
 rpcinfo_LDADD   =       $(TIRPC_LIBS)
3da827
 
3da827
diff -up rpcbind-0.2.0/src/rpcbind.c.orig rpcbind-0.2.0/src/rpcbind.c
3da827
--- rpcbind-0.2.0/src/rpcbind.c.orig	2015-05-04 08:15:10.394432254 -0400
3da827
+++ rpcbind-0.2.0/src/rpcbind.c	2015-05-04 08:48:36.463258254 -0400
3da827
@@ -56,6 +56,9 @@
3da827
 #include <netinet/in.h>
3da827
 #endif
3da827
 #include <arpa/inet.h>
3da827
+#ifdef SYSTEMD
3da827
+#include <systemd/sd-daemon.h>
3da827
+#endif
3da827
 #include <fcntl.h>
3da827
 #include <netdb.h>
3da827
 #include <stdio.h>
3da827
@@ -291,6 +294,7 @@ init_transport(struct netconfig *nconf)
3da827
 	u_int32_t host_addr[4];  /* IPv4 or IPv6 */
3da827
 	struct sockaddr_un sun;
3da827
 	mode_t oldmask;
3da827
+	int n;
3da827
         res = NULL;
3da827
 
3da827
 	if ((nconf->nc_semantics != NC_TPI_CLTS) &&
3da827
@@ -309,6 +313,76 @@ init_transport(struct netconfig *nconf)
3da827
 			fprintf(stderr, "[%d] - %s\n", i, *s);
3da827
 	}
3da827
 #endif
3da827
+	if (!__rpc_nconf2sockinfo(nconf, &si)) {
3da827
+		syslog(LOG_ERR, "cannot get information for %s",
3da827
+		    nconf->nc_netid);
3da827
+		return (1);
3da827
+	}
3da827
+
3da827
+#ifdef SYSTEMD
3da827
+	n = sd_listen_fds(0);
3da827
+	if (n < 0) {
3da827
+		syslog(LOG_ERR, "failed to acquire systemd sockets: %s", strerror(-n));
3da827
+		return 1;
3da827
+	}
3da827
+
3da827
+	/* Try to find if one of the systemd sockets we were given match
3da827
+	 * our netconfig structure. */
3da827
+
3da827
+	for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
3da827
+		struct __rpc_sockinfo si_other;
3da827
+		union {
3da827
+			struct sockaddr sa;
3da827
+			struct sockaddr_un un;
3da827
+			struct sockaddr_in in4;
3da827
+			struct sockaddr_in6 in6;
3da827
+			struct sockaddr_storage storage;
3da827
+		} sa;
3da827
+		socklen_t addrlen = sizeof(sa);
3da827
+
3da827
+		if (!__rpc_fd2sockinfo(fd, &si_other)) {
3da827
+			syslog(LOG_ERR, "cannot get information for fd %i", fd);
3da827
+			return 1;
3da827
+		}
3da827
+
3da827
+		if (si.si_af != si_other.si_af ||
3da827
+                    si.si_socktype != si_other.si_socktype ||
3da827
+                    si.si_proto != si_other.si_proto)
3da827
+			continue;
3da827
+
3da827
+		if (getsockname(fd, &sa.sa, &addrlen) < 0) {
3da827
+			syslog(LOG_ERR, "failed to query socket name: %s",
3da827
+                               strerror(errno));
3da827
+			goto error;
3da827
+		}
3da827
+
3da827
+		/* Copy the address */
3da827
+		taddr.addr.maxlen = taddr.addr.len = addrlen;
3da827
+		taddr.addr.buf = malloc(addrlen);
3da827
+		if (taddr.addr.buf == NULL) {
3da827
+			syslog(LOG_ERR,
3da827
+                               "cannot allocate memory for %s address",
3da827
+                               nconf->nc_netid);
3da827
+			goto error;
3da827
+		}
3da827
+		memcpy(taddr.addr.buf, &sa, addrlen);
3da827
+
3da827
+		my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr,
3da827
+                          RPC_MAXDATASIZE, RPC_MAXDATASIZE);
3da827
+		if (my_xprt == (SVCXPRT *)NULL) {
3da827
+			syslog(LOG_ERR, "%s: could not create service",
3da827
+                               nconf->nc_netid);
3da827
+			goto error;
3da827
+		}
3da827
+	}
3da827
+
3da827
+	/*
3da827
+	 * If none of the systemd sockets matched, we set up the socket in
3da827
+	 * the normal way:
3da827
+	 */
3da827
+#endif
3da827
+	if (my_xprt != NULL)
3da827
+		goto got_socket;
3da827
 
3da827
 	/*
3da827
 	 * XXX - using RPC library internal functions. For NC_TPI_CLTS
3da827
@@ -322,12 +396,6 @@ init_transport(struct netconfig *nconf)
3da827
 		}
3da827
 	}
3da827
 
3da827
-	if (!__rpc_nconf2sockinfo(nconf, &si)) {
3da827
-		syslog(LOG_ERR, "cannot get information for %s",
3da827
-		    nconf->nc_netid);
3da827
-		return (1);
3da827
-	}
3da827
-
3da827
 	if ((strcmp(nconf->nc_netid, "local") == 0) ||
3da827
 	    (strcmp(nconf->nc_netid, "unix") == 0)) {
3da827
 		memset(&sun, 0, sizeof sun);
3da827
@@ -564,6 +632,7 @@ init_transport(struct netconfig *nconf)
3da827
 			goto error;
3da827
 		}
3da827
 	}
3da827
+got_socket:
3da827
 
3da827
 #ifdef PORTMAP
3da827
 	/*