configure script. This makes the hooks a lot less messy.
SUBDIRS= dhcpcd-hooks
-SED_DBDIR= -e 's:@DBDIR@:${DBDIR}:g'
-SED_HOOKDIR= -e 's:@HOOKDIR@:${HOOKDIR}:g'
-SED_SCRIPT= -e 's:@SCRIPT@:${SCRIPT}:g'
-SED_SYS= -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
+SED_DBDIR= -e 's:@DBDIR@:${DBDIR}:g'
+SED_HOOKDIR= -e 's:@HOOKDIR@:${HOOKDIR}:g'
+SED_SERVICEEXISTS= -e 's:@SERVICEEXISTS@:${SERVICEEXISTS}:g'
+SED_SERVICECMD= -e 's:@SERVICECMD@:${SERVICECMD}:g'
+SED_SERVICESTATUS= -e 's:@SERVICESTATUS@:${SERVICESTATUS}:g'
+SED_SCRIPT= -e 's:@SCRIPT@:${SCRIPT}:g'
+SED_SYS= -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
_DEPEND_SH= test -e .depend && echo ".depend" || echo ""
_DEPEND!= ${_DEPEND_SH}
.SUFFIXES: .in
.in:
- ${SED} ${SED_DBDIR} ${SED_HOOKDIR} ${SED_SCRIPT} ${SED_SYS} $< > $@
+ ${SED} ${SED_DBDIR} ${SED_HOOKDIR} ${SED_SCRIPT} ${SED_SYS} \
+ ${SED_SERVICEEXISTS} ${SED_SERVICECMD} ${SED_SERVICESTATUS} \
+ $< > $@
all: config.h ${PROG} ${SCRIPTS} ${MAN5} ${MAN8}
BSD systems where this has been fixed are:
NetBSD-5.0
+We try and detect how dhcpcd should interact with system services during the
+configure stage. If we cannot auto-detect how do to this, or it is wrong then
+you can change this by passing shell commands to --service-exists,
+--servicecmd and optionally --servicestatus.
To prepare dhcpcd for import into a platform source tree (like NetBSD)
you can use the make import target to create /tmp/dhcpcd-$version and
--without-closefrom) CLOSEFROM=no;;
--without-getline) GETLINE=no;;
--without-strlcpy) STRLCPY=no;;
+ --serviceexists) SERVICEEXISTS=$var;;
+ --servicecmd) SERVICECMD=$var;;
+ --servicestatus) SERVICESTATUS=$var;;
--includedir) eval INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }$var";;
--datadir|--infodir) ;; # ignore autotools
--disable-maintainer-mode|--disable-dependency-tracking) ;;
echo "#include \"compat/strlcpy.h\"" >>$CONFIG_H
fi
+if [ -z "$SERVICECMD" ]; then
+ printf "Checking for OpenRC ... "
+ if [ -x /sbin/rc-service ]; then
+ SERVICEEXISTS="/sbin/rc-service -e \$1"
+ SERVICECMD="/sbin/rc-service \$1 -- -D \$2"
+ echo "yes"
+ else
+ echo "no"
+ fi
+fi
+if [ -z "$SERVICECMD"]; then
+ printf "Checking for invoke-rc.d ... "
+ if [ -x /usr/sbin/invoke-rc.d ]; then
+ SERVICEEXISTS="/usr/sbin/invoke-rc.d --query --quiet \$1 start >/dev/null 2>&1 || [ \$? = 104 ]"
+ SERVICECMD="/usr/sbin/invoke-rc.d \$1 \$2"
+ echo "yes"
+ else
+ echo "no"
+ fi
+fi
+if [ -z "$SERVICECMD" ]; then
+ printf "Checking for service ... "
+ if [ -x /sbin/service ]; then
+ SERVICEEXISTS="/sbin/service \$1 >/dev/null 2>&1"
+ SERVICECMD="/sbin/service \$1 \$2"
+ echo "yes"
+ else
+ echo "no"
+ fi
+fi
+if [ -z "$SERVICECMD" ]; then
+ for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do
+ printf "Checking for $x ... "
+ if [ -d $x ]; then
+ SERVICEEXISTS="[ -x $x/\$1 ]"
+ SERVICECMD="$x/\$1 \$2"
+ echo "yes"
+ break
+ else
+ echo "no"
+ fi
+ done
+fi
+if [ -e /etc/arch-release ]; then
+ echo "Overriding service status check for Arch Linux"
+ SERVICESTATUS="[ -e /var/run/daemons/$1 ]"
+ echo "yes"
+fi
+
+if [ -z "$SERVICEEXISTS" -o -z "$SERVICECMD" ]; then
+ echo "WARNING! No means of interacting with system services detected!"
+ SERVICEEXISTS="return 1"
+ SERVICECMD="return 1"
+fi
+if [ -z "$SERVICESTATUS" ]; then
+ SERVICESTATUS="service_command \$1 status >/dev/null 2>&1"
+fi
+# Transform for a make file
+SERVICEEXISTS=$(echo "$SERVICEEXISTS" | sed \
+ -e 's:\\:\\\\:g' \
+ -e 's:\&:\\\&:g' \
+ -e 's:\$:\$\$:g' \
+)
+echo "SERVICEEXISTS= $SERVICEEXISTS" >>config.mk
+SERVICECMD=$(echo "$SERVICECMD" | sed \
+ -e 's:\\:\\\\:g' \
+ -e 's:\&:\\\&:g' \
+ -e 's:\$:\$\$:g' \
+)
+echo "SERVICECMD= $SERVICECMD" >>config.mk
+SERVICESTATUS=$(echo "$SERVICESTATUS" | sed \
+ -e 's:\\:\\\\:g' \
+ -e 's:\&:\\\&:g' \
+ -e 's:\$:\$\$:g' \
+)
+echo "SERVICESTATUS= $SERVICESTATUS" >>config.mk
+
HOOKS=
if ! $HOOKSET; then
printf "Checking for ntpd ... "
# NTP_CONF=/usr/pkg/etc/ntpd.conf
# to use openntpd from pkgsrc instead of the system provided ntp.
-# Detect OpenRC, Debian or BSD rc
-# Distributions may want to just have their command here instead of this
-if type rc-service >/dev/null 2>&1 && rc-service --exists ntpd; then
- ntpd_restart_cmd="rc-service ntpd -- -Ds restart"
-elif type invoke-rc.d >/dev/null 2>&1; then
- if [ -x /etc/init.d/ntp ]; then
- ntpd_restart_cmd="invoke-rc.d ntp try-restart"
- fi
- # Debian as a seperate file for DHCP config to avoid stamping on
+: ${ntpd_restart_cmd:="service_condcommand ntpd restart || service_condcommand ntp restart"}
+if type invoke-rc.d >/dev/null 2>&1; then
+ # Debian has a seperate file for DHCP config to avoid stamping on
# the master.
[ -e /var/lib/ntp ] || mkdir /var/lib/ntp
: ${NTP_DHCP_CONF:=/var/lib/ntp/ntp.conf.dhcp}
-elif [ -x /etc/rc.d/ntpd ]; then
- ntpd_restart_cmd="/etc/rc.d/ntpd status >/dev/null 2>&1 && /etc/rc.d/ntpd restart"
-elif [ -x /usr/local/etc/rc.d/ntpd ]; then
- ntpd_restart_cmd="/usr/local/etc/rc.d/ntpd status >/dev/null 2>&1 && /usr/local/etc/rc.d/ntpd restart"
fi
ntp_conf_dir="$state_dir/ntp.conf"
fi
fi
- if [ -n "$NTP_DHCP_CONF" ]; then
- cp "$ntp_conf" "$NTP_DHCP_CONF"
- ntp_conf="$NTP_DHCP_CONF"
- fi
-
# Merge our config into ntp.conf
[ -e "$cf" ] && rm -f "$cf"
[ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"
- if [ -e "$ntp_conf" ]; then
+
+ if [ -n "$NTP_DHCP_CONF" ]; then
+ cp "$ntp_conf" "$cf"
+ ntp_conf="$NTP_DHCP_CONF"
+ elif [ -e "$ntp_conf" ]; then
remove_markers "$signature_base" "$signature_base_end" \
"$ntp_conf" > "$cf"
fi
+
if [ -n "$servers" ]; then
echo "$signature_base${header:+ $from }$header" >> "$cf"
printf "$search$servers" >> "$cf"
# Sample dhcpcd hook for ypbind
# This script is only suitable for the Linux version.
-# Distributions may want to just have their command here instead of this
-if [ -x /etc/rc.d/ypbind ]; then
- ypbind_restart_cmd="/etc/rc.d/ypbind restart"
- ypbind_stop_cmd="/etc/rc.d/ypbind stop"
-elif [ -x /usr/local/etc/rc.d/ypbind ]; then
- ypbind_restart_cmd="/usr/local/etc/rc.d/ypbind restart"
- ypbind_stop_cmd="/usr/local/etc/rc.d/ypbind stop"
-fi
-
+: ${ypbind_restart_cmd:="service_command ypbind restart"}
+: ${ypbind_stop_cmd:="service_condcommand ypbind stop"}
ypbind_dir="$state_dir/ypbind"
best_domain()
fi
}
+# Check a system service exists
+service_exists()
+{
+ @SERVICEEXISTS@
+}
+
+# Send a command to a system service
+service_cmd()
+{
+ @SERVICECMD@
+}
+
+# Send a command to a system service if it is running
+service_status()
+{
+ @SERVICESTATUS@
+}
+
+# Handy macros for our hooks
+service_command()
+{
+ service_exists $1 && service_cmd $1 $2
+}
+service_condcommand()
+{
+ service_exists $1 && service_status $1 && service_cmd $1 $2
+}
# We source each script into this one so that scripts run earlier can
# remove variables from the environment so later scripts don't see them.