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