Skip to content

Commit

Permalink
Merge pull request #1124 from yast/fix_hostname_hosts_update
Browse files Browse the repository at this point in the history
Fix hostname hosts update
  • Loading branch information
teclator committed Nov 25, 2020
2 parents c309b33 + 9935b35 commit 699858b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Nov 25 10:02:37 UTC 2020 - Knut Anderssen <kanderssen@suse.com>

- Do not crash when trying to replace an /etc/hosts alias using the
current static hostname and it is not set (bsc#1179178)
- 4.3.30

-------------------------------------------------------------------
Mon Nov 23 08:03:17 UTC 2020 - Knut Anderssen <kanderssen@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-network.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-network
Version: 4.3.29
Version: 4.3.30
Release: 0
Summary: YaST2 - Network Configuration
License: GPL-2.0-only
Expand Down
8 changes: 4 additions & 4 deletions src/modules/Host.rb
Expand Up @@ -192,8 +192,8 @@ def GetSystemHosts

# Update hosts according to the current hostname
# (only one hostname, assigned to all IP)
# @param oldhn [String] current hostname
# @param newhn [String] current domain name
# @param oldhn [String, nil] hostname to be replaced
# @param newhn [String] new hostname value
# @param ip [String] to assign
# @return [Boolean] true if success
def Update(oldhn, newhn, ip)
Expand All @@ -203,7 +203,7 @@ def Update(oldhn, newhn, ip)
log.info("Updating /etc/hosts: #{oldhn} -> #{newhn}: #{ip}")

# Remove old hostname from hosts
@hosts.delete_hostname(oldhn) if !oldhn.empty?
@hosts.delete_hostname(oldhn) if ![nil, ""].include?(oldhn)

# Add localhost if missing
@hosts.add_entry("127.0.0.1", "localhost") if @hosts.host("127.0.0.1").empty?
Expand Down Expand Up @@ -275,7 +275,7 @@ def ResolveHostnameToStaticIPs
static_ips = StaticIPs().reject { |sip| @hosts.include_ip?(sip) }
return if static_ips.empty?

fqhostname = Hostname.MergeFQ(DNS.hostname, DNS.domain)
fqhostname = DNS.hostname

# assign system wide hostname to a static ip without particular hostname
static_ips.each { |sip| Update(fqhostname, fqhostname, sip) }
Expand Down

0 comments on commit 699858b

Please sign in to comment.