git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] send-email: try to get fqdn by running hostname --fqdn on Linux and macOS

From
Junio C Hamano <gitster@pobox.com>
Date
May 9, 2025, 20:13 UTC
Message-ID
<xmqqseldzgoh.fsf@gitster.g>
In-Reply-To
<PN3PR01MB9597C419019DC28E489D2AF9B88AA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>
Aditya Garg <gargaditya08@live.com> writes:
Show 22 quoted lines
> `hostname` is a popular command available on both Linux and macOS. As
> per the man-page[1], `hostname --fqdn` command returns the fully
> qualified domain name (FQDN) of the system. The current Net::Domain
> perl module being used in the script for the same has been quite
> unrealiable in many cases. Thankfully, we now have a better check for
> valid_fqdn, which does reject the invalid FQDNs given by this module
> properly, but at the same time, it will result in a fallback to
> 'localhost.localdomain' being used. `hostname --fqdn` has been quite
> reliable (probably even more reliable than the Net::Domain module) and
> before falling back to 'localhost.localdomain', we should try to use it.
> Interestingly, the `hostname` command is actually used by perl modules
> like Net::Domain[2] and Sys::Hostname[3] to get the hostname. So, lets
> give `hostname --fqdn` a chance as well!
>
> [1]: https://man7.org/linux/man-pages/man1/hostname.1.html
> [2]: https://github.com/Perl/perl5/blob/blead/cpan/libnet/lib/Net/Domain.pm#L88
> [3]: https://github.com/Perl/perl5/blob/blead/ext/Sys-Hostname/Hostname.pm#L93
>
> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
>  git-send-email.perl | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)

As maildomain() is called at most once in a process, thanks to send_message() conditionally calling it only to set $smtp_domain that is not yet set, I do not personally mind adding an extra fork/exec here, but ...

Show 15 quoted lines
> diff --git a/git-send-email.perl b/git-send-email.perl
> index 55b7e00d29..735d8abc12 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -1393,8 +1393,20 @@ sub maildomain_mta {
>  	return $maildomain;
>  }
>  
> +sub maildomain_hostname_command {
> +	my $maildomain;
> +
> +	if ($^O eq 'linux' || $^O eq 'darwin') {
> +		my $domain = `(hostname --fqdn) 2>/dev/null`;
> +		chomp($domain);
> +		$maildomain = $domain if valid_fqdn($domain);

... we do not know everybody's implementation, especially including the non stardard ones, of 'hostname --fqdn'. Some may stay silent, or say something only to its standard error, when it cannot produce a usable output, which is the above code expects, but some others emit whatever it wants to to its standard output while signalling an error with its exit value, when it sees some error (like "I do not know about that 'fqdn' option").

In short, I do not have too much trouble against the idea to add "ask hostname(1)" to the source of maildomain information, but I'd prefer for the implementation to be a bit more careful to detect errors, more careful than "if we get anything on its standard output, it cannot be an error and we'd use that". I understand that the call to "if valid_fqdn()" tightens the condition a bit better by looking at $domain, but we shouldn't be even chomping $domain or feeding it to valid_fqdn() when we know the `hostname` failed in the first place.

> +	}
> +	return $maildomain;
> +}
Thanks.
Previous: Aditya GargNext: Aditya Garg
Message 55 of 68 in “Improve checks for valid_fqdn in send-email and update documentation”
  1. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 4, 2025
  2. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 4, 2025
  3. Kristoffer HaugsbakkMay 4, 2025
  4. Aditya GargMay 4, 2025
  5. Kristoffer HaugsbakkMay 4, 2025
  6. 2/3 docs: improve send-email documentationAditya Garg, May 4, 2025
  7. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 4, 2025
  8. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 5, 2025
  9. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 5, 2025
  10. 2/3 docs: improve send-email documentationAditya Garg, May 5, 2025
  11. Junio C HamanoMay 5, 2025
  12. Aditya GargMay 5, 2025
  13. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 5, 2025
  14. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 5, 2025
  15. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 5, 2025
  16. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 5, 2025
  17. Junio C HamanoMay 5, 2025
  18. Aditya GargMay 6, 2025
  19. Aditya GargMay 6, 2025
  20. Aditya GargMay 6, 2025
  21. Junio C HamanoMay 6, 2025
  22. Junio C HamanoMay 6, 2025
  23. Aditya GargMay 6, 2025
  24. Aditya GargMay 6, 2025
  25. Junio C HamanoMay 6, 2025
  26. 2/3 docs: improve send-email documentationAditya Garg, May 5, 2025
  27. Junio C HamanoMay 5, 2025
  28. Aditya GargMay 6, 2025
  29. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 7, 2025
  30. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 7, 2025
  31. Aditya GargMay 7, 2025
  32. Junio C HamanoMay 7, 2025
  33. Aditya GargMay 8, 2025
  34. 2/3 docs: improve send-email documentationAditya Garg, May 7, 2025
  35. Junio C HamanoMay 7, 2025
  36. Aditya GargMay 8, 2025
  37. Junio C HamanoMay 8, 2025
  38. Aditya GargMay 8, 2025
  39. Junio C HamanoMay 8, 2025
  40. Aditya GargMay 8, 2025
  41. Junio C HamanoMay 8, 2025
  42. Aditya GargMay 8, 2025
  43. Aditya GargMay 8, 2025
  44. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 7, 2025
  45. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 8, 2025
  46. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 8, 2025
  47. 2/3 docs: improve send-email documentationAditya Garg, May 8, 2025
  48. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 8, 2025
  49. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 8, 2025
  50. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 8, 2025
  51. 2/3 docs: improve send-email documentationAditya Garg, May 8, 2025
  52. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 8, 2025
  53. Junio C HamanoMay 8, 2025
  54. send-email: try to get fqdn by running hostname --fqdn on Linux and macOSAditya Garg, May 9, 2025
  55. Junio C HamanoMay 9, 2025
  56. send-email: try to get fqdn by running hostname --fqdn on Linux and macOSAditya Garg, May 10, 2025
  57. Julian SwagemakersMay 12, 2025
  58. Aditya GargMay 12, 2025
  59. Junio C HamanoMay 12, 2025
  60. Aditya GargMay 12, 2025
  61. Junio C HamanoMay 12, 2025
  62. Aditya GargMay 12, 2025
  63. Eric SunshineMay 12, 2025
  64. Junio C HamanoMay 12, 2025
  65. Aditya GargMay 13, 2025
  66. Junio C HamanoMay 12, 2025
  67. send-email: try to get fqdn by running hostname -f on Linux and macOSAditya Garg, May 12, 2025
  68. send-email: try to get fqdn by running hostname -f on Linux and macOSAditya Garg, May 12, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.