8f2528
commit 0e22b79bfde45a7cf7a2e51a68ec11c4285f3b31
8f2528
Author: Jakub Jelen <jjelen@redhat.com>
8f2528
Date:   Mon Nov 21 15:04:06 2016 +0100
8f2528
8f2528
    systemd stuff
8f2528
8f2528
diff --git a/configure.ac b/configure.ac
8f2528
index 2ffc369..162ce92 100644
8f2528
--- a/configure.ac
8f2528
+++ b/configure.ac
8f2528
@@ -4265,6 +4265,30 @@ AC_ARG_WITH([kerberos5],
8f2528
 AC_SUBST([GSSLIBS])
8f2528
 AC_SUBST([K5LIBS])
8f2528
 
8f2528
+# Check whether user wants systemd support
8f2528
+SYSTEMD_MSG="no"
8f2528
+AC_ARG_WITH(systemd,
8f2528
+	[  --with-systemd          Enable systemd support],
8f2528
+	[ if test "x$withval" != "xno" ; then
8f2528
+		AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
8f2528
+		if test "$PKGCONFIG" != "no"; then
8f2528
+			AC_MSG_CHECKING([for libsystemd])
8f2528
+			if $PKGCONFIG --exists libsystemd; then
8f2528
+				SYSTEMD_CFLAGS=`$PKGCONFIG --cflags libsystemd`
8f2528
+				SYSTEMD_LIBS=`$PKGCONFIG --libs libsystemd`
8f2528
+				CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
8f2528
+				SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
8f2528
+				AC_MSG_RESULT([yes])
8f2528
+				AC_DEFINE(HAVE_SYSTEMD, 1, [Define if you want systemd support.])
8f2528
+				SYSTEMD_MSG="yes"
8f2528
+			else
8f2528
+				AC_MSG_RESULT([no])
8f2528
+			fi
8f2528
+		fi
8f2528
+	fi ]
8f2528
+)
8f2528
+
8f2528
+
8f2528
 # Looking for programs, paths and files
8f2528
 
8f2528
 PRIVSEP_PATH=/var/empty
8f2528
@@ -5097,6 +5121,7 @@ echo "                   libedit support: $LIBEDIT_MSG"
8f2528
 echo "  Solaris process contract support: $SPC_MSG"
8f2528
 echo "           Solaris project support: $SP_MSG"
8f2528
 echo "         Solaris privilege support: $SPP_MSG"
8f2528
+echo "                   systemd support: $SYSTEMD_MSG"
8f2528
 echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
8f2528
 echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
8f2528
 echo "                  BSD Auth support: $BSD_AUTH_MSG"
8f2528
diff --git a/contrib/sshd.service b/contrib/sshd.service
8f2528
new file mode 100644
8f2528
index 0000000..e0d4923
8f2528
--- /dev/null
8f2528
+++ b/contrib/sshd.service
8f2528
@@ -0,0 +1,16 @@
8f2528
+[Unit]
8f2528
+Description=OpenSSH server daemon
8f2528
+Documentation=man:sshd(8) man:sshd_config(5)
8f2528
+After=network.target
8f2528
+
8f2528
+[Service]
8f2528
+Type=notify
8f2528
+ExecStart=/usr/sbin/sshd -D $OPTIONS
8f2528
+ExecReload=/bin/kill -HUP $MAINPID
8f2528
+KillMode=process
8f2528
+Restart=on-failure
8f2528
+RestartPreventExitStatus=255
8f2528
+
8f2528
+[Install]
8f2528
+WantedBy=multi-user.target
8f2528
+
8f2528
diff --git a/sshd.c b/sshd.c
8f2528
index 816611c..b8b9d13 100644
8f2528
--- a/sshd.c
8f2528
+++ b/sshd.c
8f2528
@@ -85,6 +85,10 @@
8f2528
 #include <prot.h>
8f2528
 #endif
8f2528
 
8f2528
+#ifdef HAVE_SYSTEMD
8f2528
+#include <systemd/sd-daemon.h>
8f2528
+#endif
8f2528
+
8f2528
 #include "xmalloc.h"
8f2528
 #include "ssh.h"
8f2528
 #include "ssh2.h"
8f2528
@@ -1833,6 +1837,11 @@ main(int ac, char **av)
8f2528
 			}
8f2528
 		}
8f2528
 
8f2528
+#ifdef HAVE_SYSTEMD
8f2528
+	/* Signal systemd that we are ready to accept connections */
8f2528
+	sd_notify(0, "READY=1");
8f2528
+#endif
8f2528
+
8f2528
 		/* Accept a connection and return in a forked child */
8f2528
 		server_accept_loop(&sock_in, &sock_out,
8f2528
 		    &newsock, config_s);