diff --git a/dhclient-script b/dhclient-script index e7c713c..e2a233c 100644 --- a/dhclient-script +++ b/dhclient-script @@ -182,14 +182,44 @@ make_resolv_conf() { fi } -exit_with_hooks() { - exit_status="${1}" +# run given script +run_hook() { + local script + local exit_status + script="${1}" + + if [ -f ${script} ]; then + . ${script} + fi - if [ -x ${ETCDIR}/dhclient-exit-hooks ]; then - . ${ETCDIR}/dhclient-exit-hooks + if [ -n "${exit_status}" ] && [ "${exit_status}" -ne 0 ]; then + logmessage "${script} returned non-zero exit status ${exit_status}" fi - exit "${exit_status}" + return ${exit_status} +} + +# run scripts in given directory +run_hookdir() { + local dir + dir="${1}" + + if [ -d "${dir}" ]; then + for script in $(run-parts --list $dir); do + run_hook ${script} || return $? + done + fi + + return 0 +} + +exit_with_hooks() { + # Source the documented exit-hook script, if it exists + run_hook "${ETCDIR}/dhclient-exit-hooks" || exit $? + # Now run scripts in the hooks directory. + run_hookdir "${ETCDIR}/dhclient-exit-hooks.d" || exit $? + + exit ${1} } quad2num() { @@ -488,7 +518,7 @@ dhconfig() { ip -4 addr replace "${alias_ip_address}/${alias_prefix}" broadcast "${alias_broadcast_address}" dev "${interface}" label "${interface}:0" ip -4 route replace "${alias_ip_address}/32" dev "${interface}" fi - + # After dhclient brings an interface UP with a new IP address, subnet mask, # and routes, in the REBOOT/BOUND states -> search for "dhclient-up-hooks". if [ "${reason}" = "BOUND" ] || [ "${reason}" = "REBOOT" ] || @@ -498,7 +528,7 @@ dhconfig() { [ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] || [ ! "${old_routers}" = "${new_routers}" ] || [ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then - + if [ -x "${ETCDIR}/dhclient-${interface}-up-hooks" ]; then . "${ETCDIR}/dhclient-${interface}-up-hooks" elif [ -x ${ETCDIR}/dhclient-up-hooks ]; then @@ -629,16 +659,9 @@ dh6config() { # ### MAIN # -if [ -x ${ETCDIR}/dhclient-enter-hooks ]; then - exit_status=0 - - # dhclient-enter-hooks can abort dhclient-script by setting - # the exit_status variable to a non-zero value - . ${ETCDIR}/dhclient-enter-hooks - if [ ${exit_status} -ne 0 ]; then - exit ${exit_status} - fi -fi +# Invoke the local dhcp client enter hooks, if they exist. +run_hook "${ETCDIR}/dhclient-enter-hooks" || exit $? +run_hookdir "${ETCDIR}/dhclient-enter-hooks.d" || exit $? if [ ! -r /etc/sysconfig/network-scripts/network-functions ]; then echo "Missing /etc/sysconfig/network-scripts/network-functions, exiting." >&2 diff --git a/dhcp.spec b/dhcp.spec index 4982a2a..7f18657 100644 --- a/dhcp.spec +++ b/dhcp.spec @@ -18,7 +18,7 @@ Summary: Dynamic host configuration protocol software Name: dhcp Version: 4.3.2 -Release: 5%{?dist} +Release: 6%{?dist} # NEVER CHANGE THE EPOCH on this package. The previous maintainer (prior to # dcantrell maintaining the package) made incorrect use of the epoch and # that's why it is at 12 now. It should have never been used, but it was. @@ -675,6 +675,9 @@ done %doc doc/html/ %changelog +* Tue May 26 2015 Jiri Popelka - 12:4.3.2-6 +- dhclient-script: run also scripts in dhclient-[enter/exit]-hooks.d dir + * Tue Apr 21 2015 Jiri Popelka - 12:4.3.2-5 - dhclient-script: add a minute to address lifetimes (#1188423)