From: Jon Trulson Date: Wed, 20 Jun 2018 22:59:34 +0000 (-0600) Subject: libtt: if local hostname lookup fails, default to localhost X-Git-Tag: 2.3.0~8 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8c1ad2d3a8ec095e86da02dbea3adec228c48820;p=oweals%2Fcde.git libtt: if local hostname lookup fails, default to localhost A recurring problem, mainly on the BSD's, and also on some Linux installations, is a failure for ttsession to start and any clients trying to attach to it failing due to having a hostname that is not associated with an IP address. This is due to code which looks up the hostname, and if it does not have a valid host record, then TT just fails. This has required those users to add an alias for their host name in their /etc/hosts file. With this commit, this should no longer be necessary. Now, if _XGethostbyname() fails when looking up the local name, a default of "localhost" is used, which should always exist. This was run tested on Linux and FreeBSD 11.1. It was compile tested on OpenBSD 6.2. --- diff --git a/cde/lib/tt/lib/util/tt_host.C b/cde/lib/tt/lib/util/tt_host.C index f73fd4ba..d608b57e 100644 --- a/cde/lib/tt/lib/util/tt_host.C +++ b/cde/lib/tt/lib/util/tt_host.C @@ -207,7 +207,38 @@ init_byname(_Tt_string name) memset((char*) &host_buf, 0, sizeof(_Xgethostbynameparams)); if (name.len() == 0) { - _name = _tt_gethostname(); + /* JET - many machines in this modern era have a hostname + * that does not have an IP address associated with it. + * So, we do a quick check to see if XGethostbyname() is + * happy with the returned name. If it isn't, then we set + * the name to "localhost", which should always exist on + * any machine with IP networking. If your machine does + * not have IP networking, you shouldn't be running TT :) + * + * This should fix those cases, particularly on BSD + * machines, whereby TT fails to start. They should no + * longer need to add their hostname manually to + * /etc/hosts (as an alias to localhost) in order to start + * CDE + */ + _name = _tt_gethostname(); + if(!_XGethostbyname((char *)_name, host_buf)) + { + /* this gets a little verbose - you see one for every + * client, so if-0 out. Leave for future debugging + * though... + */ +#if 0 + _tt_syslog(0, LOG_WARNING, "_XGethostbyname(%s) failed," + " defaulting to localhost", + (const char *)_name); +#endif + + /* fall back to localhost */ + _name = "localhost"; + } + /* clear host_buf again, for the final run below */ + memset((char*) &host_buf, 0, sizeof(_Xgethostbynameparams)); } else { qual = name.split(':',_name); if (_name.len()== 0) {