1 From be187435911cde6cc3cef6982a508261074f1e56 Mon Sep 17 00:00:00 2001
2 From: Matt Jolly <Matt.Jolly@footclan.ninja>
3 Date: Thu, 2 Feb 2023 21:05:40 +1100
4 Subject: [PATCH] systemd: Add optional support for systemd `sd_notify`
6 This is a rebase of Dennis Lamm's <expeditioneer@gentoo.org>
7 patch based on Jakub Jelen's <jjelen@redhat.com> original patch
9 Upstream-Status: Submitted [https://github.com/openssh/openssh-portable/pull/375/commits/be187435911cde6cc3cef6982a508261074f1e56]
11 Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com>
13 configure.ac | 24 ++++++++++++++++++++++++
14 sshd.c | 13 +++++++++++++
15 2 files changed, 37 insertions(+)
17 diff --git a/configure.ac b/configure.ac
18 index 22fee70f..486c189f 100644
21 @@ -4835,6 +4835,29 @@ AC_SUBST([GSSLIBS])
23 AC_SUBST([CHANNELLIBS])
25 +# Check whether user wants systemd support
28 + [ --with-systemd Enable systemd support],
29 + [ if test "x$withval" != "xno" ; then
30 + AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
31 + if test "$PKGCONFIG" != "no"; then
32 + AC_MSG_CHECKING([for libsystemd])
33 + if $PKGCONFIG --exists libsystemd; then
34 + SYSTEMD_CFLAGS=`$PKGCONFIG --cflags libsystemd`
35 + SYSTEMD_LIBS=`$PKGCONFIG --libs libsystemd`
36 + CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
37 + SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
38 + AC_MSG_RESULT([yes])
39 + AC_DEFINE(HAVE_SYSTEMD, 1, [Define if you want systemd support.])
48 # Looking for programs, paths and files
50 PRIVSEP_PATH=/var/empty
51 @@ -5634,6 +5657,7 @@ echo " libldns support: $LDNS_MSG"
52 echo " Solaris process contract support: $SPC_MSG"
53 echo " Solaris project support: $SP_MSG"
54 echo " Solaris privilege support: $SPP_MSG"
55 +echo " systemd support: $SYSTEMD_MSG"
56 echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
57 echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
58 echo " BSD Auth support: $BSD_AUTH_MSG"
59 diff --git a/sshd.c b/sshd.c
60 index 6321936c..859d6a0b 100644
68 +#include <systemd/sd-daemon.h>
74 @@ -310,6 +314,10 @@ static void
77 logit("Received SIGHUP; restarting.");
79 + /* Signal systemd that we are reloading */
80 + sd_notify(0, "RELOADING=1");
82 if (options.pid_file != NULL)
83 unlink(options.pid_file);
84 platform_pre_restart();
85 @@ -2086,6 +2094,11 @@ main(int ac, char **av)
90 + /* Signal systemd that we are ready to accept connections */
91 + sd_notify(0, "READY=1");
94 /* Accept a connection and return in a forked child */
95 server_accept_loop(&sock_in, &sock_out,