Skip to content

Commit

Permalink
Handle systems where hostname is unavailable (#20765)
Browse files Browse the repository at this point in the history
* Handle systems where `hostname` is unavailable

Fixes #20758

* Comment on hostname regex

* Fix grammar
  • Loading branch information
omus authored and tkelman committed Feb 24, 2017
1 parent 078835c commit 00b7b60
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1020,18 +1020,25 @@ mktempdir() do dir
end

# Find a hostname that maps to the loopback address
hostname = replace(readchomp(`hostname`), r"\..*$", "")
loopback = ip"127.0.0.1"
hostnames = ["localhost"]

for host in (hostname, "localhost")
# In minimal environments a hostname might not be available (issue #20758)
try
# In some environments, namely Macs, the hostname "macbook.local" is bound
# to the external address while "macbook" is bound to the loopback address.
unshift!(hostnames, replace(gethostname(), r"\..*$", ""))
end

loopback = ip"127.0.0.1"
for hostname in hostnames
try
addr = getaddrinfo(host)
addr = getaddrinfo(hostname)
catch
continue
end

if addr == loopback
common_name = host
common_name = hostname
break
end
end
Expand Down

0 comments on commit 00b7b60

Please sign in to comment.