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