[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] tools/hotplug: Fix dhcpd symlink removal in vif-nat


  • To: Diego Sueiro <Diego.Sueiro@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Wed, 9 Sep 2020 13:31:41 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZkpJUbze06xi+6+RKGfWhJNn196+Ov88gxyXTtn9pKQ=; b=Quq2Om+S8SeCA44qr5LpyYjpOp30O3fWdU5n7qz1QVBNGUY8Oz+sOZI3aZgh3KGsFaP/vJY1FIjrj52vMvNGZzv1pnH1orKnMXHYp7iuCPgHyyJkE5eOF39vJ0d8/10EZtYOB7aqRi72N3bDvVft3j/f7DBT/akcOrvYB/uhNnCrww21oL5GlTHZQ9tlgCuKqtFOvdiMUVJ01oE09LjW4cFpxfpj9gOM5kRI+QjmO6KrFnxjSWViDdJQ94LJ6c0q43U13wntM5hgSJ7MB9Bb2o0Flv8zd3xaAS4W4I3EwJiYswL1dlrzMs3oqy3+jChMh2Z0qaHI3t1z22Xj7f79ig==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iBt1EVruHaXkGjreLhryIoMJ2B7tWBO2TWjRcMUgiLzvtpayg8B4c6lr2Dc+ItrY2LopB58Kelt/2f6rgo1s1WwwKb0Q1uwDg2P9DyL6aD0vfzpYk16CPhJOWkWc1was3WeowZgmdYQ6ljdWCcoG1F4/y/3MvhNy4/Iu7gGSeJ95XMQG8vNac04Uc72upELhRGZoeOmi+IPPGAFD8a/5IZ+q9YfDFRiDm3MePbI7UUEoFBxwkxQ/TT5D2vzLM7CpUURhHCow/Q3Hb00dQAVzwZdIJCpVsCmHjZ8UH0LxLaGnSGLQ0bSy+SFdekyTxzHhZ6g+ktb+EgdMr4G+Y8vIpg==
  • Authentication-results-original: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com;
  • Cc: "open list:X86" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, nd <nd@xxxxxxx>, Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Wed, 09 Sep 2020 13:32:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHWhqYja4pY5XRPLkWmrPgjNz9n1algTc6A
  • Thread-topic: [PATCH v2] tools/hotplug: Fix dhcpd symlink removal in vif-nat


> On 9 Sep 2020, at 13:35, Diego Sueiro <Diego.Sueiro@xxxxxxx> wrote:
> 
> Copy temp files used to add/remove dhcpd configurations to avoid
> replacing potential symlinks.
> 
> If dhcp.conf is a symlink pointing to dhcp.conf.real, using 'mv'
> creates a new file dhcp.conf where cp will actually modify
> dhcp.conf.real instead of replacing the symlink with a real
> file.
> 
> Using 'cp' prevents some mistakes where the user will actually
> continue to modify dhcp.conf.real where it would not be the one
> used anymore.
> 
> Signed-off-by: Diego Sueiro <diego.sueiro@xxxxxxx>
Reviewed-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>

> ---
> Changes in v2:
>  - Update commit message
>  - Simplify the code when removing the temp file.
> ---
> tools/hotplug/Linux/vif-nat | 20 +++++++++-----------
> 1 file changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/hotplug/Linux/vif-nat b/tools/hotplug/Linux/vif-nat
> index 2614435..fd34afb 100644
> --- a/tools/hotplug/Linux/vif-nat
> +++ b/tools/hotplug/Linux/vif-nat
> @@ -95,12 +95,11 @@ dhcparg_remove_entry()
> {
>   local tmpfile=$(mktemp)
>   sed -e "s/${dev} //" "$dhcpd_arg_file" >"$tmpfile"
> -  if diff "$tmpfile" "$dhcpd_arg_file" >/dev/null
> +  if ! diff "$tmpfile" "$dhcpd_arg_file" >/dev/null
>   then
> -    rm "$tmpfile"
> -  else
> -    mv "$tmpfile" "$dhcpd_arg_file"
> +    cp "$tmpfile" "$dhcpd_arg_file"
>   fi
> +  rm "$tmpfile"
> }
> 
> dhcparg_add_entry()
> @@ -109,11 +108,11 @@ dhcparg_add_entry()
>   local tmpfile=$(mktemp)
>   # handle Red Hat, SUSE, and Debian styles, with or without quotes
>   sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"${dev} "'"/' \
> -     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
> +     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
>   sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"${dev} "'"/' \
> -     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
> +     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
>   sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"${dev} "'"/' \
> -     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
> +     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
>   rm -f "$tmpfile"
> }
> 
> @@ -121,12 +120,11 @@ dhcp_remove_entry()
> {
>   local tmpfile=$(mktemp)
>   grep -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile"
> -  if diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
> +  if ! diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
>   then
> -    rm "$tmpfile"
> -  else
> -    mv "$tmpfile" "$dhcpd_conf_file"
> +    cp "$tmpfile" "$dhcpd_conf_file"
>   fi
> +  rm "$tmpfile"
>   dhcparg_remove_entry
> }
> 
> -- 
> 2.7.4
> 
> 




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.