Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use AC_REPLACE_FUNCS() framework for popular *BSD functions
The pidfile(), strlcpy(), strlcat(), strtonum(), and utimensat() API's
don't exist on all platforms.  The GNU configure replacement framework
is the recommended approach instead of homegrown detection.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
  • Loading branch information
troglobit committed Jun 6, 2017
1 parent 67f0b3d commit 8db127b
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 39 deletions.
26 changes: 5 additions & 21 deletions configure.ac
Expand Up @@ -30,24 +30,12 @@ AC_CHECK_HEADERS([net/if.h], [], [], [
# include <sys/socket.h>
#endif])

AC_CHECK_FUNC([pidfile], has_pidfile=yes, has_pidfile=no)
AC_CHECK_FUNC([strlcpy], has_strlcpy=yes, has_strlcpy=no)
AC_CHECK_FUNC([strlcat], has_strlcat=yes, has_strlcat=no)
AC_CHECK_FUNC([strtonum], has_strtonum=yes, has_strtonum=no)
# Check for required functions in libc
AC_CHECK_FUNCS([atexit getifaddrs if_nametoindex])

AC_CHECK_FUNCS([atexit utimensat getifaddrs if_nametoindex])

AS_IF([test "x$has_strlcpy" = xno],
AC_SEARCH_LIBS([strlcpy], [util],
has_strlcpy=yes
has_strlcat=yes
has_strtonum=yes
libutil=yes))

AM_CONDITIONAL(NO_PIDFILE, [test "x$has_pidfile" = "xno"])
AM_CONDITIONAL(NO_STRLCPY, [test "x$has_strlcpy" = "xno"])
AM_CONDITIONAL(NO_STRLCAT, [test "x$has_strlcat" = "xno"])
AM_CONDITIONAL(NO_STRTONUM, [test "x$has_strtonum" = "xno"])
# Check for usually missing API's, which we can replace
AC_REPLACE_FUNCS([pidfile strlcpy strlcat strtonum utimensat])
AC_CONFIG_LIBOBJ_DIR([lib])

# If your RP is buggy cisco PIM-SMv2 implementation that computes
# the PIM-Register checksum over the whole pkt instead only over
Expand Down Expand Up @@ -152,10 +140,6 @@ AM_CONDITIONAL(LINUX, [test "x$ac_cv_header_linux_netlink_h" = "xyes"])
AM_CONDITIONAL(RSRR, [test "x$enable_rsrr" = "xyes"])
AM_CONDITIONAL(SYSTEMD, [test "x$with_systemd" != "xno"])

LIBUTIL=
AS_IF([test "x$libutil" = "yes"], [LIBUTIL=-lutil])
AC_SUBST(LIBUTIL)

# Expand $sbindir early, into $SBINDIR, for systemd unit file
# NOTE: This does *not* take prefix/exec_prefix override at "make
# install" into account, unfortunately.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 5 additions & 18 deletions src/Makefile.am
@@ -1,3 +1,6 @@
# For replacement functions in lib/
AUTOMAKE_OPTIONS = subdir-objects

# -D_GNU_SOURCE Use GNU extensions, where possible
# -D_BSD_SOURCE Use functions derived from 4.3 BSD Unix rather than POSIX.1
# In GLIBC >= v2.20 this is replaced with -D_DEFAULT_SOURCE,
Expand All @@ -12,9 +15,9 @@ pimd_SOURCES = callout.c config.c debug.c debug.h \
inet.c kern.c main.c pathnames.h \
mrt.c mrt.h route.c rp.c \
pim_proto.c pim.c pimd.h \
timer.c trace.c trace.h utimensat.c \
timer.c trace.c trace.h \
vif.c vif.h queue.h
pimd_LDADD = @LIBUTIL@
pimd_LDADD = $(LIBS) $(LIBOBJS)

if LINUX
AM_CPPFLAGS += -DRAW_OUTPUT_IS_RAW -DIOCTL_OK_ON_RAW_SOCKET
Expand All @@ -31,22 +34,6 @@ AM_CPPFLAGS += -DPIM
pimd_SOURCES += rsrr.c rsrr_var.h rsrr.h
endif

if NO_PIDFILE
pimd_SOURCES += pidfile.c
endif

if NO_STRLCPY
pimd_SOURCES += strlcpy.c
endif

if NO_STRLCAT
pimd_SOURCES += strlcat.c
endif

if NO_STRTONUM
pimd_SOURCES += strtonum.c
endif

## BSDI -D__bsdi__ is defined by the OS
#AM_CPPFLAGS += -Iinclude

Expand Down

0 comments on commit 8db127b

Please sign in to comment.