build: homologize path handling

Use consistent `e_somepath` names for expanded versions of `somepath`.
Also remove all paths from `config.h` and put them into
`lib/config_paths.h` - this is to make more obvious when someone is
doing something probably not quite properly structured.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2024-01-25 20:29:14 +01:00
parent f1ad2c4631
commit bbd858935f
24 changed files with 93 additions and 60 deletions

View file

@ -56,7 +56,7 @@ MODULE_LDFLAGS = \
$(SAN_FLAGS) \ $(SAN_FLAGS) \
# end # end
DEFS = @DEFS@ -DSYSCONFDIR=\"$(CFG_SYSCONF)/\" -DCONFDATE=$(CONFDATE) DEFS = @DEFS@ -DCONFDATE=$(CONFDATE)
AR_FLAGS = @AR_FLAGS@ AR_FLAGS = @AR_FLAGS@
ARFLAGS = @ARFLAGS@ ARFLAGS = @ARFLAGS@

View file

@ -2715,31 +2715,26 @@ fi
AC_SUBST([CONFDATE]) AC_SUBST([CONFDATE])
dnl get the full path, recursing through variables... dnl get the full path, recursing through variables...
AX_RECURSIVE_EVAL([$bindir/vtysh], [vtysh_bin]) AC_DEFUN([AX_SUBST_EXPANDED], [
AX_RECURSIVE_EVAL([$frr_sysconfdir], [CFG_SYSCONF]) AX_RECURSIVE_EVAL([[$]$1], [e_$1])
AX_RECURSIVE_EVAL([$sbindir], [CFG_SBIN]) AC_SUBST([e_$1])
AX_RECURSIVE_EVAL([$bindir], [CFG_BIN]) ])
AX_RECURSIVE_EVAL([$frr_runstatedir], [CFG_STATE])
AX_RECURSIVE_EVAL([$frr_libstatedir], [CFG_LIBSTATE]) AX_SUBST_EXPANDED([bindir])
AX_RECURSIVE_EVAL([$moduledir], [CFG_MODULE]) AX_SUBST_EXPANDED([sbindir])
AX_RECURSIVE_EVAL([$yangmodelsdir], [CFG_YANGMODELS]) AX_SUBST_EXPANDED([frr_sysconfdir])
AX_RECURSIVE_EVAL([$scriptdir], [CFG_SCRIPT]) AX_SUBST_EXPANDED([frr_runstatedir])
AC_SUBST([vtysh_bin]) AX_SUBST_EXPANDED([frr_libstatedir])
AC_SUBST([CFG_SYSCONF]) AX_SUBST_EXPANDED([moduledir])
AC_SUBST([CFG_SBIN]) AX_SUBST_EXPANDED([yangmodelsdir])
AC_SUBST([CFG_BIN]) AX_SUBST_EXPANDED([scriptdir])
AC_SUBST([CFG_STATE])
dnl AC_SUBST([CFG_LIBSTATE]) -- not currently used dnl strip duplicate trailing slashes if necessary
AC_SUBST([CFG_MODULE]) dnl note this uses e_bindir / e_sbindir created above
AC_SUBST([CFG_SCRIPT]) watchfrr_sh="\${e_sbindir%/}/watchfrr.sh"
AC_SUBST([CFG_YANGMODELS]) AX_SUBST_EXPANDED([watchfrr_sh])
AC_DEFINE_UNQUOTED([VTYSH_BIN_PATH], ["$vtysh_bin"], [path to vtysh binary]) vtysh_bin="\${e_bindir%/}/vtysh"
AC_DEFINE_UNQUOTED([MODULE_PATH], ["$CFG_MODULE"], [path to modules]) AX_SUBST_EXPANDED([vtysh_bin])
AC_DEFINE_UNQUOTED([SCRIPT_PATH], ["$CFG_SCRIPT"], [path to scripts])
AC_DEFINE_UNQUOTED([FRR_RUNSTATE_PATH], ["$CFG_STATE"], [/run/frr equivalent])
AC_DEFINE_UNQUOTED([FRR_LIBSTATE_PATH], ["$CFG_LIBSTATE"], [/var/lib/frr equivalent])
AC_DEFINE_UNQUOTED([YANG_MODELS_PATH], ["$CFG_YANGMODELS"], [path to YANG data models])
AC_DEFINE_UNQUOTED([WATCHFRR_SH_PATH], ["${CFG_SBIN%/}/watchfrr.sh"], [path to watchfrr.sh])
dnl various features dnl various features
AM_CONDITIONAL([SUPPORT_REALMS], [test "$enable_realms" = "yes"]) AM_CONDITIONAL([SUPPORT_REALMS], [test "$enable_realms" = "yes"])
@ -2811,6 +2806,7 @@ AC_CONFIG_FILES([
alpine/APKBUILD alpine/APKBUILD
snapcraft/snapcraft.yaml snapcraft/snapcraft.yaml
lib/version.h lib/version.h
lib/config_paths.h
tests/lib/cli/test_cli.refout pkgsrc/mgmtd.sh tests/lib/cli/test_cli.refout pkgsrc/mgmtd.sh
pkgsrc/bgpd.sh pkgsrc/ospf6d.sh pkgsrc/ospfd.sh pkgsrc/bgpd.sh pkgsrc/ospf6d.sh pkgsrc/ospfd.sh
pkgsrc/ripd.sh pkgsrc/ripngd.sh pkgsrc/zebra.sh pkgsrc/ripd.sh pkgsrc/ripngd.sh pkgsrc/zebra.sh
@ -2898,10 +2894,10 @@ compiler : ${CC}
compiler flags : ${CFLAGS} ${WERROR} ${AC_CFLAGS} ${SAN_FLAGS} compiler flags : ${CFLAGS} ${WERROR} ${AC_CFLAGS} ${SAN_FLAGS}
make : ${MAKE-make} make : ${MAKE-make}
linker flags : ${LDFLAGS} ${SAN_FLAGS} ${LIBS} ${LIBCAP} ${LIBREADLINE} ${LIBM} linker flags : ${LDFLAGS} ${SAN_FLAGS} ${LIBS} ${LIBCAP} ${LIBREADLINE} ${LIBM}
state file directory : ${CFG_STATE} state file directory : ${e_frr_runstatedir}
config file directory : ${CFG_SYSCONF} config file directory : ${e_sysconfdir}
module directory : ${CFG_MODULE} module directory : ${e_moduledir}
script directory : ${CFG_SCRIPT} script directory : ${e_scriptdir}
user to run as : ${enable_user} user to run as : ${enable_user}
group to run as : ${enable_group} group to run as : ${enable_group}
group for vty sockets : ${enable_vty_group} group for vty sockets : ${enable_vty_group}

1
lib/.gitignore vendored
View file

@ -1,3 +1,4 @@
/config_paths.h
/version.c /version.c
/version.h /version.h
/gitversion.h /gitversion.h

View file

@ -43,6 +43,8 @@
#include "frrscript.h" #include "frrscript.h"
#include "lib/config_paths.h"
DEFINE_MTYPE_STATIC(LIB, HOST, "Host config"); DEFINE_MTYPE_STATIC(LIB, HOST, "Host config");
DEFINE_MTYPE(LIB, COMPLETION, "Completion item"); DEFINE_MTYPE(LIB, COMPLETION, "Completion item");

24
lib/config_paths.h.in Normal file
View file

@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/* autogenerated by configure / config.status */
/* IF YOU ARE INCLUDING THIS FILE FROM A DAEMON OR ZEBRA, YOU ARE PROBABLY
* DOING SOMETHING WRONG. Check for / add a library function that retrieves
* the path you need.
*
* Only libfrr and watchfrr should be including this file.
*/
/* the replacements for these are emitted by AX_SUBST_EXPANDED, which also
* adds the e_ prefix
*/
#define FRR_RUNSTATE_PATH "@e_frr_runstatedir@"
#define FRR_LIBSTATE_PATH "@e_frr_libstatedir@"
#define YANG_MODELS_PATH "@e_yangmodelsdir@"
#define MODULE_PATH "@e_moduledir@"
#define SCRIPT_PATH "@e_scriptdir@"
/* for extra footgunning, this one has a trailing slash */
#define SYSCONFDIR "@e_frr_sysconfdir@/"
#define VTYSH_BIN_PATH "@e_vtysh_bin@"
#define WATCHFRR_SH_PATH "@e_watchfrr_sh@"

View file

@ -37,6 +37,8 @@
#include "frrscript.h" #include "frrscript.h"
#include "systemd.h" #include "systemd.h"
#include "lib/config_paths.h"
DEFINE_HOOK(frr_early_init, (struct event_loop * tm), (tm)); DEFINE_HOOK(frr_early_init, (struct event_loop * tm), (tm));
DEFINE_HOOK(frr_late_init, (struct event_loop * tm), (tm)); DEFINE_HOOK(frr_late_init, (struct event_loop * tm), (tm));
DEFINE_HOOK(frr_config_pre, (struct event_loop * tm), (tm)); DEFINE_HOOK(frr_config_pre, (struct event_loop * tm), (tm));

View file

@ -46,6 +46,8 @@
#include <arpa/telnet.h> #include <arpa/telnet.h>
#include <termios.h> #include <termios.h>
#include "lib/config_paths.h"
#include "lib/vty_clippy.c" #include "lib/vty_clippy.c"
DEFINE_MTYPE_STATIC(LIB, VTY, "VTY"); DEFINE_MTYPE_STATIC(LIB, VTY, "VTY");

View file

@ -13,6 +13,8 @@
#include "yang_translator.h" #include "yang_translator.h"
#include "northbound.h" #include "northbound.h"
#include "lib/config_paths.h"
DEFINE_MTYPE_STATIC(LIB, YANG_MODULE, "YANG module"); DEFINE_MTYPE_STATIC(LIB, YANG_MODULE, "YANG module");
DEFINE_MTYPE_STATIC(LIB, YANG_DATA, "YANG data structure"); DEFINE_MTYPE_STATIC(LIB, YANG_DATA, "YANG data structure");

View file

@ -16,7 +16,7 @@ fi
name="bgpd" name="bgpd"
rcvar=$name rcvar=$name
required_files="@CFG_SYSCONF@/${name}.conf" required_files="@e_sysconfdir@/${name}.conf"
command="@prefix@/sbin/${name}" command="@prefix@/sbin/${name}"
command_args="-d" command_args="-d"

View file

@ -16,7 +16,7 @@ fi
name="eigrpd" name="eigrpd"
rcvar=$name rcvar=$name
required_files="@CFG_SYSCONF@/${name}.conf" required_files="@e_sysconfdir@/${name}.conf"
command="@prefix@/sbin/${name}" command="@prefix@/sbin/${name}"
command_args="-d" command_args="-d"

View file

@ -16,7 +16,7 @@ fi
name="mgmtd" name="mgmtd"
rcvar=$name rcvar=$name
required_files="@CFG_SYSCONF@/${name}.conf" required_files="@e_sysconfdir@/${name}.conf"
command="@prefix@/sbin/${name}" command="@prefix@/sbin/${name}"
command_args="-d" command_args="-d"

View file

@ -16,7 +16,7 @@ fi
name="ospf6d" name="ospf6d"
rcvar=$name rcvar=$name
required_files="@CFG_SYSCONF@/${name}.conf" required_files="@e_sysconfdir@/${name}.conf"
command="@prefix@/sbin/${name}" command="@prefix@/sbin/${name}"
command_args="-d" command_args="-d"

View file

@ -16,7 +16,7 @@ fi
name="ospfd" name="ospfd"
rcvar=$name rcvar=$name
required_files="@CFG_SYSCONF@/${name}.conf" required_files="@e_sysconfdir@/${name}.conf"
command="@prefix@/sbin/${name}" command="@prefix@/sbin/${name}"
command_args="-d" command_args="-d"

View file

@ -16,7 +16,7 @@ fi
name="ripd" name="ripd"
rcvar=$name rcvar=$name
required_files="@CFG_SYSCONF@/${name}.conf" required_files="@e_sysconfdir@/${name}.conf"
command="@prefix@/sbin/${name}" command="@prefix@/sbin/${name}"
command_args="-d" command_args="-d"

View file

@ -16,7 +16,7 @@ fi
name="ripngd" name="ripngd"
rcvar=$name rcvar=$name
required_files="@CFG_SYSCONF@/${name}.conf" required_files="@e_sysconfdir@/${name}.conf"
command="@prefix@/sbin/${name}" command="@prefix@/sbin/${name}"
command_args="-d" command_args="-d"

View file

@ -16,7 +16,7 @@ fi
name="zebra" name="zebra"
rcvar=$name rcvar=$name
required_files="@CFG_SYSCONF@/${name}.conf" required_files="@e_sysconfdir@/${name}.conf"
command="@prefix@/sbin/${name}" command="@prefix@/sbin/${name}"
command_args="-d" command_args="-d"

View file

@ -14,11 +14,11 @@
# #
PATH=/bin:/usr/bin:/sbin:/usr/sbin PATH=/bin:/usr/bin:/sbin:/usr/sbin
D_PATH="@CFG_SBIN@" # /usr/lib/frr D_PATH="@e_sbindir@" # /usr/lib/frr
C_PATH="@CFG_SYSCONF@" # /etc/frr C_PATH="@e_frr_sysconfdir@" # /etc/frr
V_PATH="@CFG_STATE@" # /var/run/frr V_PATH="@e_frr_runstatedir@" # /var/run/frr
B_PATH="@CFG_BIN@" B_PATH="@e_bindir@"
VTYSH="@vtysh_bin@" # /usr/bin/vtysh VTYSH="@e_vtysh_bin@" # /usr/bin/vtysh
FRR_USER="@enable_user@" # frr FRR_USER="@enable_user@" # frr
FRR_GROUP="@enable_group@" # frr FRR_GROUP="@enable_group@" # frr
FRR_VTY_GROUP="@enable_vty_group@" # frrvty FRR_VTY_GROUP="@enable_vty_group@" # frrvty

View file

@ -17,10 +17,10 @@ WatchdogSec=60s
RestartSec=5 RestartSec=5
Restart=always Restart=always
LimitNOFILE=1024 LimitNOFILE=1024
PIDFile=@CFG_STATE@/watchfrr.pid PIDFile=@e_frr_runstatedir@/watchfrr.pid
ExecStart=@CFG_SBIN@/frrinit.sh start ExecStart=@e_sbindir@/frrinit.sh start
ExecStop=@CFG_SBIN@/frrinit.sh stop ExecStop=@e_sbindir@/frrinit.sh stop
ExecReload=@CFG_SBIN@/frrinit.sh reload ExecReload=@e_sbindir@/frrinit.sh reload
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -17,10 +17,10 @@ WatchdogSec=60s
RestartSec=5 RestartSec=5
Restart=always Restart=always
LimitNOFILE=1024 LimitNOFILE=1024
PIDFile=@CFG_STATE@/%I/watchfrr.pid PIDFile=@e_frr_runstatedir@/%I/watchfrr.pid
ExecStart=@CFG_SBIN@/frrinit.sh start %I ExecStart=@e_sbindir@/frrinit.sh start %I
ExecStop=@CFG_SBIN@/frrinit.sh stop %I ExecStop=@e_sbindir@/frrinit.sh stop %I
ExecReload=@CFG_SBIN@/frrinit.sh reload %I ExecReload=@e_sbindir@/frrinit.sh reload %I
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -14,18 +14,18 @@
# not perform any action. Note there is an "exit 1" if the main config # not perform any action. Note there is an "exit 1" if the main config
# file does not exist. # file does not exist.
# #
# This script should be installed in @CFG_SBIN@/frrcommon.sh # This script should be installed in @e_sbindir@/frrcommon.sh
# FRR_PATHSPACE is passed in from watchfrr # FRR_PATHSPACE is passed in from watchfrr
suffix="${FRR_PATHSPACE:+/${FRR_PATHSPACE}}" suffix="${FRR_PATHSPACE:+/${FRR_PATHSPACE}}"
nsopt="${FRR_PATHSPACE:+-N ${FRR_PATHSPACE}}" nsopt="${FRR_PATHSPACE:+-N ${FRR_PATHSPACE}}"
PATH=/bin:/usr/bin:/sbin:/usr/sbin PATH=/bin:/usr/bin:/sbin:/usr/sbin
D_PATH="@CFG_SBIN@" # /usr/lib/frr D_PATH="@e_sbindir@" # /usr/lib/frr
C_PATH="@CFG_SYSCONF@${suffix}" # /etc/frr C_PATH="@e_frr_sysconfdir@${suffix}" # /etc/frr
V_PATH="@CFG_STATE@${suffix}" # /var/run/frr V_PATH="@e_frr_runstatedir@${suffix}" # /var/run/frr
B_PATH="@CFG_BIN@" B_PATH="@e_bindir@"
VTYSH="@vtysh_bin@" # /usr/bin/vtysh VTYSH="@e_vtysh_bin@" # /usr/bin/vtysh
FRR_USER="@enable_user@" # frr FRR_USER="@enable_user@" # frr
FRR_GROUP="@enable_group@" # frr FRR_GROUP="@enable_group@" # frr
FRR_VTY_GROUP="@enable_vty_group@" # frrvty FRR_VTY_GROUP="@enable_vty_group@" # frrvty

View file

@ -37,7 +37,7 @@ self="`dirname $0`"
if [ -r "$self/frrcommon.sh" ]; then if [ -r "$self/frrcommon.sh" ]; then
. "$self/frrcommon.sh" . "$self/frrcommon.sh"
else else
. "@CFG_SBIN@/frrcommon.sh" . "@e_sbindir@/frrcommon.sh"
fi fi
case "$1" in case "$1" in

View file

@ -5,7 +5,7 @@
# internally by watchfrr to start the protocol daemons with the appropriate # internally by watchfrr to start the protocol daemons with the appropriate
# options. # options.
# #
# This script should be installed in @CFG_SBIN@/watchfrr.sh # This script should be installed in @e_sbindir@/watchfrr.sh
log_success_msg() { log_success_msg() {
: :
@ -27,7 +27,7 @@ self="`dirname $0`"
if [ -r "$self/frrcommon.sh" ]; then if [ -r "$self/frrcommon.sh" ]; then
. "$self/frrcommon.sh" . "$self/frrcommon.sh"
else else
. "@CFG_SBIN@/frrcommon.sh" . "@e_sbindir@/frrcommon.sh"
fi fi
frrcommon_main "$@" frrcommon_main "$@"

View file

@ -32,6 +32,8 @@
#include "watchfrr.h" #include "watchfrr.h"
#include "watchfrr_errors.h" #include "watchfrr_errors.h"
#include "lib/config_paths.h"
#ifndef MIN #ifndef MIN
#define MIN(X,Y) (((X) <= (Y)) ? (X) : (Y)) #define MIN(X,Y) (((X) <= (Y)) ? (X) : (Y))
#endif #endif

View file

@ -18,6 +18,8 @@
#include "watchfrr.h" #include "watchfrr.h"
#include "lib/config_paths.h"
pid_t integrated_write_pid; pid_t integrated_write_pid;
static int integrated_result_fd; static int integrated_result_fd;