[PATCH] Portability: use `uname -n` instead of `hostname`

Geert Hendrickx geert at hendrickx.be
Sun Oct 11 08:04:06 UTC 2020


# HG changeset patch
# User Geert Hendrickx <geert at hendrickx.be>
# Date 1602402793 -7200
#      Sun Oct 11 09:53:13 2020 +0200
# Node ID 53f3eae1dc9a4f901f3d4da67daa0181d13dc222
# Parent  4e06441193417456bf24b213d15da12a90322f4c
Portability: use `uname -n` instead of `hostname`.

As `hostname` is not defined by POSIX and not available
by default on some modern Linux distro's (Arch, Fedora),
making some tests fail.  Using `uname -n` instead fixes
this in a portable way.

diff -r 4e0644119341 -r 53f3eae1dc9a mail_error_log.t
--- a/mail_error_log.t	Tue Oct 06 20:52:06 2020 +0100
+++ b/mail_error_log.t	Sun Oct 11 09:53:13 2020 +0200
@@ -233,7 +233,7 @@
 	ok($sec < 60, "$desc valid seconds");
 
 	ok(defined($host), "$desc has host");
-	chomp(my $hostname = lc `hostname`);
+	chomp(my $hostname = lc `uname -n`);
 	is($host , $hostname, "$desc valid host");
 
 	ok(defined($tag), "$desc has tag");
diff -r 4e0644119341 -r 53f3eae1dc9a stream_access_log.t
--- a/stream_access_log.t	Tue Oct 06 20:52:06 2020 +0100
+++ b/stream_access_log.t	Sun Oct 11 09:53:13 2020 +0200
@@ -158,7 +158,7 @@
 ok($t->read_file('complex.log'), 'if with complex value');
 ok($t->read_file('varlog_3.log'), 'variable in file');
 
-chomp(my $hostname = lc `hostname`);
+chomp(my $hostname = lc `uname -n`);
 like($t->read_file('vars.log'), qr/^\d+:[\d.]+:$hostname:\d+$/, 'log vars');
 is($t->read_file('addr.log'),
 	"$escaped:$lhost:$lport:127.0.0.1:$dport:127.0.0.1:$uport\n",
diff -r 4e0644119341 -r 53f3eae1dc9a stream_error_log.t
--- a/stream_error_log.t	Tue Oct 06 20:52:06 2020 +0100
+++ b/stream_error_log.t	Sun Oct 11 09:53:13 2020 +0200
@@ -241,7 +241,7 @@
 	ok($sec < 60, "$desc valid seconds");
 
 	ok(defined($host), "$desc has host");
-	chomp(my $hostname = lc `hostname`);
+	chomp(my $hostname = lc `uname -n`);
 	is($host , $hostname, "$desc valid host");
 
 	ok(defined($tag), "$desc has tag");
diff -r 4e0644119341 -r 53f3eae1dc9a stream_variables.t
--- a/stream_variables.t	Tue Oct 06 20:52:06 2020 +0100
+++ b/stream_variables.t	Sun Oct 11 09:53:13 2020 +0200
@@ -80,7 +80,7 @@
 
 ###############################################################################
 
-chomp(my $hostname = lc `hostname`);
+chomp(my $hostname = lc `uname -n`);
 like(stream('127.0.0.1:' . port(8080))->read(),
 	qr/^\d+:[\d.]+:$hostname:\d+:0$/, 'vars');
 
diff -r 4e0644119341 -r 53f3eae1dc9a syslog.t
--- a/syslog.t	Tue Oct 06 20:52:06 2020 +0100
+++ b/syslog.t	Sun Oct 11 09:53:13 2020 +0200
@@ -321,7 +321,7 @@
 	ok($sec < 60, "$desc valid seconds");
 
 	ok(defined($host), "$desc has host");
-	chomp(my $hostname = lc `hostname`);
+	chomp(my $hostname = lc `uname -n`);
 	is($host , $hostname, "$desc valid host");
 
 	ok(defined($tag), "$desc has tag");




More information about the nginx-devel mailing list