Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init.d/hostname: fix /etc/hostname processing #728

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions init.d/hostname.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,28 @@ depend()

start()
{
local h source
if read -r h _ 2> /dev/null < @SYSCONFDIR@/hostname; then
local source
if [ -s @SYSCONFDIR@/hostname ]; then
source="@SYSCONFDIR@/hostname"
elif [ -n "${hostname}" ]; then
h=${hostname}
source="@SYSCONFDIR@/conf.d/${RC_SVCNAME}"
fi
if [ -z "$h" ]; then
if [ -z "$source" ]; then
einfo "Using default system hostname"
return 0
fi
ebegin "Setting hostname to $h from $source"
hostname "$h"
if [ "$source" = "@SYSCONFDIR@/conf.d/$RC_SVCNAME" ]; then
ewarn "Setting hostname in @SYSCONFDIR@/conf.d/$RC_SVCNAME is deprecated"
ewarn "and will be removed in the future."
fi
ebegin "Setting hostname from $source"
if [ "$source" = "@SYSCONFDIR@/hostname" ]; then
hostname -F "$source"
else
hostname "$hostname"
fi
if [ $? ]; then
einfo "hostname set to $(hostname)"
fi
eend $? "Failed to set the hostname"
}
Loading