app-emulation/rkt: Allow several --hosts-entry=host args

This commit is contained in:
David Michael 2017-10-24 12:04:08 -07:00
parent 6ea01e5963
commit c527617564
3 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,68 @@
From ce936a91678b77a2b91440e0198c895519ca8b24 Mon Sep 17 00:00:00 2001
From: Luca Bruno <luca.bruno@coreos.com>
Date: Mon, 23 Oct 2017 08:49:09 +0000
Subject: [PATCH] stage0/run: relax '--hosts-entry' parser
This tweaks the '--hosts-entry' CLI flag parser to accept multiple
time the special value "host" when there are no other conflicting
settings.
---
rkt/run.go | 14 +++++++-------
tests/rkt_etc_hosts_test.go | 5 +++++
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/rkt/run.go b/rkt/run.go
index b852e13a6..ab4121475 100644
--- a/rkt/run.go
+++ b/rkt/run.go
@@ -18,6 +18,7 @@ package main
import (
"bufio"
+ "errors"
"fmt"
"net"
"os"
@@ -643,13 +644,8 @@ func parseDNSFlags(flagHostsEntries, flagDNS, flagDNSSearch, flagDNSOpt []string
// Parse out --hosts-entries, also looking for the magic value "host"
for _, entry := range flagHostsEntries {
if entry == "host" {
- if len(flagHostsEntries) == 1 {
- DNSConfMode.Hosts = "host"
- } else {
- return DNSConfMode, DNSConfig, &HostsEntries,
- fmt.Errorf("cannot pass --hosts-entry=host with multiple hosts-entries")
- }
- break
+ DNSConfMode.Hosts = "host"
+ continue
}
for _, entry := range strings.Split(entry, ",") {
vals := strings.SplitN(entry, "=", 2)
@@ -677,6 +673,10 @@ func parseDNSFlags(flagHostsEntries, flagDNS, flagDNSSearch, flagDNSOpt []string
}
if len(HostsEntries) > 0 {
+ if DNSConfMode.Hosts == "host" {
+ return DNSConfMode, DNSConfig, &HostsEntries,
+ errors.New("cannot pass --hosts-entry=host with multiple hosts-entries")
+ }
DNSConfMode.Hosts = "stage0"
}
diff --git a/tests/rkt_etc_hosts_test.go b/tests/rkt_etc_hosts_test.go
index 374916834..b3967cf6e 100644
--- a/tests/rkt_etc_hosts_test.go
+++ b/tests/rkt_etc_hosts_test.go
@@ -80,6 +80,11 @@ func TestEtcHosts(t *testing.T) {
"--exec=/inspect -- -file-name=/etc/hosts -hash-file",
sum,
},
+ { // Test that multiple '--hosts-entry=host' entries are fine
+ "--hosts-entry=host --hosts-entry=host",
+ "--exec=/inspect -- -file-name=/etc/hosts -hash-file",
+ sum,
+ },
{ // test that we create our own
"--hosts-entry=128.66.0.99=host1",
"--exec=/inspect -- -file-name=/etc/hosts -read-file",

View File

@ -84,6 +84,8 @@ src_prepare() {
die "CoreOS versions in ebuild and rkt build scripts are mismatched, expecting ${rkt_coreos_version}!"
fi
epatch "${FILESDIR}/${PN}-1.29.0-allow-multiple-hosts-entry-host.patch"
autotools-utils_src_prepare
}