Welcome! Log In Create A New Profile

Advanced

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

Geert Hendrickx
October 11, 2020 04:04AM
# HG changeset patch
# User Geert Hendrickx <geert@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");


_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

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

Geert Hendrickx 521 October 11, 2020 04:04AM

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

Geert Hendrickx 178 October 11, 2020 04:08AM

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

Sergey Kandaurov 164 October 12, 2020 01:16PM

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

Geert Hendrickx 193 October 13, 2020 03:22AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 233
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready