This is an archive of the discontinued LLVM Phabricator instance.

Remove call to obsolete gethostbyname, using getaddrinfo
ClosedPublic

Authored by serge-sans-paille on Sep 5 2019, 9:59 AM.

Details

Summary

From the man page:

The gethostbyname*() and gethostbyaddr*() functions are obsolete.
Applications should use getaddrinfo(3) and getnameinfo(3) instead.

That's what I did, using the canonical name as a relevant entry, which looks like the closer match to the original call.

Diff Detail

Repository
rL LLVM

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2019, 9:59 AM
labath accepted this revision.Sep 6 2019, 1:43 AM
labath added a subscriber: labath.

Sounds like a good idea, particularly as gethostbyname is not thread safe. It seems getaddrinfo is already used in lldb, so it should be supported by all OSs that we care about.

This revision is now accepted and ready to land.Sep 6 2019, 1:43 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 6 2019, 4:06 AM

This code is trying too hard and failing. Either the result of gethostname() is canonical or it is not. If it is not, then trying to canonicalize it is – for various reasons – a lost cause. For example, a given machine might have multiple network interfaces with multiple addresses per interface, each with a different canonical name. Separably, the result of HostInfoPosix::GetHostname() and latency thereof shouldn't depend on whether networking is up or down or what network the machine happened to be attached to at any given moment (like a laptop that travels between work and home).

@davezarzycki I tend to agree with you. We can just remove 35:44 and just keep the hostname.

@davezarzycki I tend to agree with you. We can just remove 35:44 and just keep the hostname.

sounds good to me

Great. See: r371596