Skip to content

Commit

Permalink
Remove hardcoded paths to commands, configs, etc. in source
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Prindeville committed Oct 23, 2023
1 parent 4fc330d commit 85a26ee
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/backend/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
16 changes: 16 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -6932,12 +6932,28 @@ fi
# Expand for easy replacement in example/main/example.xml.in
# Special case is $libdir, which is composed from $exec_prefix
test "x$prefix" = xNONE && prefix=$ac_default_prefix
BINDIR=`eval echo $bindir`
SBINDIR=`eval echo $sbindir`
SYSCONFDIR=`eval echo $sysconfdir`
DATADIR=`eval echo \`eval echo $datadir\``
LIBDIR=`eval echo $libdir`
LIBEXECDIR=`eval echo $libexecdir`
LOCALSTATEDIR=`eval echo $localstatedir`


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
Expand Down
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,20 @@ AH_BOTTOM([#include <clixon_custom.h>])
# Expand for easy replacement in example/main/example.xml.in
# Special case is $libdir, which is composed from $exec_prefix
test "x$prefix" = xNONE && prefix=$ac_default_prefix
BINDIR=`eval echo $bindir`
SBINDIR=`eval echo $sbindir`
SYSCONFDIR=`eval echo $sysconfdir`
DATADIR=`eval echo \`eval echo $datadir\``
LIBDIR=`eval echo $libdir`
LIBEXECDIR=`eval echo $libexecdir`
LOCALSTATEDIR=`eval echo $localstatedir`

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
Expand Down
12 changes: 12 additions & 0 deletions include/clixon_config.h.in
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/src/clixon_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 8 additions & 4 deletions util/clixon_netconf_ssh_callhome.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -79,7 +83,7 @@ sudo clixon_netconf_ssh_callhome -a 127.0.0.1 -c /var/tmp/./test_netconf_ssh_cal
#include <sys/socket.h>

#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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -237,7 +241,7 @@ usage(char *argv0)
"\t-f ipv4|ipv6 \tSocket address family(inet:ipv4-address default)\n"
"\t-a <addrstr> \tIP address (eg 1.2.3.4) - mandatory\n"
"\t-p <port> \tPort (default 4334)\n"
"\t-c <file> \tClixon config file - (default /usr/local/etc/clixon.xml)\n"
"\t-c <file> \tClixon config file - (default " CLIXON_DEFAULT_CONFIG ")\n"
"\t-C <file> \tSSHD config file - (default /dev/null)\n"
"\t-s <sshd> \tPath to sshd binary, default %s\n"
,
Expand All @@ -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;
Expand Down

0 comments on commit 85a26ee

Please sign in to comment.