git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Aditya Garg <gargaditya08@live.com>
Cc: git@vger.kernel.org,  Eric Sunshine <sunshine@sunshineco.com>,
	sandals@crustytoothpaste.net,  Zi Yao <ziyao@disroot.org>,
	 Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Subject: Re: [PATCH] send-email: try to get fqdn by running hostname --fqdn on Linux and macOS
Date: Fri, 09 May 2025 13:13:02 -0700	[thread overview]
Message-ID: <xmqqseldzgoh.fsf@gitster.g> (raw)
In-Reply-To: <PN3PR01MB9597C419019DC28E489D2AF9B88AA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM> (Aditya Garg's message of "Fri, 9 May 2025 16:49:58 +0000")

Aditya Garg <gargaditya08@live.com> writes:

> `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 ...

> 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.

  reply	other threads:[~2025-05-09 20:13 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-04 13:54 [PATCH 0/3] Improve checks for valid_fqdn in send-email and update documentation Aditya Garg
2025-05-04 13:54 ` [PATCH 1/3] send-mail: improve checks for valid_fqdn Aditya Garg
2025-05-04 14:22   ` Kristoffer Haugsbakk
2025-05-04 15:26     ` Aditya Garg
2025-05-04 16:05       ` Kristoffer Haugsbakk
2025-05-04 13:54 ` [PATCH 2/3] docs: improve send-email documentation Aditya Garg
2025-05-04 13:54 ` [PATCH 3/3] docs: add credential helper for outlook and gmail in OAuth list of helpers Aditya Garg
2025-05-05  6:16 ` [PATCH v2 0/3] Improve checks for valid_fqdn in send-email and update documentation Aditya Garg
2025-05-05  6:16   ` [PATCH v2 1/3] send-mail: improve checks for valid_fqdn Aditya Garg
2025-05-05  6:16   ` [PATCH v2 2/3] docs: improve send-email documentation Aditya Garg
2025-05-05 19:20     ` Junio C Hamano
2025-05-05 19:30       ` Aditya Garg
2025-05-05  6:16   ` [PATCH v2 3/3] docs: add credential helper for outlook and gmail in OAuth list of helpers Aditya Garg
2025-05-05 15:23 ` [PATCH v3 0/3] Improve checks for valid_fqdn in send-email and update documentation Aditya Garg
2025-05-05 15:23   ` [PATCH v3 1/3] send-mail: improve checks for valid_fqdn Aditya Garg
2025-05-05 23:49     ` Junio C Hamano
2025-05-06  5:38       ` Aditya Garg
2025-05-06  9:35         ` Aditya Garg
2025-05-06 16:50           ` Aditya Garg
2025-05-06 21:59             ` Junio C Hamano
2025-05-06 17:11           ` Junio C Hamano
2025-05-06 17:23             ` Aditya Garg
2025-05-06 17:49               ` Aditya Garg
2025-05-06 22:07               ` Junio C Hamano
2025-05-05 15:23   ` [PATCH v3 2/3] docs: improve send-email documentation Aditya Garg
2025-05-05 23:54     ` Junio C Hamano
2025-05-06  5:36       ` Aditya Garg
2025-05-05 15:23   ` [PATCH v3 3/3] docs: add credential helper for outlook and gmail in OAuth list of helpers Aditya Garg
2025-05-07 12:33 ` [PATCH v4 0/3] Improve checks for valid_fqdn in send-email and update documentation Aditya Garg
2025-05-07 12:33   ` [PATCH v4 1/3] send-mail: improve checks for valid_fqdn Aditya Garg
2025-05-07 12:48     ` Aditya Garg
2025-05-07 22:42     ` Junio C Hamano
2025-05-08 10:38       ` Aditya Garg
2025-05-07 12:33   ` [PATCH v4 2/3] docs: improve send-email documentation Aditya Garg
2025-05-07 22:21     ` Junio C Hamano
2025-05-08  3:29       ` Aditya Garg
2025-05-08 13:33         ` Junio C Hamano
2025-05-08 13:52           ` Aditya Garg
2025-05-08 16:23             ` Junio C Hamano
2025-05-08 16:38               ` Aditya Garg
2025-05-08 14:52           ` Junio C Hamano
2025-05-08 15:05             ` Aditya Garg
2025-05-08 15:08               ` Aditya Garg
2025-05-07 12:33   ` [PATCH v4 3/3] docs: add credential helper for outlook and gmail in OAuth list of helpers Aditya Garg
2025-05-08 15:18 ` [PATCH v6 0/3] Improve checks for valid_fqdn in send-email and update documentation Aditya Garg
2025-05-08 15:18   ` [PATCH v6 1/3] send-mail: improve checks for valid_fqdn Aditya Garg
2025-05-08 15:18   ` [PATCH v6 2/3] docs: improve send-email documentation Aditya Garg
2025-05-08 15:18   ` [PATCH v6 3/3] docs: add credential helper for outlook and gmail in OAuth list of helpers Aditya Garg
2025-05-08 17:14 ` [PATCH v7 0/3] Improve checks for valid_fqdn in send-email and update documentation Aditya Garg
2025-05-08 17:14   ` [PATCH v7 1/3] send-mail: improve checks for valid_fqdn Aditya Garg
2025-05-08 17:14   ` [PATCH v7 2/3] docs: improve send-email documentation Aditya Garg
2025-05-08 17:14   ` [PATCH v7 3/3] docs: add credential helper for outlook and gmail in OAuth list of helpers Aditya Garg
2025-05-08 18:08   ` [PATCH v7 0/3] Improve checks for valid_fqdn in send-email and update documentation Junio C Hamano
2025-05-09 16:49   ` [PATCH] send-email: try to get fqdn by running hostname --fqdn on Linux and macOS Aditya Garg
2025-05-09 20:13     ` Junio C Hamano [this message]
2025-05-10  7:37     ` [PATCH v2] " Aditya Garg
2025-05-12  7:46       ` Julian Swagemakers
2025-05-12  7:49         ` Aditya Garg
2025-05-12 16:42         ` Junio C Hamano
2025-05-12 16:46           ` Aditya Garg
2025-05-12 17:34             ` Junio C Hamano
2025-05-12 17:42               ` Aditya Garg
2025-05-12 19:05               ` Eric Sunshine
2025-05-12 20:15                 ` Junio C Hamano
2025-05-13 12:28                   ` Aditya Garg
2025-05-12 13:32       ` Junio C Hamano
2025-05-12  8:11     ` [PATCH v3] send-email: try to get fqdn by running hostname -f " Aditya Garg
2025-05-12 17:16     ` [PATCH v4] " Aditya Garg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqseldzgoh.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=gargaditya08@live.com \
    --cc=git@vger.kernel.org \
    --cc=kristofferhaugsbakk@fastmail.com \
    --cc=sandals@crustytoothpaste.net \
    --cc=sunshine@sunshineco.com \
    --cc=ziyao@disroot.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).