Fix setting hostname for Debian and Ubuntu using hostnamectl

This commit is contained in:
iliajie
2022-10-05 22:32:29 +03:00
parent feb87e2b53
commit 7c301848cb
2 changed files with 16 additions and 3 deletions

View File

@@ -571,6 +571,13 @@ foreach my $f ("/etc/hostname", "/etc/HOSTNAME", "/etc/mailname") {
&close_tempfile(HOST);
}
}
# Use the hostnamectl command as well
if (&has_command("hostnamectl")) {
&system_logged("hostnamectl set-hostname ".quotemeta($hostname).
" >/dev/null 2>&1");
}
undef(@main::get_system_hostname); # clear cache
}

View File

@@ -387,15 +387,21 @@ return &get_system_hostname();
sub save_hostname
{
my ($hostname) = @_;
my (%conf, $f);
&system_logged("hostname ".quotemeta($hostname)." >/dev/null 2>&1");
foreach $f ("/etc/hostname", "/etc/HOSTNAME", "/etc/mailname") {
foreach my $f ("/etc/hostname", "/etc/HOSTNAME", "/etc/mailname") {
if (-r $f) {
&open_lock_tempfile(HOST, ">$f");
&print_tempfile(HOST, $_[0],"\n");
&print_tempfile(HOST, $hostname,"\n");
&close_tempfile(HOST);
}
}
# Use the hostnamectl command as well
if (&has_command("hostnamectl")) {
&system_logged("hostnamectl set-hostname ".quotemeta($hostname).
" >/dev/null 2>&1");
}
undef(@main::get_system_hostname); # clear cache
}