From 7243c7109c69520cdd22d80e5a1f15da8d31ada4 Mon Sep 17 00:00:00 2001 From: Bo Wang Date: Tue, 4 Jun 2024 15:19:49 +0800 Subject: [PATCH] fix(libpod): add newline character to the end of container's hostname file debian's man (5) hostname page states "The file should contain a single newline-terminated hostname string." [NO NEW TESTS NEEDED] fix #22729 Signed-off-by: Bo Wang --- libpod/container_internal_linux.go | 2 +- test/e2e/run_dns_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 5385d95705..42223587ef 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -664,7 +664,7 @@ func (c *Container) makePlatformBindMounts() error { // Make /etc/hostname // This should never change, so no need to recreate if it exists if _, ok := c.state.BindMounts["/etc/hostname"]; !ok { - hostnamePath, err := c.writeStringToRundir("hostname", c.Hostname()) + hostnamePath, err := c.writeStringToRundir("hostname", c.Hostname()+"\n") if err != nil { return fmt.Errorf("creating hostname file for container %s: %w", c.ID(), err) } diff --git a/test/e2e/run_dns_test.go b/test/e2e/run_dns_test.go index 341831349a..126c17a741 100644 --- a/test/e2e/run_dns_test.go +++ b/test/e2e/run_dns_test.go @@ -60,7 +60,7 @@ var _ = Describe("Podman run dns", func() { session := podmanTest.Podman([]string{"run", "--hostname=foobar", ALPINE, "cat", "/etc/hostname"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) - Expect(session.OutputToString()).To(Equal("foobar")) + Expect(string(session.Out.Contents())).To(Equal("foobar\n")) session = podmanTest.Podman([]string{"run", "--hostname=foobar", ALPINE, "hostname"}) session.WaitWithDefaultTimeout()