Skip to content

Commit

Permalink
fix(libpod): add newline character to the end of container's hostname…
Browse files Browse the repository at this point in the history
… file

debian's man (5) hostname page states "The file should contain a single newline-terminated hostname
string."
[NO NEW TESTS NEEDED]

fix containers#22729

Signed-off-by: Bo Wang <[email protected]>
  • Loading branch information
ut-wangbo committed Jun 4, 2024
1 parent 6417fa7 commit 7243c71
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/run_dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7243c71

Please sign in to comment.