Skip to content

Commit bbd8589

Browse files
committed
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 <[email protected]>
1 parent f1ad2c4 commit bbd8589

24 files changed

+93
-60
lines changed

Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ MODULE_LDFLAGS = \
5656
$(SAN_FLAGS) \
5757
# end
5858

59-
DEFS = @DEFS@ -DSYSCONFDIR=\"$(CFG_SYSCONF)/\" -DCONFDATE=$(CONFDATE)
59+
DEFS = @DEFS@ -DCONFDATE=$(CONFDATE)
6060

6161
AR_FLAGS = @AR_FLAGS@
6262
ARFLAGS = @ARFLAGS@

configure.ac

+25-29
Original file line numberDiff line numberDiff line change
@@ -2715,31 +2715,26 @@ fi
27152715
AC_SUBST([CONFDATE])
27162716

27172717
dnl get the full path, recursing through variables...
2718-
AX_RECURSIVE_EVAL([$bindir/vtysh], [vtysh_bin])
2719-
AX_RECURSIVE_EVAL([$frr_sysconfdir], [CFG_SYSCONF])
2720-
AX_RECURSIVE_EVAL([$sbindir], [CFG_SBIN])
2721-
AX_RECURSIVE_EVAL([$bindir], [CFG_BIN])
2722-
AX_RECURSIVE_EVAL([$frr_runstatedir], [CFG_STATE])
2723-
AX_RECURSIVE_EVAL([$frr_libstatedir], [CFG_LIBSTATE])
2724-
AX_RECURSIVE_EVAL([$moduledir], [CFG_MODULE])
2725-
AX_RECURSIVE_EVAL([$yangmodelsdir], [CFG_YANGMODELS])
2726-
AX_RECURSIVE_EVAL([$scriptdir], [CFG_SCRIPT])
2727-
AC_SUBST([vtysh_bin])
2728-
AC_SUBST([CFG_SYSCONF])
2729-
AC_SUBST([CFG_SBIN])
2730-
AC_SUBST([CFG_BIN])
2731-
AC_SUBST([CFG_STATE])
2732-
dnl AC_SUBST([CFG_LIBSTATE]) -- not currently used
2733-
AC_SUBST([CFG_MODULE])
2734-
AC_SUBST([CFG_SCRIPT])
2735-
AC_SUBST([CFG_YANGMODELS])
2736-
AC_DEFINE_UNQUOTED([VTYSH_BIN_PATH], ["$vtysh_bin"], [path to vtysh binary])
2737-
AC_DEFINE_UNQUOTED([MODULE_PATH], ["$CFG_MODULE"], [path to modules])
2738-
AC_DEFINE_UNQUOTED([SCRIPT_PATH], ["$CFG_SCRIPT"], [path to scripts])
2739-
AC_DEFINE_UNQUOTED([FRR_RUNSTATE_PATH], ["$CFG_STATE"], [/run/frr equivalent])
2740-
AC_DEFINE_UNQUOTED([FRR_LIBSTATE_PATH], ["$CFG_LIBSTATE"], [/var/lib/frr equivalent])
2741-
AC_DEFINE_UNQUOTED([YANG_MODELS_PATH], ["$CFG_YANGMODELS"], [path to YANG data models])
2742-
AC_DEFINE_UNQUOTED([WATCHFRR_SH_PATH], ["${CFG_SBIN%/}/watchfrr.sh"], [path to watchfrr.sh])
2718+
AC_DEFUN([AX_SUBST_EXPANDED], [
2719+
AX_RECURSIVE_EVAL([[$]$1], [e_$1])
2720+
AC_SUBST([e_$1])
2721+
])
2722+
2723+
AX_SUBST_EXPANDED([bindir])
2724+
AX_SUBST_EXPANDED([sbindir])
2725+
AX_SUBST_EXPANDED([frr_sysconfdir])
2726+
AX_SUBST_EXPANDED([frr_runstatedir])
2727+
AX_SUBST_EXPANDED([frr_libstatedir])
2728+
AX_SUBST_EXPANDED([moduledir])
2729+
AX_SUBST_EXPANDED([yangmodelsdir])
2730+
AX_SUBST_EXPANDED([scriptdir])
2731+
2732+
dnl strip duplicate trailing slashes if necessary
2733+
dnl note this uses e_bindir / e_sbindir created above
2734+
watchfrr_sh="\${e_sbindir%/}/watchfrr.sh"
2735+
AX_SUBST_EXPANDED([watchfrr_sh])
2736+
vtysh_bin="\${e_bindir%/}/vtysh"
2737+
AX_SUBST_EXPANDED([vtysh_bin])
27432738

27442739
dnl various features
27452740
AM_CONDITIONAL([SUPPORT_REALMS], [test "$enable_realms" = "yes"])
@@ -2811,6 +2806,7 @@ AC_CONFIG_FILES([
28112806
alpine/APKBUILD
28122807
snapcraft/snapcraft.yaml
28132808
lib/version.h
2809+
lib/config_paths.h
28142810
tests/lib/cli/test_cli.refout pkgsrc/mgmtd.sh
28152811
pkgsrc/bgpd.sh pkgsrc/ospf6d.sh pkgsrc/ospfd.sh
28162812
pkgsrc/ripd.sh pkgsrc/ripngd.sh pkgsrc/zebra.sh
@@ -2898,10 +2894,10 @@ compiler : ${CC}
28982894
compiler flags : ${CFLAGS} ${WERROR} ${AC_CFLAGS} ${SAN_FLAGS}
28992895
make : ${MAKE-make}
29002896
linker flags : ${LDFLAGS} ${SAN_FLAGS} ${LIBS} ${LIBCAP} ${LIBREADLINE} ${LIBM}
2901-
state file directory : ${CFG_STATE}
2902-
config file directory : ${CFG_SYSCONF}
2903-
module directory : ${CFG_MODULE}
2904-
script directory : ${CFG_SCRIPT}
2897+
state file directory : ${e_frr_runstatedir}
2898+
config file directory : ${e_sysconfdir}
2899+
module directory : ${e_moduledir}
2900+
script directory : ${e_scriptdir}
29052901
user to run as : ${enable_user}
29062902
group to run as : ${enable_group}
29072903
group for vty sockets : ${enable_vty_group}

lib/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/config_paths.h
12
/version.c
23
/version.h
34
/gitversion.h

lib/command.c

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
#include "frrscript.h"
4545

46+
#include "lib/config_paths.h"
47+
4648
DEFINE_MTYPE_STATIC(LIB, HOST, "Host config");
4749
DEFINE_MTYPE(LIB, COMPLETION, "Completion item");
4850

lib/config_paths.h.in

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/* autogenerated by configure / config.status */
3+
4+
/* IF YOU ARE INCLUDING THIS FILE FROM A DAEMON OR ZEBRA, YOU ARE PROBABLY
5+
* DOING SOMETHING WRONG. Check for / add a library function that retrieves
6+
* the path you need.
7+
*
8+
* Only libfrr and watchfrr should be including this file.
9+
*/
10+
11+
/* the replacements for these are emitted by AX_SUBST_EXPANDED, which also
12+
* adds the e_ prefix
13+
*/
14+
#define FRR_RUNSTATE_PATH "@e_frr_runstatedir@"
15+
#define FRR_LIBSTATE_PATH "@e_frr_libstatedir@"
16+
#define YANG_MODELS_PATH "@e_yangmodelsdir@"
17+
#define MODULE_PATH "@e_moduledir@"
18+
#define SCRIPT_PATH "@e_scriptdir@"
19+
20+
/* for extra footgunning, this one has a trailing slash */
21+
#define SYSCONFDIR "@e_frr_sysconfdir@/"
22+
23+
#define VTYSH_BIN_PATH "@e_vtysh_bin@"
24+
#define WATCHFRR_SH_PATH "@e_watchfrr_sh@"

lib/libfrr.c

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "frrscript.h"
3838
#include "systemd.h"
3939

40+
#include "lib/config_paths.h"
41+
4042
DEFINE_HOOK(frr_early_init, (struct event_loop * tm), (tm));
4143
DEFINE_HOOK(frr_late_init, (struct event_loop * tm), (tm));
4244
DEFINE_HOOK(frr_config_pre, (struct event_loop * tm), (tm));

lib/vty.c

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
#include <arpa/telnet.h>
4747
#include <termios.h>
4848

49+
#include "lib/config_paths.h"
50+
4951
#include "lib/vty_clippy.c"
5052

5153
DEFINE_MTYPE_STATIC(LIB, VTY, "VTY");

lib/yang.c

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "yang_translator.h"
1414
#include "northbound.h"
1515

16+
#include "lib/config_paths.h"
17+
1618
DEFINE_MTYPE_STATIC(LIB, YANG_MODULE, "YANG module");
1719
DEFINE_MTYPE_STATIC(LIB, YANG_DATA, "YANG data structure");
1820

pkgsrc/bgpd.sh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717
name="bgpd"
1818
rcvar=$name
19-
required_files="@CFG_SYSCONF@/${name}.conf"
19+
required_files="@e_sysconfdir@/${name}.conf"
2020
command="@prefix@/sbin/${name}"
2121
command_args="-d"
2222

pkgsrc/eigrpd.sh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717
name="eigrpd"
1818
rcvar=$name
19-
required_files="@CFG_SYSCONF@/${name}.conf"
19+
required_files="@e_sysconfdir@/${name}.conf"
2020
command="@prefix@/sbin/${name}"
2121
command_args="-d"
2222

pkgsrc/mgmtd.sh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717
name="mgmtd"
1818
rcvar=$name
19-
required_files="@CFG_SYSCONF@/${name}.conf"
19+
required_files="@e_sysconfdir@/${name}.conf"
2020
command="@prefix@/sbin/${name}"
2121
command_args="-d"
2222

pkgsrc/ospf6d.sh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717
name="ospf6d"
1818
rcvar=$name
19-
required_files="@CFG_SYSCONF@/${name}.conf"
19+
required_files="@e_sysconfdir@/${name}.conf"
2020
command="@prefix@/sbin/${name}"
2121
command_args="-d"
2222

pkgsrc/ospfd.sh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717
name="ospfd"
1818
rcvar=$name
19-
required_files="@CFG_SYSCONF@/${name}.conf"
19+
required_files="@e_sysconfdir@/${name}.conf"
2020
command="@prefix@/sbin/${name}"
2121
command_args="-d"
2222

pkgsrc/ripd.sh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717
name="ripd"
1818
rcvar=$name
19-
required_files="@CFG_SYSCONF@/${name}.conf"
19+
required_files="@e_sysconfdir@/${name}.conf"
2020
command="@prefix@/sbin/${name}"
2121
command_args="-d"
2222

pkgsrc/ripngd.sh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717
name="ripngd"
1818
rcvar=$name
19-
required_files="@CFG_SYSCONF@/${name}.conf"
19+
required_files="@e_sysconfdir@/${name}.conf"
2020
command="@prefix@/sbin/${name}"
2121
command_args="-d"
2222

pkgsrc/zebra.sh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717
name="zebra"
1818
rcvar=$name
19-
required_files="@CFG_SYSCONF@/${name}.conf"
19+
required_files="@e_sysconfdir@/${name}.conf"
2020
command="@prefix@/sbin/${name}"
2121
command_args="-d"
2222

tools/frr.in

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
#
1515

1616
PATH=/bin:/usr/bin:/sbin:/usr/sbin
17-
D_PATH="@CFG_SBIN@" # /usr/lib/frr
18-
C_PATH="@CFG_SYSCONF@" # /etc/frr
19-
V_PATH="@CFG_STATE@" # /var/run/frr
20-
B_PATH="@CFG_BIN@"
21-
VTYSH="@vtysh_bin@" # /usr/bin/vtysh
17+
D_PATH="@e_sbindir@" # /usr/lib/frr
18+
C_PATH="@e_frr_sysconfdir@" # /etc/frr
19+
V_PATH="@e_frr_runstatedir@" # /var/run/frr
20+
B_PATH="@e_bindir@"
21+
VTYSH="@e_vtysh_bin@" # /usr/bin/vtysh
2222
FRR_USER="@enable_user@" # frr
2323
FRR_GROUP="@enable_group@" # frr
2424
FRR_VTY_GROUP="@enable_vty_group@" # frrvty

tools/frr.service.in

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ WatchdogSec=60s
1717
RestartSec=5
1818
Restart=always
1919
LimitNOFILE=1024
20-
PIDFile=@CFG_STATE@/watchfrr.pid
21-
ExecStart=@CFG_SBIN@/frrinit.sh start
22-
ExecStop=@CFG_SBIN@/frrinit.sh stop
23-
ExecReload=@CFG_SBIN@/frrinit.sh reload
20+
PIDFile=@e_frr_runstatedir@/watchfrr.pid
21+
ExecStart=@e_sbindir@/frrinit.sh start
22+
ExecStop=@e_sbindir@/frrinit.sh stop
23+
ExecReload=@e_sbindir@/frrinit.sh reload
2424

2525
[Install]
2626
WantedBy=multi-user.target

tools/[email protected]

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ WatchdogSec=60s
1717
RestartSec=5
1818
Restart=always
1919
LimitNOFILE=1024
20-
PIDFile=@CFG_STATE@/%I/watchfrr.pid
21-
ExecStart=@CFG_SBIN@/frrinit.sh start %I
22-
ExecStop=@CFG_SBIN@/frrinit.sh stop %I
23-
ExecReload=@CFG_SBIN@/frrinit.sh reload %I
20+
PIDFile=@e_frr_runstatedir@/%I/watchfrr.pid
21+
ExecStart=@e_sbindir@/frrinit.sh start %I
22+
ExecStop=@e_sbindir@/frrinit.sh stop %I
23+
ExecReload=@e_sbindir@/frrinit.sh reload %I
2424

2525
[Install]
2626
WantedBy=multi-user.target

tools/frrcommon.sh.in

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
# not perform any action. Note there is an "exit 1" if the main config
1515
# file does not exist.
1616
#
17-
# This script should be installed in @CFG_SBIN@/frrcommon.sh
17+
# This script should be installed in @e_sbindir@/frrcommon.sh
1818

1919
# FRR_PATHSPACE is passed in from watchfrr
2020
suffix="${FRR_PATHSPACE:+/${FRR_PATHSPACE}}"
2121
nsopt="${FRR_PATHSPACE:+-N ${FRR_PATHSPACE}}"
2222

2323
PATH=/bin:/usr/bin:/sbin:/usr/sbin
24-
D_PATH="@CFG_SBIN@" # /usr/lib/frr
25-
C_PATH="@CFG_SYSCONF@${suffix}" # /etc/frr
26-
V_PATH="@CFG_STATE@${suffix}" # /var/run/frr
27-
B_PATH="@CFG_BIN@"
28-
VTYSH="@vtysh_bin@" # /usr/bin/vtysh
24+
D_PATH="@e_sbindir@" # /usr/lib/frr
25+
C_PATH="@e_frr_sysconfdir@${suffix}" # /etc/frr
26+
V_PATH="@e_frr_runstatedir@${suffix}" # /var/run/frr
27+
B_PATH="@e_bindir@"
28+
VTYSH="@e_vtysh_bin@" # /usr/bin/vtysh
2929
FRR_USER="@enable_user@" # frr
3030
FRR_GROUP="@enable_group@" # frr
3131
FRR_VTY_GROUP="@enable_vty_group@" # frrvty

tools/frrinit.sh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ self="`dirname $0`"
3737
if [ -r "$self/frrcommon.sh" ]; then
3838
. "$self/frrcommon.sh"
3939
else
40-
. "@CFG_SBIN@/frrcommon.sh"
40+
. "@e_sbindir@/frrcommon.sh"
4141
fi
4242

4343
case "$1" in

tools/watchfrr.sh.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# internally by watchfrr to start the protocol daemons with the appropriate
66
# options.
77
#
8-
# This script should be installed in @CFG_SBIN@/watchfrr.sh
8+
# This script should be installed in @e_sbindir@/watchfrr.sh
99

1010
log_success_msg() {
1111
:
@@ -27,7 +27,7 @@ self="`dirname $0`"
2727
if [ -r "$self/frrcommon.sh" ]; then
2828
. "$self/frrcommon.sh"
2929
else
30-
. "@CFG_SBIN@/frrcommon.sh"
30+
. "@e_sbindir@/frrcommon.sh"
3131
fi
3232

3333
frrcommon_main "$@"

watchfrr/watchfrr.c

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "watchfrr.h"
3333
#include "watchfrr_errors.h"
3434

35+
#include "lib/config_paths.h"
36+
3537
#ifndef MIN
3638
#define MIN(X,Y) (((X) <= (Y)) ? (X) : (Y))
3739
#endif

watchfrr/watchfrr_vty.c

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "watchfrr.h"
2020

21+
#include "lib/config_paths.h"
22+
2123
pid_t integrated_write_pid;
2224
static int integrated_result_fd;
2325

0 commit comments

Comments
 (0)