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) \
# end
DEFS = @DEFS@ -DSYSCONFDIR=\"$(CFG_SYSCONF)/\" -DCONFDATE=$(CONFDATE)
DEFS = @DEFS@ -DCONFDATE=$(CONFDATE)
AR_FLAGS = @AR_FLAGS@
ARFLAGS = @ARFLAGS@

View File

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

1
lib/.gitignore vendored
View File

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

View File

@ -43,6 +43,8 @@
#include "frrscript.h"
#include "lib/config_paths.h"
DEFINE_MTYPE_STATIC(LIB, HOST, "Host config");
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 "systemd.h"
#include "lib/config_paths.h"
DEFINE_HOOK(frr_early_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));

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,18 +14,18 @@
# not perform any action. Note there is an "exit 1" if the main config
# 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
suffix="${FRR_PATHSPACE:+/${FRR_PATHSPACE}}"
nsopt="${FRR_PATHSPACE:+-N ${FRR_PATHSPACE}}"
PATH=/bin:/usr/bin:/sbin:/usr/sbin
D_PATH="@CFG_SBIN@" # /usr/lib/frr
C_PATH="@CFG_SYSCONF@${suffix}" # /etc/frr
V_PATH="@CFG_STATE@${suffix}" # /var/run/frr
B_PATH="@CFG_BIN@"
VTYSH="@vtysh_bin@" # /usr/bin/vtysh
D_PATH="@e_sbindir@" # /usr/lib/frr
C_PATH="@e_frr_sysconfdir@${suffix}" # /etc/frr
V_PATH="@e_frr_runstatedir@${suffix}" # /var/run/frr
B_PATH="@e_bindir@"
VTYSH="@e_vtysh_bin@" # /usr/bin/vtysh
FRR_USER="@enable_user@" # frr
FRR_GROUP="@enable_group@" # frr
FRR_VTY_GROUP="@enable_vty_group@" # frrvty

View File

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

View File

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

View File

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

View File

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