[libvirt] [PATCH] network: detect conflicting route even if it is the final entry

This is a folloup to commit 5f719596, which checks for a route conflicting with the standard libvirt default network subnet (192.168.122.0/24). It turns out that the output of "ip route show" doesn't have a trailing newline, so there would be no match if the route we were looking for was the final line of output. This can be solved by adding ${nl} to the end of the output (just as we were already doing at the beginning of the output). --- libvirt.spec.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvirt.spec.in b/libvirt.spec.in index c2e2be4..bec3a50 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1737,7 +1737,7 @@ if test $1 -eq 1 && test ! -f %{_sysconfdir}/libvirt/qemu/networks/default.xml ; sub=${orig_sub} nl=' ' - routes="${nl}$(ip route show | cut -d' ' -f1)" + routes="${nl}$(ip route show | cut -d' ' -f1)${nl}" case ${routes} in *"${nl}192.168.${orig_sub}.0/24${nl}"*) # there was a match, so we need to look for an unused subnet -- 1.9.3

On 09/15/2014 11:34 AM, Laine Stump wrote:
This is a folloup to commit 5f719596, which checks for a route conflicting with the standard libvirt default network subnet (192.168.122.0/24). It turns out that the output of "ip route show" doesn't have a trailing newline,
Well, 'ip' outputs the trailing newline, but $() strips it.
so there would be no match if the route we were looking for was the final line of output. This can be solved by adding ${nl} to the end of the output (just as we were already doing at the beginning of the output). --- libvirt.spec.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK, and sorry for missing it the first time
diff --git a/libvirt.spec.in b/libvirt.spec.in index c2e2be4..bec3a50 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1737,7 +1737,7 @@ if test $1 -eq 1 && test ! -f %{_sysconfdir}/libvirt/qemu/networks/default.xml ; sub=${orig_sub} nl=' ' - routes="${nl}$(ip route show | cut -d' ' -f1)" + routes="${nl}$(ip route show | cut -d' ' -f1)${nl}" case ${routes} in *"${nl}192.168.${orig_sub}.0/24${nl}"*) # there was a match, so we need to look for an unused subnet
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 09/15/2014 01:56 PM, Eric Blake wrote:
On 09/15/2014 11:34 AM, Laine Stump wrote:
This is a folloup to commit 5f719596, which checks for a route conflicting with the standard libvirt default network subnet (192.168.122.0/24). It turns out that the output of "ip route show" doesn't have a trailing newline, Well, 'ip' outputs the trailing newline, but $() strips it.
Aha! I'll modify the comment accordingly before I push.
so there would be no match if the route we were looking for was the final line of output. This can be solved by adding ${nl} to the end of the output (just as we were already doing at the beginning of the output). --- libvirt.spec.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK, and sorry for missing it the first time
Seeing that you gave me the cool idea of using a case statement to replace invocation of grep, and were just typing off the top of your head, that's totally understandable and acceptable! :-)
participants (2)
-
Eric Blake
-
Laine Stump