Don't echo a trailing newline when listing resolv.conf contents.
authorRoy Marples <roy@marples.name>
Wed, 24 Feb 2016 20:17:28 +0000 (20:17 +0000)
committerRoy Marples <roy@marples.name>
Wed, 24 Feb 2016 20:17:28 +0000 (20:17 +0000)
resolvconf.in

index 4a2ed2807347a6b0184d1723f49a17cc4fb7b0ae..a574912777124d432092c9c686158b9f3a15579a 100644 (file)
@@ -112,27 +112,6 @@ usage()
        error_exit "$*"
 }
 
-echo_resolv()
-{
-       local line= OIFS="$IFS"
-
-       [ -n "$1" -a -f "$IFACEDIR/$1" ] || return 1
-       echo "# resolv.conf from $1"
-       # Our variable maker works of the fact each resolv.conf per interface
-       # is separated by blank lines.
-       # So we remove them when echoing them.
-       while read -r line; do
-               IFS="$OIFS"
-               if [ -n "$line" ]; then
-                       # We need to set IFS here to preserve any whitespace
-                       IFS=''
-                       printf "%s\n" "$line"
-               fi
-       done < "$IFACEDIR/$1"
-       echo
-       IFS="$OIFS"
-}
-
 # Strip any trailing dot from each name as a FQDN does not belong
 # in resolv.conf(5)
 # If you think otherwise, capture a DNS trace and you'll see libc
@@ -345,6 +324,26 @@ fi"
        return 0
 }
 
+echo_resolv()
+{
+       local line= OIFS="$IFS"
+
+       [ -n "$1" -a -f "$IFACEDIR/$1" ] || return 1
+       echo "# resolv.conf from $1"
+       # Our variable maker works of the fact each resolv.conf per interface
+       # is separated by blank lines.
+       # So we remove them when echoing them.
+       while read -r line; do
+               IFS="$OIFS"
+               if [ -n "$line" ]; then
+                       # We need to set IFS here to preserve any whitespace
+                       IFS=''
+                       printf "%s\n" "$line"
+               fi
+       done < "$IFACEDIR/$1"
+       IFS="$OIFS"
+}
+
 list_resolv()
 {
        [ -d "$IFACEDIR" ] || return 0
@@ -404,6 +403,7 @@ list_resolv()
 
        cd "$IFACEDIR"
        retval=1
+       excl=true
        for i in $(uniqify $list); do
                # Only list interfaces which we really have
                if ! [ -f "$i" ]; then
@@ -417,6 +417,12 @@ list_resolv()
                if [ "$cmd" = i -o "$cmd" = "-i" ]; then
                        printf %s "$i "
                else
+                       # To avoid trailing a blank line at the end
+                       if $excl; then
+                               excl=false
+                       else
+                               echo
+                       fi
                        echo_resolv "$i"
                fi
                [ $? = 0 -a "$retval" = 1 ] && retval=0