examples/udhcp/simple.script: fix resolv.conf update if it is a dangling symlink
authorRolf Eike Beer <eb@emlix.com>
Thu, 28 Mar 2019 14:29:29 +0000 (15:29 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 13 Apr 2019 14:58:00 +0000 (16:58 +0200)
If /etc/resolv.conf is a symlink to a tmpfs and the actual file does not
already exist, "readlink -f" will not detect it as symlink. Explicitely check
for that condition before and touch the file, making the other code work as
intended.

Signed-off-by: Rolf Eike Beer <eb@emlix.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
examples/udhcp/simple.script

index 44aa46ece63f86ec2fd3d5975acd0157e7e910bf..53974e6d691773116c81d1794b6ad3c3c480b668 100755 (executable)
@@ -55,6 +55,10 @@ case "$1" in
                echo "Recreating $RESOLV_CONF"
                # If the file is a symlink somewhere (like /etc/resolv.conf
                # pointing to /run/resolv.conf), make sure things work.
+               if test -L "$RESOLV_CONF"; then
+                       # If it's a dangling symlink, try to create the target.
+                       test -e "$RESOLV_CONF" || touch "$RESOLV_CONF"
+               fi
                realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
                tmpfile="$realconf-$$"
                > "$tmpfile"