Skip to content

Hostname written to /etc/hostname does not include new-line at end #22729

@dagraff-cisco

Description

@dagraff-cisco

As noted in docker, the hostname written to /etc/hostname does not include a new-line at the end.

As per debian's hostname (5) man page:

The file should contain a single newline-terminated hostname string. Comments (lines starting with a "#") are ignored. The hostname should be composed of up to 64 7-bit ASCII lower-case alphanumeric characters or hyphens forming a valid DNS domain name. It is recommended that this name contains only a single label, i.e. without any dots. Invalid characters will be filtered out in an attempt to make the name valid, but obviously it is recommended to use a valid name and not rely on this filtering.

The code in question: is here

hostnamePath, err := c.writeStringToRundir("hostname", c.Hostname())

This should be amended to read

hostnamePath, err := c.writeStringToRundir("hostname", fmt.Sprintf("%s\n", c.Hostname()))

Metadata

Metadata

Assignees

Labels

Good First IssueThis issue would be a good issue for a first time contributor to undertake.kind/bugCategorizes issue or PR as related to a bug.locked - please file new issue/PRAssist humans wanting to comment on an old issue or PR with locked comments.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions