diff options
author | Peter Hunt <pehunt@redhat.com> | 2019-03-03 22:54:41 -0500 |
---|---|---|
committer | Peter Hunt <pehunt@redhat.com> | 2019-03-05 13:15:25 -0500 |
commit | 6c8f2072aaa3e0b46b2f8d94331fcc88ec6bff11 (patch) | |
tree | 1189b9992d002a641ae8cb00f72d39e3bfceb171 /libpod/container_internal.go | |
parent | 3614764b70b8541444e8e9966075ccef082535b0 (diff) | |
download | podman-6c8f2072aaa3e0b46b2f8d94331fcc88ec6bff11.tar.gz podman-6c8f2072aaa3e0b46b2f8d94331fcc88ec6bff11.tar.bz2 podman-6c8f2072aaa3e0b46b2f8d94331fcc88ec6bff11.zip |
Append hosts to dependency container's /etc/hosts file
Before, any container with a netNS dependency simply used its dependency container's hosts file, and didn't abide its configuration (mainly --add-host). Fix this by always appending to the dependency container's hosts file, creating one if necessary.
Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r-- | libpod/container_internal.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index e3753d825..08945c410 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1231,6 +1231,23 @@ func (c *Container) writeStringToRundir(destFile, output string) (string, error) return filepath.Join(c.state.DestinationRunDir, destFile), nil } +// appendStringToRundir appends the provided string to the runtimedir file +func (c *Container) appendStringToRundir(destFile, output string) (string, error) { + destFileName := filepath.Join(c.state.RunDir, destFile) + + f, err := os.OpenFile(destFileName, os.O_APPEND|os.O_WRONLY, 0600) + if err != nil { + return "", errors.Wrapf(err, "unable to open %s", destFileName) + } + defer f.Close() + + if _, err := f.WriteString(output); err != nil { + return "", errors.Wrapf(err, "unable to write %s", destFileName) + } + + return filepath.Join(c.state.DestinationRunDir, destFile), nil +} + // Save OCI spec to disk, replacing any existing specs for the container func (c *Container) saveSpec(spec *spec.Spec) error { // If the OCI spec already exists, we need to replace it |