From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Tremer <michael.tremer@ipfire.org> To: development@lists.ipfire.org Subject: Re: [Patch RFC 15/15] network startup: Only work with configured zones Date: Wed, 24 May 2023 10:00:55 +0100 Message-ID: <41E36FDB-A756-49A4-B982-9229EA993565@ipfire.org> In-Reply-To: <20230523172314.7826-16-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6028763307508620803==" List-Id: <development.lists.ipfire.org> --===============6028763307508620803== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable See my former email about how to fix this. I believe this is the third patch in this series that touches the same code b= y adding/removing arrays and keeping status. Just use the functions that you have created as it will make this all a lot e= asier to read and extend whenever necessary. -Michael > On 23 May 2023, at 18:23, Jonatan Schlag <jonatan.schlag(a)ipfire.org> wrot= e: >=20 > Otherwise the called script fails with an failure message. > This does not hurt but is ugly. > I also changed my mind about the wording here. Because we only have four > possible zones we could talk about valid zones. But I think it is easier > and more future proof to talk about what is configured on the system. >=20 > Should make further changes easier. >=20 > Signed-off-by: Jonatan Schlag <jonatan.schlag(a)ipfire.org> > --- > src/initscripts/system/network | 37 +++++++++++++++++++--------------- > 1 file changed, 21 insertions(+), 16 deletions(-) >=20 > diff --git a/src/initscripts/system/network b/src/initscripts/system/network > index ff305e472..abbd5bd88 100644 > --- a/src/initscripts/system/network > +++ b/src/initscripts/system/network > @@ -21,6 +21,8 @@ >=20 > . /etc/sysconfig/rc > . ${rc_functions} > +. /etc/init.d/networking/functions.network > + > eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) >=20 > DO=3D"${1}" > @@ -31,34 +33,37 @@ if ! [[ "${DO}" =3D=3D "start" || "${DO}" =3D=3D "rest= art" || "${DO}" =3D=3D "stop" ]]; the > exit 1 > fi >=20 > -declare -a VALID_ZONES > +declare -a CONFIGURED_ZONES >=20 > -VALID_ZONES+=3D("blue") > -VALID_ZONES+=3D("green") > -VALID_ZONES+=3D("orange") > +for zone in blue green orange; do > + if is_${zone}_used; then > + CONFIGURED_ZONES+=3D("${zone}") > + fi > +done >=20 > -# If we are called as /etc/init.d/network also red is a valid zone. > -# Otherwise we are called as /etc/init.d/network-local where red > -# is invalid. > +# If we are called as /etc/init.d/network also red is a configured zone. > +# Otherwise we are called as /etc/init.d/network-local where we do > +# not need to take care of red > if [[ "$(basename $0)" =3D=3D "network" ]]; then > - VALID_ZONES+=3D("red") > + CONFIGURED_ZONES+=3D("red") > fi >=20 > declare -A ZONE_ACTION >=20 > -for i in "${VALID_ZONES[@]}"; do > +for i in "${CONFIGURED_ZONES[@]}"; do > ZONE_ACTION[${i}]=3Dfalse > done >=20 > if [ $# -eq 0 ]; then > - for i in "${VALID_ZONES[@]}"; do > - ZONE_ACTION[${i}]=3Dtrue > + for zone in "${CONFIGURED_ZONES[@]}"; do > + ZONE_ACTION[${zone}]=3Dtrue > done > fi >=20 > + > while [ $# -ne 0 ]; do > ZONE_VALID=3Dfalse > - for i in "${VALID_ZONES[@]}"; do > + for i in "${CONFIGURED_ZONES[@]}"; do > if [ "${i}" =3D=3D "${1}" ]; then > ZONE_ACTION[${i}]=3Dtrue > ZONE_VALID=3Dtrue > @@ -68,7 +73,7 @@ while [ $# -ne 0 ]; do > done >=20 > if ! ${ZONE_VALID}; then > - echo "'${1}' is not a valid zone. Cannot go on." > + echo "'${1}' is not configured on this system. Cannot go on." > exit 1 > fi > done > @@ -76,14 +81,14 @@ done > case "${DO}" in > start) > # Starting interfaces... > - for i in "${VALID_ZONES[@]}"; do > + for i in "${CONFIGURED_ZONES[@]}"; do > ${ZONE_ACTION[${i}]} && /etc/rc.d/init.d/networking/${i} start > done > ;; >=20 > stop) > # Stopping interfaces... > - for i in "${VALID_ZONES[@]}"; do > + for i in "${CONFIGURED_ZONES[@]}"; do > ${ZONE_ACTION[${i}]} && /etc/rc.d/init.d/networking/${i} stop > done >=20 > @@ -91,7 +96,7 @@ case "${DO}" in > ;; >=20 > restart) > - for i in "${VALID_ZONES[@]}"; do > + for i in "${CONFIGURED_ZONES[@]}"; do > if ${ZONE_ACTION[${i}]}; then > ARGS+=3D" ${i}" > fi > --=20 > 2.30.2 >=20 --===============6028763307508620803==--