I wrote: > I pushed this change, to use the system's hostname binary for comparison > instead.
I should have tested it a bit more -- some systems lack the hostname binary... I have now pushed this to fall back to uname in that case. /Simon
From 6677c1202426c8f4a22c67789415822515f95e0e Mon Sep 17 00:00:00 2001 From: Simon Josefsson <[email protected]> Date: Thu, 28 Jan 2021 10:00:27 +0100 Subject: [PATCH] tests/hostname.sh: Use uname as fallback if system lack hostname command. Only require mktemp when running root test. --- ChangeLog | 5 +++++ tests/hostname.sh | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index b58669ad..64cb57b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-01-28 Simon Josefsson <[email protected]> + + * tests/hostname.sh: Use uname as fallback if system lack hostname + command. Only require mktemp when running root test. + 2021-01-28 Simon Josefsson <[email protected]> * tests/hostname.sh: Use system hostname, not system uname, for diff --git a/tests/hostname.sh b/tests/hostname.sh index 56720610..4b85cbc9 100755 --- a/tests/hostname.sh +++ b/tests/hostname.sh @@ -26,8 +26,6 @@ . ./tools.sh -$need_mktemp || exit_no_mktemp - hostname=${hostname:-../src/hostname$EXEEXT} if [ $VERBOSE ]; then @@ -41,17 +39,28 @@ posttest () { test -n "$NAMEFILE" && test -r "$NAMEFILE" && rm "$NAMEFILE" } -$hostname || errno=$? +our_hostname=`$hostname` || errno=$? test $errno -eq 0 || echo "Failed to get hostname." >&2 test $errno -eq 0 || exit $errno -test `$hostname` = `hostname` || errno=$? -test $errno -eq 0 || echo "Failed to get same hostname as system (`$hostname` vs `hostname`)." >&2 -test $errno -eq 0 || exit $errno +sys_hostname=`hostname` || errno=$? +if test $errno -ne 0; then + echo "System hostname failed (rc $errno out $sys_hostname)." >&2 + sys_hostname=`uname -n` || errno=$? + test $errno -eq 0 || echo "Failed uname (rc $errno out $sys_hostname)." >&2 + test $errno -eq 0 || exit $errno +fi + +if test "$our_hostname" != "$sys_hostname"; then + echo "Hostname mismatch $our_hostname != $sys_hostname" + exit 1 +fi if test `func_id_uid` != 0; then echo "hostname: skipping tests to set host name" else + $need_mktemp || exit_no_mktemp + # Only run this if hostname succeeded... if test $errno -eq 0; then $hostname `$hostname` || errno=$? -- 2.20.1
signature.asc
Description: PGP signature
