mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-15 04:32:24 +00:00
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.
This commit is contained in:
parent
b2540645a3
commit
8c1ad2d3a8
1 changed files with 32 additions and 1 deletions
|
@ -207,7 +207,38 @@ init_byname(_Tt_string name)
|
||||||
|
|
||||||
memset((char*) &host_buf, 0, sizeof(_Xgethostbynameparams));
|
memset((char*) &host_buf, 0, sizeof(_Xgethostbynameparams));
|
||||||
if (name.len() == 0) {
|
if (name.len() == 0) {
|
||||||
|
/* 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();
|
_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 {
|
} else {
|
||||||
qual = name.split(':',_name);
|
qual = name.split(':',_name);
|
||||||
if (_name.len()== 0) {
|
if (_name.len()== 0) {
|
||||||
|
|
Loading…
Reference in a new issue