From: Roy Marples Date: Fri, 9 Oct 2009 16:26:23 +0000 (+0000) Subject: Remeber preferred domain list order so we fall back correctly. X-Git-Tag: v5.1.2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e155775ea95d3c0affb15be34d38507b3ed4ec96;p=thirdparty%2Fdhcpcd.git Remeber preferred domain list order so we fall back correctly. Stop ypbind when we don't have any domains so we don't stall. --- diff --git a/dhcpcd-hooks/50-ypbind b/dhcpcd-hooks/50-ypbind index 44f5bb17..3d569467 100644 --- a/dhcpcd-hooks/50-ypbind +++ b/dhcpcd-hooks/50-ypbind @@ -4,46 +4,66 @@ # 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_dir="$state_dir/ypbind" + +best_domain() +{ + local i= + + for i in $interfaces; do + if [ -e "$ypbind_dir/$i" ]; then + cat "$ypbind_dir/$i" + fi + done + return 1 +} + make_yp_binding() { - [ -z "$new_nis_domain" ] && return + [ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir" + echo "$new_nis_domain" >"$ypbind_dir/$interface" + local nd="$(best_domain)" local cf=/var/yp/binding/"$new_nis_domain".ypservers if [ -n "$new_nis_servers" ]; then local ncf="$cf.$interface" x= rm -f "$ncf" for x in $new_nis_servers; do - echo "$x" >> "$ncf" + echo "$x" >>"$ncf" done - if change_file "$cf" "$ncf"; then - if [ -n "$ypbind_restart_cmd" ]; then - eval $ypbind_restart_cmd - fi - fi + change_file "$cf" "$ncf" else - if [ -e "$cf" ]; then - rm "$cf" - if [ -n "$ypbind_restart_cmd" ]; then - eval $ypbind_restart_cmd - fi + # Because this is not an if .. fi then we can use $? below + [ -e "$cf" ] && rm "$cf" + fi + + if [ $? = 0 -o "$nd" != "$(domainname)" ]; then + domainname "$nd" + if [ -n "$ypbind_restart_cmd" ]; then + eval $ypbind_restart_cmd fi fi } restore_yp_binding() { - [ -z "$old_nis_domain" ] && return - - if restore_conf /var/yp/binding/"$old_nis_domain".ypservers; then - if [ -n "$ypbind_restart_cmd" ]; then - eval $ypbind_restart_cmd + rm -f "$ypbind_dir/$interface" + local nd="$(best_domain)" + # We need to stop ypbind if there is no best domain + # otherwise it will just stall as we cannot set domainname + # to blank :/ + if [ -z "$nd" ]; then + if [ -n "$ypbind_stop_cmd" ]; then + eval $ypbind_stop_cmd fi - elif [ -e /var/yp/binding/"$old_nis_domain".ypservers ]; then - rm /var/yp/binding/"$old_nis_domain".ypservers + elif [ "$nd" != "$(domainname)" ]; then + domainname "$nd" if [ -n "$ypbind_restart_cmd" ]; then eval $ypbind_restart_cmd fi @@ -51,6 +71,16 @@ restore_yp_binding() } case "$reason" in -BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) make_yp_binding;; -EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) restore_yp_binding;; +PREINIT) + rm -f "$ypbind_dir/$interface" + ;; +TEST) + ;; +*) + if [ -n "$new_nis_domain" ]; then + make_yp_binding + elif [ -n "$old_nis_domain" ]; then + restore_yp_binding + fi + ;; esac