rutwa189 / rpms / openssh

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