Skip to content

Commit 9c9f884

Browse files
AdityaGarg8gitster
authored andcommitted
send-email: try to get fqdn by running hostname -f on Linux and macOS
`hostname` is a popular command available on both Linux and macOS. As per the man-page[1], `hostname -f` 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 -f` 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 -f` 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6f84262 commit 9c9f884

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

git-send-email.perl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,8 +1386,22 @@ sub maildomain_mta {
13861386
return $maildomain;
13871387
}
13881388

1389+
sub maildomain_hostname_command {
1390+
my $maildomain;
1391+
1392+
if ($^O eq 'linux' || $^O eq 'darwin') {
1393+
my $domain = `(hostname -f) 2>/dev/null`;
1394+
if (!$?) {
1395+
chomp($domain);
1396+
$maildomain = $domain if valid_fqdn($domain);
1397+
}
1398+
}
1399+
return $maildomain;
1400+
}
1401+
13891402
sub maildomain {
1390-
return maildomain_net() || maildomain_mta() || 'localhost.localdomain';
1403+
return maildomain_net() || maildomain_mta() ||
1404+
maildomain_hostname_command || 'localhost.localdomain';
13911405
}
13921406

13931407
sub smtp_host_string {

0 commit comments

Comments
 (0)