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