]> Frank Brehm's Git Trees - config/helga/etc.git/commitdiff
saving uncommitted changes in /etc prior to emerge run
authorroot <root@helga.brehm-online.com>
Sat, 7 Jan 2017 12:01:54 +0000 (13:01 +0100)
committerroot <root@helga.brehm-online.com>
Sat, 7 Jan 2017 12:01:54 +0000 (13:01 +0100)
init.d/net.lo

index ed6fe0d00254dbae6330242cec637b6bc987bd95..5577fa1bc019e081a9cf0e2d7baa8804f2be84c4 100755 (executable)
@@ -1,10 +1,12 @@
-#!/sbin/runscript
+#!/sbin/openrc-run
 # Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
+# Copyright (c) 2010-2016 Gentoo Foundation
 # Released under the 2-clause BSD license.
 
+SHDIR="/lib/netifrc/sh"
 MODULESDIR="/lib/netifrc/net"
 MODULESLIST="${RC_SVCDIR}/nettree"
-_config_vars="config routes"
+_config_vars="config metric routes"
 
 [ -z "${IN_BACKGROUND}" ] && IN_BACKGROUND="NO"
 
@@ -13,14 +15,25 @@ description="Configures network interfaces."
 # Handy var so we don't have to embed new lines everywhere for array splitting
 __IFS="
 "
+
+#  Set the INIT to be openrc if this file is called directly
+: ${INIT:=openrc}
+
+if [ -f "$SHDIR/functions.sh" ]; then
+       . "$SHDIR/functions.sh"
+else
+       echo "$SHDIR/functions.sh missing. Exiting"
+       exit 1
+fi
+
 depend()
 {
-       local IFACE=${RC_SVCNAME#*.}
+       local IFACE=$(get_interface)
        local IFVAR=$(shell_var "${IFACE}")
 
-       need localmount
        if [ "$RC_UNAME" = Linux -a "$IFACE" != lo ]; then
                need sysfs
+               after modules
        fi
        after bootmisc
        keyword -jail -prefix -vserver
@@ -29,6 +42,7 @@ depend()
                lo|lo0) ;;
                *)
                        after net.lo net.lo0 dbus
+                       need localmount
                        provide net
                        ;;
        esac
@@ -103,7 +117,7 @@ _flatten_array()
 
 _wait_for_carrier()
 {
-       local timeout= efunc=einfon
+       local timeout=
 
        _has_carrier  && return 0
 
@@ -113,20 +127,19 @@ _wait_for_carrier()
        # Incase users don't want this nice feature ...
        [ ${timeout} -le 0 ] && return 0
 
-       yesno ${RC_PARALLEL} && efunc=einfo
-       ${efunc} "Waiting for carrier (${timeout} seconds) "
+       einfon "Waiting for carrier (${timeout} seconds) "
        while [ ${timeout} -gt 0 ]; do
                if _has_carrier; then
-                       [ "${efunc}" = "einfon" ] && echo
+                       echo
                        eend 0
                        return 0
                fi
                sleep 1
                : $(( timeout -= 1 ))
-               [ "${efunc}" = "einfon" ] && printf "."
+               printf "."
        done
 
-       [ "${efunc}" = "einfon" ] && echo
+       echo
        eend 1
        return 1
 }
@@ -203,7 +216,7 @@ _program_available()
                        /*) [ -x "${x}" ] && break;;
                        *) type "${x}" >/dev/null 2>&1 && break;;
                esac
-               unset x
+               x=
        done
        [ -n "${x}" ] && echo $x && return 0
        return 1
@@ -214,20 +227,52 @@ _show_address()
        einfo "received address $(_get_inet_address "${IFACE}")"
 }
 
+# Allow custom error handling behavior to be set by the user.
+# Known used combinations, with defaults
+# errh_IFVAR_address_EEXIST=warn
+# errh_IFVAR_route_EEXIST=warn
+_get_errorhandler_behavior() {
+       IFVAR="$1"
+       object="$2"
+       error="$3"
+       fallback="$4"
+       value=
+       for key in \
+               "errh_${IFVAR}_${object}_${error}" \
+               "errh_${IFVAR}_${object}_DEFAULT" \
+               "errh_${IFVAR}_DEFAULT_${error}" \
+               "errh_${IFVAR}_DEFAULT_DEFAULT" \
+               "errh_DEFAULT_${object}_${error}" \
+               "errh_DEFAULT_${object}_DEFAULT" \
+               "errh_DEFAULT_DEFAULT_${error}" \
+               "errh_DEFAULT_DEFAULT_DEFAULT" \
+               "errh" \
+               "fallback" ; do
+               eval value="\${${key}}"
+               if [ -n "$value" ]; then
+                       echo "$value" && break
+               fi
+       done
+}
+
 # Basically sorts our modules into order and saves the list
 _gen_module_list()
 {
        local x= f= force=$1
-       if ! ${force} && [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt "${MODULESDIR}" ]; then
-               local update=false
-               for x in "${MODULESDIR}"/*.sh; do
-                       [ -e "${x}" ] || continue
-                       if [ "${x}" -nt "${MODULESLIST}" ]; then
-                               update=true
-                               break
-                       fi
-               done
-               ${update} || return 0
+       if ! ${force} ; then
+               if [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt /proc/$$/status ]; then
+                       ewarn "Discarding cached module list ($MODULESLIST) as it's newer current time!"
+               elif [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt "${MODULESDIR}" ]; then
+                       local update=false
+                       for x in "${MODULESDIR}"/*.sh; do
+                               [ -e "${x}" ] || continue
+                               if [ "${x}" -nt "${MODULESLIST}" ]; then
+                                       update=true
+                                       break
+                               fi
+                       done
+                       ${update} || return 0
+               fi
        fi
 
        einfo "Caching network module dependencies"
@@ -519,10 +564,22 @@ interface_down()
 {
        _run_if _down "$@"
 }
+set_interface_type()
+{
+       service_set_value iface_type "$@"
+}
+get_interface_type()
+{
+       ( RC_SVCNAME="net.$IFACE" service_get_value iface_type )
+}
+is_interface_type()
+{
+       [ "$(get_interface_type)" = "$1" ]
+}
 
 start()
 {
-       local IFACE=${RC_SVCNAME#*.} oneworked=false fallback=false module=
+       local IFACE=$(get_interface) oneworked=false fallback=false module=
        local IFVAR=$(shell_var "${IFACE}") cmd= our_metric=
        local metric=0 _up_before_preup
        eval _up_before_preup="\$up_before_preup_${IFVAR}"
@@ -636,7 +693,7 @@ start()
                return 1
        fi
 
-       local hideFirstroute=false first=true routes=
+       local first=true routes=
        if ${fallback}; then
                routes="$(_get_array "fallback_routes_${IFVAR}")"
        fi
@@ -647,7 +704,6 @@ start()
                if [ "${config_0}" != "null" ]; then
                        routes="127.0.0.0/8 via 127.0.0.1
 ${routes}"
-                       hideFirstroute=true
                fi
        fi
 
@@ -679,12 +735,7 @@ ${routes}"
                        *:*/*)                             cmd="-net ${cmd}";;
                        *)                                 cmd="-host ${cmd}";;
                esac
-               if ${hideFirstroute}; then
-                       _add_route ${fam} ${cmd} >/dev/null 2>&1
-                       hideFirstroute=false
-               else
-                       _add_route ${fam} ${cmd} >/dev/null
-               fi
+               _add_route ${fam} ${cmd}
                eend $?
                eoutdent
        done
@@ -717,7 +768,7 @@ stop()
        # correctly if we go back to multiuser.
        yesno ${keep_network:-YES} && yesno $RC_GOINGDOWN && return 0
 
-       local IFACE=${RC_SVCNAME#*.} module=
+       local IFACE=$(get_interface) module=
        local IFVAR=$(shell_var "${IFACE}") opts=
 
        einfo "Bringing down interface ${IFACE}"
@@ -787,3 +838,5 @@ stop()
 
        return 0
 }
+
+# vim:filetype=gentoo-init-d: