Minimize differences in ifstart() function between netstart and
authorrpe <rpe@openbsd.org>
Fri, 7 Apr 2017 22:53:25 +0000 (22:53 +0000)
committerrpe <rpe@openbsd.org>
Fri, 7 Apr 2017 22:53:25 +0000 (22:53 +0000)
install.sub which makes it easier to spot changes in the future.

- comments and formatting
- quotes on assignments are not needed (netstart)
- remove stray space in test (netstart)
- use $file variable with while-loop (netstart)
- although valid, instead of i use $i in arithmetic test (install.sub)

OK krw@, tb@
Looks good deraadt@

distrib/miniroot/install.sub
etc/netstart

index e81f59a..4171e07 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/ksh
-#      $OpenBSD: install.sub,v 1.994 2017/04/07 22:15:17 rpe Exp $
+#      $OpenBSD: install.sub,v 1.995 2017/04/07 22:53:25 rpe Exp $
 #
 # Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback
 # Copyright (c) 2015, Robert Peichaer <rpe@openbsd.org>
@@ -2131,29 +2131,30 @@ ifstart () {
                        # Make sure and get any remaining args in ext2,
                        # like the read below.
                        i=1
-                       while [ i -lt 6 -a -n "$1" ]; do shift; let i=i+1; done
+                       while [ $i -lt 6 -a -n "$1" ]; do shift; let i=i+1; done
                        ext2="$@"
                else
                        # Read the next line or exit the while loop.
                        read af name mask bcaddr ext1 ext2 || break
                fi
-               # $af can be "dhcp", "rtsol", an address family, commands,
+               # $af can be "dhcp", "up", "rtsol", an address family, commands,
                # or a comment.
                case "$af" in
                "#"*|"!"*|"bridge"|"")
                        # Skip comments, user commands, bridges, and empty lines.
                        continue
                        ;;
-               "dhcp") [ "$name" = "NONE" ] && name=
+               "dhcp")
+                       [ "$name" = "NONE" ] && name=
                        [ "$mask" = "NONE" ] && mask=
                        [ "$bcaddr" = "NONE" ] && bcaddr=
-                       dhcpif="$dhcpif $if"
                        cmd="ifconfig $if $name $mask $bcaddr $ext1 $ext2 down"
                        if [[ -x /sbin/dhclient ]]; then
                                cmd="$cmd; dhclient $if"
                        else
                                cmd="$cmd; echo /sbin/dhclient missing - skipping dhcp request."
                        fi
+                       dhcpif="$dhcpif $if"
                        ;;
                "rtsol")
                        if ifconfig $if inet6 >/dev/null 2>&1; then
@@ -2163,7 +2164,8 @@ ifstart () {
                                cmd="$cmd; echo no INET6 support - skipping rtsol request."
                        fi
                        ;;
-               *)      read dt dtaddr
+               *)
+                       read dt dtaddr
                        if [ "$name" = "alias" ]; then
                                # Perform a 'shift' of sorts.
                                alias=$name
@@ -2177,7 +2179,8 @@ ifstart () {
                        fi
                        cmd="ifconfig $if $af $alias $name"
                        case "$dt" in
-                       dest)   cmd="$cmd $dtaddr"
+                       dest)
+                               cmd="$cmd $dtaddr"
                                ;;
                        *)
                                cmd2="$dt $dtaddr"
@@ -2190,7 +2193,7 @@ ifstart () {
                                        return
                                fi
                                [ "$mask" ] && cmd="$cmd netmask $mask"
-                               if [ "$bcaddr" -a X"$bcaddr" != "XNONE" ]; then
+                               if [ "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
                                        cmd="$cmd broadcast $bcaddr"
                                fi
                                ;;
@@ -2202,7 +2205,8 @@ ifstart () {
                                [ "$mask" ] && cmd="$cmd prefixlen $mask"
                                cmd="$cmd $bcaddr"
                                ;;
-                       *)      cmd="$cmd $mask $bcaddr"
+                       *)
+                               cmd="$cmd $mask $bcaddr"
                                ;;
                        esac
                        cmd="$cmd $ext1 $ext2"
index 8847641..6586b06 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/sh -
 #
-#      $OpenBSD: netstart,v 1.174 2017/04/07 22:15:17 rpe Exp $
+#      $OpenBSD: netstart,v 1.175 2017/04/07 22:53:25 rpe Exp $
 
 # Turn off Strict Bourne shell mode.
 set +o sh
@@ -51,7 +51,7 @@ ifstart() {
                        # We are carrying over from the 'read dt dtaddr'
                        # last time.
                        set -- $cmd2
-                       af="$1" name="$2" mask="$3" bcaddr="$4" ext1="$5" cmd2=
+                       af=$1 name=$2 mask=$3 bcaddr=$4 ext1=$5 cmd2=
                        # Make sure and get any remaining args in ext2,
                        # like the read below.
                        i=1
@@ -64,7 +64,8 @@ ifstart() {
                # $af can be "dhcp", "up", "rtsol", an address family, commands,
                # or a comment.
                case "$af" in
-               "#"*|"") # Skip comments and empty lines.
+               "#"*|"")
+                       # Skip comments and empty lines.
                        continue
                        ;;
                "!"*) # Parse commands.
@@ -84,7 +85,7 @@ ifstart() {
                        ;;
                *)
                        read dt dtaddr
-                       if [ "$name"  = "alias" ]; then
+                       if [ "$name" = "alias" ]; then
                                # Perform a 'shift' of sorts.
                                alias=$name
                                name=$mask
@@ -131,7 +132,7 @@ ifstart() {
                        ;;
                esac
                eval "$cmd"
-       done </etc/hostname.$if
+       done <$file
 }
 
 # Start multiple interfaces by driver name.