rcolebaugh / rpms / openssh

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