3

In Emacs 24, the function system-name returns an FQDN. In Emacs 25, system-name returns just the host name, and there doesn't seem to be a good way to get the FQDN.

How do I get an FQDN portably across Emacs versions?

  • Could you clarify why you need an FQDN? – Stefan May 23 '15 at 14:09
  • BTW, does Wanderlust really need an FQDN? Why? – Stefan May 23 '15 at 15:01
  • 1
    I know SMTP likes it, but the "if possible" part means that in practice it's not actually needed. And in my experience, on those hosts where an FQDN makes sense, you can often configure /usr/bin/sendmail so MUAs don't all need to be configured individually. – Stefan May 23 '15 at 15:36
  • 3
    Stefan, you're absolutely right about everything, and please feel welcome to discuss Wanderlust's defaults on the WL mailing list. But this question is not about changing Wanderlust's defaults — it's about keeping Wanderlust's current functionality under Emacs 25. – jch May 23 '15 at 17:26
5

Emacs used to try and set system-name to an FQDN. This has caused a fair bit of bug-reports and frustration over the years, since it caused Emacs to sometimes hang for somewhere between 30s and 2min at startup in case of a "misconfigured" DNS setup. Things have gotten worse nowadays since in many common situations (e.g. machine behind NAT) it's almost impossible to find such an FQDN, and it can change at any time during the Emacs session.

So in Emacs-25 we decided to stop trying. This is also indirectly the answer to your question: no, we don't know how to get an FQDN portably, so we don't try to find an FQDN any more.

For those situations where you do need an FQDN, you will generally have some extra knowledge about your machine's config which will make it possible for you to find the FQDN and/or to write a little chunk of code which can find this FQDN.

One easy way (in some situations) might be to change the machine's localname to be this FQDN (so Emacs's system-name will again be an FQDN).

1

My fix was to use this:

(car (split-string (shell-command-to-string "hostname -f")))

It's a bit of a hack, because I just use the hostname -f shell command. This is because I don't think hostname should return the FQDN. there's all sorts of things wrong with this, and anyways, I don't always control the /etc/hosts file or the hostname myself

My use case is simply using the smtpmail handler to send mail with Emacs. The remote SMTP server expects a FQDN to be given in the HELO parameter. Before Emacs 25, this would work fine, but now it fails. Using localname, localhost or any static variation wouldn't work either, and some servers explicitly will deny localhost.localdomain as well.

Therefore I now have yet another kludge in my .emacs, like this:

;; most SMTP servers expect a FQDN on HELO and (system-name) returns
;; only the short hostname since Emacs25, fallback to hostname -f
(when (>= emacs-major-version 25)
  (setq smtpmail-local-domain (car (split-string (shell-command-to-string "hostname -f")))))

Kind of unfortunate, if you ask me. I understand this was done to workaround broken configurations, but at least there should be a system-name-fqdn macro or something to do the right thing for people that are properly configured... If you're going to break the API, at least provide a fallback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.