diff options
author | Kevin McCarthy <kevin@8t8.us> | 2020-09-23 11:08:03 -0700 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2020-09-25 13:33:25 -0700 |
commit | b0ccf259f2f9d69196a69a59d572b1481fb0fc03 (patch) | |
tree | e828091b023df58ebe930ed93ef8effedffb312f /init.c | |
parent | 8a2fc8012924988064073d46279920a03dea1b36 (diff) |
Delay $hostname setting until after the muttrc is evaluated.
Commit 5c5c34f2 made back in 1.6 changed Fqdn setting to use
gethostname() and getaddrinfo() to get the canonical domain. This is
more accurate but can cause startup delays for systems where the DNS
resolution is not set up properly.
Because this occurred before muttrc reading, there was no workaround
except to "fix DNS".
Change Fqdn ($hostname) setting to occur after the muttrc and '-e'
argument processing occur.
This is a possible breaking change if users rely on $hostname inside
their muttrc, for example 'source "muttrc.$hostname"'. The workaround
would be to put something like (depending on the system type): 'set
hostname = `hostname --fqdn`' in the muttrc above that invocation.
Also note that we still set Hostname (the internal variable) early,
because it is used in more places than Fqdn, such as tempfiles.
Diffstat (limited to 'init.c')
-rw-r--r-- | init.c | 71 |
1 files changed, 43 insertions, 28 deletions
@@ -3669,11 +3669,15 @@ void mutt_init (int skip_sys_rc, LIST *commands) start_debug (); #endif - /* And about the host... */ -#ifdef DOMAIN - domain = safe_strdup (DOMAIN); -#endif /* DOMAIN */ + /* + * Determine Hostname. + * + * This is used in tempfile creation, so set it early. We delay + * Fqdn ($hostname) setting until the muttrc is evaluated, so the + * user has the ability to manually set it (for example, if their + * DNS resolution has issues). + */ /* * The call to uname() shouldn't fail, but if it does, the system is horribly @@ -3693,30 +3697,6 @@ void mutt_init (int skip_sys_rc, LIST *commands) else Hostname = safe_strdup (utsname.nodename); - /* now get FQDN. Use configured domain first, DNS next, then uname */ - if (domain) - { - /* we have a compile-time domain name, use that for Fqdn */ - Fqdn = safe_malloc (mutt_strlen (domain) + mutt_strlen (Hostname) + 2); - sprintf (Fqdn, "%s.%s", NONULL(Hostname), domain); /* __SPRINTF_CHECKED__ */ - } - else if (!(getdnsdomainname (buffer))) - { - Fqdn = safe_malloc (mutt_buffer_len (buffer) + mutt_strlen (Hostname) + 2); - sprintf (Fqdn, "%s.%s", NONULL(Hostname), mutt_b2s (buffer)); /* __SPRINTF_CHECKED__ */ - } - else - /* - * DNS failed, use the nodename. Whether or not the nodename had a '.' in - * it, we can use the nodename as the FQDN. On hosts where DNS is not - * being used, e.g. small network that relies on hosts files, a short host - * name is all that is required for SMTP to work correctly. It could be - * wrong, but we've done the best we can, at this point the onus is on the - * user to provide the correct hostname if the nodename won't work in their - * network. - */ - Fqdn = safe_strdup(utsname.nodename); - if ((p = getenv ("MAIL"))) Spoolfile = safe_strdup (p); @@ -3884,6 +3864,41 @@ void mutt_init (int skip_sys_rc, LIST *commands) mutt_exit(1); } + + /* If not set in the muttrc or mutt_execute_commands(), set Fqdn ($hostname). + * Use configured domain first, DNS next, then uname + */ + if (!Fqdn) + { +#ifdef DOMAIN + domain = safe_strdup (DOMAIN); +#endif /* DOMAIN */ + + if (domain) + { + /* we have a compile-time domain name, use that for Fqdn */ + Fqdn = safe_malloc (mutt_strlen (domain) + mutt_strlen (Hostname) + 2); + sprintf (Fqdn, "%s.%s", NONULL(Hostname), domain); /* __SPRINTF_CHECKED__ */ + } + else if (!(getdnsdomainname (buffer))) + { + Fqdn = safe_malloc (mutt_buffer_len (buffer) + mutt_strlen (Hostname) + 2); + sprintf (Fqdn, "%s.%s", NONULL(Hostname), mutt_b2s (buffer)); /* __SPRINTF_CHECKED__ */ + } + else + /* + * DNS failed, use the nodename. Whether or not the nodename had a '.' in + * it, we can use the nodename as the FQDN. On hosts where DNS is not + * being used, e.g. small network that relies on hosts files, a short host + * name is all that is required for SMTP to work correctly. It could be + * wrong, but we've done the best we can, at this point the onus is on the + * user to provide the correct hostname if the nodename won't work in their + * network. + */ + Fqdn = safe_strdup(utsname.nodename); + } + + mutt_read_histfile (); FREE (&err.data); |