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 Nov 6, 2023
1 parent d46c4c2 commit 5afbad5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 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
23 changes: 18 additions & 5 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -6602,6 +6602,24 @@ then :
fi


# Default location for config file

printf "%s\n" "#define CLIXON_DEFAULT_CONFIG \"${CLIXON_DEFAULT_CONFIG}\"" >>confdefs.h



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


{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for socket in -lsocket" >&5
printf %s "checking for socket in -lsocket... " >&6; }
if test ${ac_cv_lib_socket_socket+y}
Expand Down Expand Up @@ -6931,11 +6949,6 @@ if test -n "${CLICON_GROUP}"; then
echo "Using CLICON_GROUP here: ${CLICON_GROUP}"
fi

# Default location for config file

printf "%s\n" "#define CLIXON_DEFAULT_CONFIG \"${CLIXON_DEFAULT_CONFIG}\"" >>confdefs.h


# Dummy to disable native language support (nls) to remove warnings in buildroot
# Check whether --enable-nls was given.
if test ${enable_nls+y}
Expand Down
11 changes: 8 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ AC_ARG_WITH([configfile],
[AS_HELP_STRING([--with-configfile=FILE],[Set default path to config file])],
[CLIXON_DEFAULT_CONFIG="$withval"],)

# Default location for config file
AC_DEFINE_UNQUOTED(CLIXON_DEFAULT_CONFIG,"${CLIXON_DEFAULT_CONFIG}",[Location for apps to find default config file])

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_CHECK_LIB(socket, socket)
AC_CHECK_LIB(dl, dlopen)

Expand Down Expand Up @@ -443,9 +451,6 @@ if test -n "${CLICON_GROUP}"; then
echo "Using CLICON_GROUP here: ${CLICON_GROUP}"
fi

# Default location for config file
AC_DEFINE_UNQUOTED(CLIXON_DEFAULT_CONFIG,"${CLIXON_DEFAULT_CONFIG}",[Location for apps to find default config file])

# Dummy to disable native language support (nls) to remove warnings in buildroot
AC_ARG_ENABLE(nls)

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 5afbad5

Please sign in to comment.