From 70673260fedd19ef0da51485cf458aedb892919f Mon Sep 17 00:00:00 2001 From: Philip Prindeville Date: Mon, 23 Oct 2023 13:52:40 -0600 Subject: [PATCH] Remove hardcoded paths to commands, configs, etc. in source --- apps/backend/Makefile.in | 2 +- configure | 14 ++++++++++++++ configure.ac | 6 ++++++ include/clixon_config.h.in | 12 ++++++++++++ lib/src/clixon_client.c | 2 +- util/clixon_netconf_ssh_callhome.c | 12 ++++++++---- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/apps/backend/Makefile.in b/apps/backend/Makefile.in index 0b48743e4..2a412bca5 100644 --- a/apps/backend/Makefile.in +++ b/apps/backend/Makefile.in @@ -166,7 +166,7 @@ install-include: clixon_backend.h clixon_backend_client.h clixon_backend_transac .SUFFIXES: .c .o .c.o: - $(CC) $(INCLUDES) $(CPPFLAGS) -D__PROGRAM__=\"$(APPL)\" -DCLIXON_CONFIG_SBINDIR=\"$(sbindir)\" $(CFLAGS) -c $< + $(CC) $(INCLUDES) $(CPPFLAGS) -D__PROGRAM__=\"$(APPL)\" $(CFLAGS) -c $< # Just link test programs test.c : diff --git a/configure b/configure index 1fd8e8976..9f4936ec3 100755 --- a/configure +++ b/configure @@ -6945,6 +6945,20 @@ fi test "x$prefix" = xNONE && prefix=$ac_default_prefix + +printf "%s\n" "#define CLIXON_CONFIG_BINDIR \"${BINDIR}\"" >>confdefs.h + + +printf "%s\n" "#define CLIXON_CONFIG_LOCALSTATEDIR \"${LOCALSTATEDIR}\"" >>confdefs.h + + +printf "%s\n" "#define CLIXON_CONFIG_SBINDIR \"${SBINDIR}\"" >>confdefs.h + + +printf "%s\n" "#define CLIXON_CONFIG_SYSCONFDIR \"${SYSCONFDIR}\"" >>confdefs.h + + + ac_config_files="$ac_config_files Makefile lib/Makefile lib/src/Makefile lib/clixon/Makefile apps/Makefile apps/cli/Makefile apps/backend/Makefile apps/netconf/Makefile apps/restconf/Makefile apps/snmp/Makefile include/Makefile etc/Makefile etc/clixonrc example/Makefile example/main/Makefile example/main/example.xml docker/Makefile docker/clixon-dev/Makefile docker/example/Makefile docker/test/Makefile util/Makefile yang/Makefile yang/clixon/Makefile yang/mandatory/Makefile doc/Makefile test/Makefile test/config.sh test/cicd/Makefile test/vagrant/Makefile" cat >confcache <<\_ACEOF diff --git a/configure.ac b/configure.ac index 1f4ced4dd..3467113cd 100644 --- a/configure.ac +++ b/configure.ac @@ -453,6 +453,12 @@ AH_BOTTOM([#include ]) test "x$prefix" = xNONE && prefix=$ac_default_prefix +AC_DEFINE_UNQUOTED(CLIXON_CONFIG_BINDIR, "${BINDIR}", [Pass-through $bindir]) +AC_DEFINE_UNQUOTED(CLIXON_CONFIG_LOCALSTATEDIR, "${LOCALSTATEDIR}", [Pass-through $localstatedir]) +AC_DEFINE_UNQUOTED(CLIXON_CONFIG_SBINDIR, "${SBINDIR}", [Pass-through $sbindir]) +AC_DEFINE_UNQUOTED(CLIXON_CONFIG_SYSCONFDIR, "${SYSCONFDIR}", [Pass-through $sysconfdir]) + + AC_CONFIG_FILES([Makefile lib/Makefile lib/src/Makefile diff --git a/include/clixon_config.h.in b/include/clixon_config.h.in index 5476737f9..32b8430eb 100644 --- a/include/clixon_config.h.in +++ b/include/clixon_config.h.in @@ -1,5 +1,17 @@ /* include/clixon_config.h.in. Generated from configure.ac by autoheader. */ +/* Pass-through $bindir */ +#undef CLIXON_CONFIG_BINDIR + +/* Pass-through $localstatedir */ +#undef CLIXON_CONFIG_LOCALSTATEDIR + +/* Pass-through $sbindir */ +#undef CLIXON_CONFIG_SBINDIR + +/* Pass-through $sysconfdir */ +#undef CLIXON_CONFIG_SYSCONFDIR + /* Location for apps to find default config file */ #undef CLIXON_DEFAULT_CONFIG diff --git a/lib/src/clixon_client.c b/lib/src/clixon_client.c index 2a59cbc93..6409913b5 100644 --- a/lib/src/clixon_client.c +++ b/lib/src/clixon_client.c @@ -74,7 +74,7 @@ /* Netconf binary default, override with environment variable: CLIXON_NETCONF_BIN * Could try to get path from install/makefile data */ -#define CLIXON_NETCONF_BIN "/usr/local/bin/clixon_netconf" +#define CLIXON_NETCONF_BIN CLIXON_CONFIG_BINDIR "/clixon_netconf" #define CLIXON_CLIENT_MAGIC 0x54fe649a diff --git a/util/clixon_netconf_ssh_callhome.c b/util/clixon_netconf_ssh_callhome.c index 78cafb225..2fb090821 100644 --- a/util/clixon_netconf_ssh_callhome.c +++ b/util/clixon_netconf_ssh_callhome.c @@ -68,6 +68,10 @@ sudo clixon_netconf_ssh_callhome -a 127.0.0.1 -c /var/tmp/./test_netconf_ssh_cal */ +#ifdef HAVE_CONFIG_H +#include "clixon_config.h" /* generated by config & autoconf */ +#endif + #include #include #include @@ -79,7 +83,7 @@ sudo clixon_netconf_ssh_callhome -a 127.0.0.1 -c /var/tmp/./test_netconf_ssh_cal #include #define NETCONF_CH_SSH 4334 -#define SSHDBIN_DEFAULT "/usr/sbin/sshd" +#define SSHDBIN_DEFAULT CLIXON_CONFIG_SBINDIR "/sshd" #define UTIL_OPTS "hD:f:a:p:s:c:C:" static int @@ -151,7 +155,7 @@ ssh_server_exec(int s, int nr; char *optstr = NULL; size_t len; - const char *formatstr = "Subsystem netconf /usr/local/bin/clixon_netconf -f %s"; + const char *formatstr = "Subsystem netconf " CLIXON_CONFIG_BINDIR "/clixon_netconf -f %s"; if (s < 0){ errno = EINVAL; @@ -237,7 +241,7 @@ usage(char *argv0) "\t-f ipv4|ipv6 \tSocket address family(inet:ipv4-address default)\n" "\t-a \tIP address (eg 1.2.3.4) - mandatory\n" "\t-p \tPort (default 4334)\n" - "\t-c \tClixon config file - (default /usr/local/etc/clixon.xml)\n" + "\t-c \tClixon config file - (default " CLIXON_DEFAULT_CONFIG ")\n" "\t-C \tSSHD config file - (default /dev/null)\n" "\t-s \tPath to sshd binary, default %s\n" , @@ -261,7 +265,7 @@ main(int argc, int s = -1; char *sshdbin = SSHDBIN_DEFAULT; char *sshdconfigfile = "/dev/null"; - char *clixonconfigfile = "/usr/local/etc/clixon.xml"; + char *clixonconfigfile = CLIXON_CONFIG_SYSCONFDIR "/clixon.xml"; optind = 1; opterr = 0;