diff options
| author | Quentin Young <qlyoung@users.noreply.github.com> | 2021-07-06 14:54:25 +0000 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-06 14:54:25 +0000 | 
| commit | e15106149fda3b3c915d14a2fc6b749598a73b6c (patch) | |
| tree | 23c519d61c2155056803cc8e7de10cdaafa93d25 | |
| parent | acb4c44ef8da8c1a155184a809647533237adca9 (diff) | |
| parent | ab140d61cdd04db03ef597f645e601429396d3c8 (diff) | |
Merge pull request #8508 from opensourcerouting/systemd-no-lib
28 files changed, 151 insertions, 163 deletions
diff --git a/alpine/APKBUILD.in b/alpine/APKBUILD.in index dfedf0b52b..e6776cb3a2 100644 --- a/alpine/APKBUILD.in +++ b/alpine/APKBUILD.in @@ -41,7 +41,6 @@ build() {  		--sysconfdir=$_sysconfdir \  		--libdir=$_libdir \  		--localstatedir=$_localstatedir \ -		--enable-systemd=no \  		--enable-rpki \  		--enable-vtysh \  		--enable-multipath=64 \ diff --git a/configure.ac b/configure.ac index 6108a37522..a23011b755 100644 --- a/configure.ac +++ b/configure.ac @@ -672,8 +672,6 @@ AC_ARG_ENABLE([fpm],    AS_HELP_STRING([--enable-fpm], [enable Forwarding Plane Manager support]))  AC_ARG_ENABLE([pcep],    AS_HELP_STRING([--enable-pcep], [enable PCEP support for pathd])) -AC_ARG_ENABLE([systemd], -  AS_HELP_STRING([--enable-systemd], [enable Systemd support]))  AC_ARG_ENABLE([werror],    AS_HELP_STRING([--enable-werror], [enable -Werror (recommended for developers only)]))  AC_ARG_ENABLE([cumulus], @@ -768,19 +766,6 @@ case "${enable_cpu_time}" in    ;;  esac -case "${enable_systemd}" in -  "no") ;; -  "yes") -  AC_CHECK_LIB([systemd], [sd_notify], [LIBS="$LIBS -lsystemd"]) -  if test "$ac_cv_lib_systemd_sd_notify" = "no"; then -    AC_MSG_ERROR([enable systemd has been specified but systemd development env not found on your system]) -  else -    AC_DEFINE([HAVE_SYSTEMD], [1], [Compile systemd support in]) -  fi -  ;; -  "*") ;; -esac -  if test "$enable_rr_semantics" != "no" ; then    AC_DEFINE([HAVE_V6_RR_SEMANTICS], [1], [Compile in v6 Route Replacement Semantics])  fi diff --git a/debian/README.Debian b/debian/README.Debian index a23a0efcac..53fb6c9d0e 100644 --- a/debian/README.Debian +++ b/debian/README.Debian @@ -31,10 +31,6 @@ The following Build Profiles have been added:    controls whether the RPKI module is built.    Will be enabled by default at some point, adds some extra dependencies. -- pkg.frr.nosystemd -  Disables both systemd unit file installation as well as watchfrr sd_notify -  support at startup.  Removes libsystemd dependency. -  Note that all options have a "no" form;  if you want to have your decision  be sticky regardless of changes to what it defaults to, then always use one  of the two.  For example, all occurrences of <pkg.frr.rtrlib> will at some @@ -43,10 +39,6 @@ point be replaced with <!pkg.frr.nortrlib>.  The main frr package has the exact same contents regardless of rtrlib or snmp  choices.  The options only control frr-snmp and frr-rpki-rtrlib packages. -The main frr package does NOT have the same contents if pkg.frr.nosystemd is -used.  This option should only be used for systems that do not have systemd, -e.g. Ubuntu 14.04. -  * Debian Policy compliance notes  ================================ diff --git a/debian/control b/debian/control index 0bbe99b312..0e67ff3730 100644 --- a/debian/control +++ b/debian/control @@ -22,7 +22,6 @@ Build-Depends: bison,                 librtr-dev <!pkg.frr.nortrlib>,                 libsnmp-dev,                 libssh-dev <!pkg.frr.nortrlib>, -               libsystemd-dev <!pkg.frr.nosystemd>,                 libyang2-dev,                 lsb-base,                 pkg-config, diff --git a/debian/rules b/debian/rules index 93d0cdb2a0..0fa9c3a3b0 100755 --- a/debian/rules +++ b/debian/rules @@ -21,14 +21,6 @@ else    CONF_RPKI=--disable-rpki  endif -ifeq ($(filter pkg.frr.nosystemd,$(DEB_BUILD_PROFILES)),) -  DH_WITHOUT_SYSTEMD= -  CONF_SYSTEMD=--enable-systemd=yes -else -  DH_WITHOUT_SYSTEMD=--without=systemd -  CONF_SYSTEMD=--enable-systemd=no -endif -  ifeq ($(filter pkg.frr.lua,$(DEB_BUILD_PROFILES)),)    CONF_LUA=--disable-scripting  else @@ -38,7 +30,7 @@ endif  export PYTHON=python3  %: -	dh $@ $(DH_WITHOUT_SYSTEMD) +	dh $@  override_dh_auto_configure:  	$(shell dpkg-buildflags --export=sh); \ @@ -52,7 +44,6 @@ override_dh_auto_configure:  		LIBTOOLFLAGS="-rpath /usr/lib/$(DEB_HOST_MULTIARCH)/frr" \  		--disable-dependency-tracking \  		\ -		$(CONF_SYSTEMD) \  		$(CONF_RPKI) \  		$(CONF_LUA) \  		--with-libpam \ @@ -80,9 +71,7 @@ override_dh_auto_install:  	sed -e '1c #!/usr/bin/python3' -i debian/tmp/usr/lib/frr/generate_support_bundle.py  # let dh_systemd_* and dh_installinit do their thing automatically -ifeq ($(filter pkg.frr.nosystemd,$(DEB_BUILD_PROFILES)),)  	cp tools/frr.service debian/frr.service -endif  	cp tools/frrinit.sh debian/frr.init  	-rm -f debian/tmp/usr/lib/frr/frr diff --git a/doc/developer/building-frr-for-archlinux.rst b/doc/developer/building-frr-for-archlinux.rst index e589a9f724..af1677e89e 100644 --- a/doc/developer/building-frr-for-archlinux.rst +++ b/doc/developer/building-frr-for-archlinux.rst @@ -10,8 +10,8 @@ Installing Dependencies     sudo pacman -S \        git autoconf automake libtool make cmake pcre readline texinfo \        pkg-config pam json-c bison flex python-pytest \ -      c-ares python systemd python2-ipaddress python-sphinx \ -      systemd-libs net-snmp perl libcap libelf +      c-ares python python2-ipaddress python-sphinx \ +      net-snmp perl libcap libelf  .. include:: building-libyang.rst diff --git a/doc/developer/building-frr-for-centos7.rst b/doc/developer/building-frr-for-centos7.rst index 93b9993a38..ce11126f70 100644 --- a/doc/developer/building-frr-for-centos7.rst +++ b/doc/developer/building-frr-for-centos7.rst @@ -21,7 +21,7 @@ Add packages:      sudo yum install git autoconf automake libtool make \        readline-devel texinfo net-snmp-devel groff pkgconfig \        json-c-devel pam-devel bison flex pytest c-ares-devel \ -      python-devel systemd-devel python-sphinx libcap-devel \ +      python-devel python-sphinx libcap-devel \        elfutils-libelf-devel  .. include:: building-libyang.rst @@ -66,7 +66,6 @@ an example.)          --enable-user=frr \          --enable-group=frr \          --enable-vty-group=frrvty \ -	--enable-systemd=yes \          --disable-ldpd \          --enable-fpm \          --with-pkg-git-version \ diff --git a/doc/developer/building-frr-for-centos8.rst b/doc/developer/building-frr-for-centos8.rst index 65c93286b7..109a7866d9 100644 --- a/doc/developer/building-frr-for-centos8.rst +++ b/doc/developer/building-frr-for-centos8.rst @@ -14,7 +14,7 @@ Add packages:      sudo dnf install --enablerepo=PowerTools git autoconf pcre-devel \        automake libtool make readline-devel texinfo net-snmp-devel pkgconfig \        groff pkgconfig json-c-devel pam-devel bison flex python2-pytest \ -      c-ares-devel python2-devel systemd-devel libcap-devel \ +      c-ares-devel python2-devel libcap-devel \        elfutils-libelf-devel  .. include:: building-libyang.rst @@ -59,7 +59,6 @@ an example.)          --enable-user=frr \          --enable-group=frr \          --enable-vty-group=frrvty \ -	--enable-systemd=yes \          --disable-ldpd \          --enable-fpm \          --with-pkg-git-version \ diff --git a/doc/developer/building-frr-for-debian8.rst b/doc/developer/building-frr-for-debian8.rst index 475e0303fc..5e58854ed7 100644 --- a/doc/developer/building-frr-for-debian8.rst +++ b/doc/developer/building-frr-for-debian8.rst @@ -17,7 +17,7 @@ Add packages:     sudo apt-get install git autoconf automake libtool make \        libreadline-dev texinfo libjson-c-dev pkg-config bison flex python3-pip \ -      libc-ares-dev python3-dev python3-sphinx build-essential libsystemd-dev \ +      libc-ares-dev python3-dev python3-sphinx build-essential \        libsnmp-dev libcap-dev libelf-dev  Install newer pytest (>3.0) from pip diff --git a/doc/developer/building-frr-for-debian9.rst b/doc/developer/building-frr-for-debian9.rst index 1981127b3d..f8d8025f62 100644 --- a/doc/developer/building-frr-for-debian9.rst +++ b/doc/developer/building-frr-for-debian9.rst @@ -11,7 +11,7 @@ Add packages:     sudo apt-get install git autoconf automake libtool make \       libreadline-dev texinfo libjson-c-dev pkg-config bison flex \       libc-ares-dev python3-dev python3-pytest python3-sphinx build-essential \ -     libsnmp-dev libsystemd-dev libcap-dev libelf-dev +     libsnmp-dev libcap-dev libelf-dev  .. include:: building-libyang.rst diff --git a/doc/developer/building-frr-for-fedora.rst b/doc/developer/building-frr-for-fedora.rst index 5fecd8a826..6ce76ba158 100644 --- a/doc/developer/building-frr-for-fedora.rst +++ b/doc/developer/building-frr-for-fedora.rst @@ -14,7 +14,7 @@ Installing Dependencies     sudo dnf install git autoconf automake libtool make \       readline-devel texinfo net-snmp-devel groff pkgconfig json-c-devel \       pam-devel python3-pytest bison flex c-ares-devel python3-devel \ -     python3-sphinx perl-core patch systemd-devel libcap-devel \ +     python3-sphinx perl-core patch libcap-devel \       elfutils-libelf-devel  .. include:: building-libyang.rst diff --git a/doc/developer/building-frr-for-opensuse.rst b/doc/developer/building-frr-for-opensuse.rst index 4e886e9c25..ee6a36a14b 100644 --- a/doc/developer/building-frr-for-opensuse.rst +++ b/doc/developer/building-frr-for-opensuse.rst @@ -13,7 +13,7 @@ Installing Dependencies     zypper in  git autoconf automake libtool make   \       readline-devel texinfo net-snmp-devel groff pkgconfig libjson-c-devel\       pam-devel python3-pytest bison flex c-ares-devel python3-devel\ -     python3-Sphinx perl patch systemd-devel libcap-devel libyang-devel \ +     python3-Sphinx perl patch libcap-devel libyang-devel \       libelf-devel  Building & Installing FRR diff --git a/doc/developer/building-frr-for-ubuntu1604.rst b/doc/developer/building-frr-for-ubuntu1604.rst index 2cb9536f9b..d79545c859 100644 --- a/doc/developer/building-frr-for-ubuntu1604.rst +++ b/doc/developer/building-frr-for-ubuntu1604.rst @@ -13,8 +13,8 @@ Installing Dependencies     apt-get install \        git autoconf automake libtool make libreadline-dev texinfo \        pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \ -      libc-ares-dev python3-dev libsystemd-dev python-ipaddress python3-sphinx \ -      install-info build-essential libsystemd-dev libsnmp-dev perl libcap-dev \ +      libc-ares-dev python3-dev python-ipaddress python3-sphinx \ +      install-info build-essential libsnmp-dev perl libcap-dev \        libelf-dev  .. include:: building-libyang.rst diff --git a/doc/developer/building-frr-for-ubuntu1804.rst b/doc/developer/building-frr-for-ubuntu1804.rst index eb3991c139..39a17fc01c 100644 --- a/doc/developer/building-frr-for-ubuntu1804.rst +++ b/doc/developer/building-frr-for-ubuntu1804.rst @@ -13,8 +13,8 @@ Installing Dependencies     sudo apt-get install \        git autoconf automake libtool make libreadline-dev texinfo \        pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \ -      libc-ares-dev python3-dev libsystemd-dev python-ipaddress python3-sphinx \ -      install-info build-essential libsystemd-dev libsnmp-dev perl libcap-dev \ +      libc-ares-dev python3-dev python-ipaddress python3-sphinx \ +      install-info build-essential libsnmp-dev perl libcap-dev \        libelf-dev  .. include:: building-libyang.rst diff --git a/doc/developer/building-frr-for-ubuntu2004.rst b/doc/developer/building-frr-for-ubuntu2004.rst index 58d72e2891..92ddead4a5 100644 --- a/doc/developer/building-frr-for-ubuntu2004.rst +++ b/doc/developer/building-frr-for-ubuntu2004.rst @@ -13,8 +13,8 @@ Installing Dependencies     sudo apt-get install \        git autoconf automake libtool make libreadline-dev texinfo \        pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \ -      libc-ares-dev python3-dev libsystemd-dev python-ipaddress python3-sphinx \ -      install-info build-essential libsystemd-dev libsnmp-dev perl \ +      libc-ares-dev python3-dev python-ipaddress python3-sphinx \ +      install-info build-essential libsnmp-dev perl \        libcap-dev python2 libelf-dev  Note that Ubuntu 20 no longer installs python 2.x, so it must be diff --git a/doc/developer/include-compile.rst b/doc/developer/include-compile.rst index d9fa260221..513cac6179 100644 --- a/doc/developer/include-compile.rst +++ b/doc/developer/include-compile.rst @@ -2,11 +2,6 @@ Clone the FRR git repo and use the included ``configure`` script to configure  FRR's build time options to your liking. The full option listing can be  obtained by running ``./configure -h``. The options shown below are examples. -.. note:: - -   If your platform uses ``systemd``, please make sure to add -   ``--enable-systemd=yes`` to your configure options. -  .. code-block:: console     git clone https://github.com/frrouting/frr.git frr diff --git a/doc/developer/packaging-debian.rst b/doc/developer/packaging-debian.rst index 968e960267..a81e052490 100644 --- a/doc/developer/packaging-debian.rst +++ b/doc/developer/packaging-debian.rst @@ -53,7 +53,7 @@ buster.)     Where `$options` may contain any or all of the following items:     * build profiles specified with ``-P``, e.g. -     ``-Ppkg.frr.nortrlib,pkg.frr.nosystemd``. +     ``-Ppkg.frr.nortrlib,pkg.frr.rtrlib``.       Multiple values are separated by commas and there must not be a space       after the ``-P``. @@ -64,14 +64,6 @@ buster.)       +================+===================+=========================================+       | pkg.frr.rtrlib | pkg.frr.nortrlib  | builds frr-rpki-rtrlib package (or not) |       +----------------+-------------------+-----------------------------------------+ -     | n/a            | pkg.frr.nosystemd | removes libsystemd dependency and       | -     |                |                   | disables unit file installation         | -     +----------------+-------------------+-----------------------------------------+ - -     .. note:: - -        The ``pkg.frr.nosystemd`` option is only intended to support Ubuntu -        14.04 (and should be enabled when building for that.)     * the ``-uc -us`` options to disable signing the packages with your GPG key diff --git a/doc/developer/packaging-redhat.rst b/doc/developer/packaging-redhat.rst index 458cfa0ad4..9e64b912f3 100644 --- a/doc/developer/packaging-redhat.rst +++ b/doc/developer/packaging-redhat.rst @@ -18,10 +18,6 @@ Tested on CentOS 6, CentOS 7, CentOS 8 and Fedora 24.        yum install rpm-build net-snmp-devel pam-devel libcap-devel -   If your platform uses systemd:: - -      yum install systemd-devel -     For CentOS 7 and CentOS 8, the package will be built using python3     and requires additional python3 packages:: diff --git a/doc/user/installation.rst b/doc/user/installation.rst index 63254555d9..fdf5bab9c9 100644 --- a/doc/user/installation.rst +++ b/doc/user/installation.rst @@ -146,11 +146,6 @@ options from the list below.     software available on your machine.  This is needed for systemd integration, if you     disable watchfrr you cannot have any systemd integration. -.. option:: --enable-systemd - -   Build watchfrr with systemd integration, this will allow FRR to communicate with -   systemd to tell systemd if FRR has come up properly. -  .. option:: --enable-werror     Build with all warnings converted to errors as a compile option.  This @@ -404,6 +399,12 @@ options to the configuration script.     Set StrongSWAN vici interface socket path [/var/run/charon.vici]. +.. note:: + +   The former ``--enable-systemd`` option does not exist anymore.  Support for +   systemd is now always available through built-in functions, without +   depending on libsystemd. +  Python dependency, documentation and tests  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docker/centos-7/Dockerfile b/docker/centos-7/Dockerfile index 303a33fe4a..73097df8fa 100644 --- a/docker/centos-7/Dockerfile +++ b/docker/centos-7/Dockerfile @@ -4,7 +4,7 @@ RUN yum install -y epel-release  RUN yum install -y rpm-build autoconf automake libtool make \          readline-devel texinfo net-snmp-devel groff pkgconfig \          json-c-devel pam-devel bison flex pytest c-ares-devel \ -        python3-devel python3-sphinx systemd-devel libcap-devel \ +        python3-devel python3-sphinx libcap-devel \          https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-7-x86_64-Packages/libyang2-2.0.0.10.g2eb910e4-1.el7.x86_64.rpm \          https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-7-x86_64-Packages/libyang2-devel-2.0.0.10.g2eb910e4-1.el7.x86_64.rpm \          https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-0.7.0-1.el7.centos.x86_64.rpm \ diff --git a/docker/centos-8/Dockerfile b/docker/centos-8/Dockerfile index 8a0c28e13b..71378c2451 100644 --- a/docker/centos-8/Dockerfile +++ b/docker/centos-8/Dockerfile @@ -4,7 +4,7 @@ FROM centos:centos8 as centos-8-builder  RUN dnf install --enablerepo=powertools -y rpm-build git autoconf pcre-devel \          automake libtool make readline-devel texinfo net-snmp-devel pkgconfig \          groff pkgconfig json-c-devel pam-devel bison flex python3-pytest \ -        c-ares-devel python3-devel python3-sphinx systemd-devel libcap-devel platform-python-devel \ +        c-ares-devel python3-devel python3-sphinx libcap-devel platform-python-devel \          https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-8-x86_64-Packages/libyang2-2.0.0.10.g2eb910e4-1.el8.x86_64.rpm \          https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-8-x86_64-Packages/libyang2-devel-2.0.0.10.g2eb910e4-1.el8.x86_64.rpm \          https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-0.7.0-1.el7.centos.x86_64.rpm \ diff --git a/docker/ubuntu18-ci/Dockerfile b/docker/ubuntu18-ci/Dockerfile index 680b9172ad..766f06dfc2 100644 --- a/docker/ubuntu18-ci/Dockerfile +++ b/docker/ubuntu18-ci/Dockerfile @@ -7,8 +7,8 @@ RUN apt update && \      apt-get install -y \        git autoconf automake libtool make libreadline-dev texinfo \        pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \ -      libc-ares-dev python3-dev libsystemd-dev python-ipaddress python3-sphinx \ -      install-info build-essential libsystemd-dev libsnmp-dev perl libcap-dev \ +      libc-ares-dev python3-dev python-ipaddress python3-sphinx \ +      install-info build-essential libsnmp-dev perl libcap-dev \        libelf-dev \        sudo gdb iputils-ping time \        mininet python-pip iproute2 iperf && \ diff --git a/docker/ubuntu20-ci/Dockerfile b/docker/ubuntu20-ci/Dockerfile index 47d5b81d3a..b5df98f23e 100644 --- a/docker/ubuntu20-ci/Dockerfile +++ b/docker/ubuntu20-ci/Dockerfile @@ -7,8 +7,8 @@ RUN apt update && \      apt-get install -y \        git autoconf automake libtool make libreadline-dev texinfo \        pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \ -      libc-ares-dev python3-dev libsystemd-dev python-ipaddress python3-sphinx \ -      install-info build-essential libsystemd-dev libsnmp-dev perl \ +      libc-ares-dev python3-dev python-ipaddress python3-sphinx \ +      install-info build-essential libsnmp-dev perl \        libcap-dev python2 libelf-dev \        sudo gdb curl iputils-ping time \        libgrpc++-dev libgrpc-dev protobuf-compiler-grpc \ diff --git a/lib/libfrr.c b/lib/libfrr.c index 0817182f7a..97dab74d9b 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -44,6 +44,7 @@  #include "frr_pthread.h"  #include "defaults.h"  #include "frrscript.h" +#include "systemd.h"  DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm));  DEFINE_HOOK(frr_config_pre, (struct thread_master * tm), (tm)); @@ -363,6 +364,11 @@ void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv)  		startup_fds |= UINT64_C(0x1) << (uint64_t)i;  	} + +	/* note this doesn't do anything, it just grabs state, so doing it +	 * early in _preinit is perfect. +	 */ +	systemd_init_env();  }  bool frr_is_startup_fd(int fd) diff --git a/lib/systemd.c b/lib/systemd.c index c5cc3aa447..7944c2493b 100644 --- a/lib/systemd.c +++ b/lib/systemd.c @@ -20,68 +20,56 @@   */  #include <zebra.h> +#include <sys/un.h>  #include "thread.h"  #include "systemd.h" +#include "lib_errors.h" -#if defined HAVE_SYSTEMD -#include <systemd/sd-daemon.h> -#endif +/* these are cleared from env so they don't "leak" into things we fork(), + * particularly for watchfrr starting individual daemons + * + * watchdog_pid is currently not used since watchfrr starts forking. + * (TODO: handle that better, somehow?) + */ +static pid_t watchdog_pid = -1; +static intmax_t watchdog_msec; + +/* not used yet, but can trigger auto-switch to journald logging */ +bool sd_stdout_is_journal; +bool sd_stderr_is_journal; + +static char *notify_socket; -/* - * Wrapper this silliness if we - * don't have systemd +/* talk to whatever entity claims to be systemd ;) + * + * refer to sd_notify docs for messages systemd accepts over this socket. + * This function should be functionally equivalent to sd_notify().   */  static void systemd_send_information(const char *info)  { -#if defined HAVE_SYSTEMD -	sd_notify(0, info); -#else -	return; -#endif -} +	int sock; +	struct sockaddr_un sun; -/* - * A return of 0 means that we are not watchdoged - */ -static int systemd_get_watchdog_time(int the_process) -{ -#if defined HAVE_SYSTEMD -	uint64_t usec; -	char *watchdog = NULL; -	int ret; - -	ret = sd_watchdog_enabled(0, &usec); - -	/* -	 * If return is 0 -> we don't want watchdog -	 * if return is < 0, some sort of failure occurred -	 */ -	if (ret < 0) -		return 0; - -	/* -	 * systemd can return that this process -	 * is not the expected sender of the watchdog timer -	 * If we set the_process = 0 then we expect to -	 * be able to send the watchdog to systemd -	 * irrelevant of the pid of this process. -	 */ -	if (ret == 0 && the_process) -		return 0; - -	if (ret == 0 && !the_process) { -		watchdog = getenv("WATCHDOG_USEC"); -		if (!watchdog) -			return 0; - -		usec = atol(watchdog); -	} +	if (!notify_socket) +		return; + +	sock = socket(AF_UNIX, SOCK_DGRAM, 0); +	if (sock < 0) +		return; + +	sun.sun_family = AF_UNIX; +	strlcpy(sun.sun_path, notify_socket, sizeof(sun.sun_path)); -	return (usec / 1000000) / 3; -#else -	return 0; -#endif +	/* linux abstract unix socket namespace */ +	if (sun.sun_path[0] == '@') +		sun.sun_path[0] = '\0'; + +	/* nothing we can do if this errors out... */ +	sendto(sock, info, strlen(info), 0, (struct sockaddr *)&sun, +	       sizeof(sun)); + +	close(sock);  }  void systemd_send_stopping(void) @@ -90,34 +78,27 @@ void systemd_send_stopping(void)  	systemd_send_information("STOPPING=1");  } -/* - * How many seconds should we wait between watchdog sends - */ -static int wsecs = 0;  static struct thread_master *systemd_master = NULL;  static int systemd_send_watchdog(struct thread *t)  {  	systemd_send_information("WATCHDOG=1"); -	thread_add_timer(systemd_master, systemd_send_watchdog, NULL, wsecs, -			 NULL); - +	assert(watchdog_msec > 0); +	thread_add_timer_msec(systemd_master, systemd_send_watchdog, NULL, +			      watchdog_msec, NULL);  	return 1;  } -void systemd_send_started(struct thread_master *m, int the_process) +void systemd_send_started(struct thread_master *m)  {  	assert(m != NULL); -	wsecs = systemd_get_watchdog_time(the_process);  	systemd_master = m;  	systemd_send_information("READY=1"); -	if (wsecs != 0) { -		systemd_send_information("WATCHDOG=1"); -		thread_add_timer(m, systemd_send_watchdog, m, wsecs, NULL); -	} +	if (watchdog_msec > 0) +		systemd_send_watchdog(NULL);  }  void systemd_send_status(const char *status) @@ -127,3 +108,65 @@ void systemd_send_status(const char *status)  	snprintf(buffer, sizeof(buffer), "STATUS=%s", status);  	systemd_send_information(buffer);  } + +static intmax_t getenv_int(const char *varname, intmax_t dflt) +{ +	char *val, *err; +	intmax_t intval; + +	val = getenv(varname); +	if (!val) +		return dflt; + +	intval = strtoimax(val, &err, 0); +	if (*err || !*val) +		return dflt; +	return intval; +} + +void systemd_init_env(void) +{ +	char *tmp; +	uintmax_t dev, ino; +	int len; +	struct stat st; + +	notify_socket = getenv("NOTIFY_SOCKET"); + +	/* no point in setting up watchdog w/o notify socket */ +	if (notify_socket) { +		intmax_t watchdog_usec; + +		watchdog_pid = getenv_int("WATCHDOG_PID", -1); +		if (watchdog_pid <= 0) +			watchdog_pid = -1; + +		/* note this is the deadline, hence the divide by 3 */ +		watchdog_usec = getenv_int("WATCHDOG_USEC", 0); +		if (watchdog_usec >= 3000) +			watchdog_msec = watchdog_usec / 3000; +		else { +			if (watchdog_usec != 0) +				flog_err( +					EC_LIB_UNAVAILABLE, +					"systemd expects a %jd microsecond watchdog timer, but FRR only supports millisecond resolution!", +					watchdog_usec); +			watchdog_msec = 0; +		} +	} + +	tmp = getenv("JOURNAL_STREAM"); +	if (tmp && sscanf(tmp, "%ju:%ju%n", &dev, &ino, &len) == 2 +	    && (size_t)len == strlen(tmp)) { +		if (fstat(1, &st) == 0 && st.st_dev == (dev_t)dev +		    && st.st_ino == (ino_t)ino) +			sd_stdout_is_journal = true; +		if (fstat(2, &st) == 0 && st.st_dev == (dev_t)dev +		    && st.st_ino == (ino_t)ino) +			sd_stderr_is_journal = true; +	} + +	/* these should *not* be passed to any other process we start */ +	unsetenv("WATCHDOG_PID"); +	unsetenv("WATCHDOG_USEC"); +} diff --git a/lib/systemd.h b/lib/systemd.h index d9885c5d9c..1933f4f688 100644 --- a/lib/systemd.h +++ b/lib/systemd.h @@ -28,9 +28,6 @@ extern "C" {   *   * Design point is that if systemd is not being used on this system   * then these functions becomes a no-op. - * - * To turn on systemd compilation, use --enable-systemd on - * configure run.   */  void systemd_send_stopping(void); @@ -39,13 +36,18 @@ void systemd_send_stopping(void);   *  the_process - Should we send watchdog if we are not the requested   *                process?   */ -void systemd_send_started(struct thread_master *master, int the_process); +void systemd_send_started(struct thread_master *master);  /*   * status - A status string to send to systemd   */  void systemd_send_status(const char *status); +/* + * grab startup state from env vars + */ +void systemd_init_env(void); +  #ifdef __cplusplus  }  #endif diff --git a/redhat/frr.spec.in b/redhat/frr.spec.in index e24a84d1e4..fbe4c4a1f1 100644 --- a/redhat/frr.spec.in +++ b/redhat/frr.spec.in @@ -199,8 +199,6 @@ Requires:       initscripts  BuildRequires:  pam-devel  %endif  %if "%{initsystem}" == "systemd" -BuildRequires:      systemd -BuildRequires:      systemd-devel  Requires(post):     systemd  Requires(preun):    systemd  Requires(postun):   systemd @@ -396,9 +394,6 @@ routing state through standard SNMP MIBs.      --disable-bgp-vnc \  %endif      --enable-isisd \ -%if "%{initsystem}" == "systemd" -    --enable-systemd \ -%endif      --enable-rpki \  %if %{with_bfdd}      --enable-bfdd \ diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c index faf1777d7f..d0b4be81d4 100644 --- a/watchfrr/watchfrr.c +++ b/watchfrr/watchfrr.c @@ -469,12 +469,10 @@ static int run_job(struct restart_info *restart, const char *cmdtype,  		return -1;  	} -#if defined HAVE_SYSTEMD  	char buffer[512];  	snprintf(buffer, sizeof(buffer), "restarting %s", restart->name);  	systemd_send_status(buffer); -#endif  	/* Note: time_elapsed test must come before the force test, since we  	   need @@ -506,9 +504,8 @@ static int run_job(struct restart_info *restart, const char *cmdtype,  			restart->pid = 0;  	} -#if defined HAVE_SYSTEMD  	systemd_send_status("FRR Operational"); -#endif +  	/* Calculate the new restart interval. */  	if (update_interval) {  		if (delay.tv_sec > 2 * gs.max_restart_interval) @@ -718,10 +715,9 @@ static void daemon_send_ready(int exitcode)  	fp = fopen(started, "w");  	if (fp)  		fclose(fp); -#if defined HAVE_SYSTEMD -	systemd_send_started(master, 0); + +	systemd_send_started(master);  	systemd_send_status("FRR Operational"); -#endif  	sent = 1;  }  | 
