commit-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Inetutils branch, master, updated. inetutils-1_9_2-20-gb4e807


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_2-20-gb4e8076
Date: Fri, 02 May 2014 15:08:27 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  b4e8076826838934bf518b8d0dbc86c37b8af6e8 (commit)
      from  547bb31ef5a971fcd310b741a20cbe1b0959770a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=b4e8076826838934bf518b8d0dbc86c37b8af6e8


commit b4e8076826838934bf518b8d0dbc86c37b8af6e8
Author: Mats Erik Andersson <address@hidden>
Date:   Tue Apr 29 22:56:40 2014 +0200

    hostname: Degenerate cases.
    
    Better replies when name resolution fails.

diff --git a/ChangeLog b/ChangeLog
index d0b8bd4..03ec4f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2014-04-29  Mats Erik Andersson  <address@hidden>
+
+       hostname: Degenerate cases.
+       Better replies when name resolution fails.
+
+       * configure.ac: Remove check for gethostname in libresolv.
+       If hstrerror is missing, check for it in libresolv.
+       (LIBRESOLV): New variable published using AC_SUBST.
+
+       * src/Makefile.am (hostname_LDADD): New variable.
+
+       * src/hostname.c (get_name): Call puts() only if NAME
+       carries some content.  Will, most importantly, reply
+       with an empty string, not an empty line, when no aliases
+       are found.
+       (get_aliases): Return an empty string when the host's
+       name cannot be resolved.
+       (get_fqdn): Fall back to the system reported hostname
+       when name resolution fails.
+       [HAVE_HSTRERROR] (get_ip_addresses): Exit with an error
+       when name resolution fails.
+
+       * tests/hostname.sh: Check availability of mktemp.
+       (posttest): New function, used as trap.
+       <root execution>: New test case with switch '-F'.
+
 2014-04-26  Mats Erik Andersson  <address@hidden>
 
        libinetutils: Skeletal preparations for Heimdal.
diff --git a/configure.ac b/configure.ac
index 3915b8e..54fab00 100644
--- a/configure.ac
+++ b/configure.ac
@@ -154,7 +154,6 @@ gl_INIT
 
 ### Checks for libraries.
 AC_SEARCH_LIBS([inet_ntoa], [nsl])
-AC_SEARCH_LIBS([gethostname], [resolv])
 AC_SEARCH_LIBS([getpeername], [socket])
 
 # See if a termcap library is available (under one of several names)
@@ -795,7 +794,14 @@ if test "$ac_cv_func_strerror" = no; then
 fi
 
 # See if the system has hstrerror, and replace it if not
+save_LIBS=$LIBS
+
 AC_CHECK_FUNC(hstrerror)
+if test "$ac_cv_func_hstrerror" != yes; then
+  # Is hstrerror contained in a separate library?
+  AC_CHECK_LIB([resolv], [hstrerror], LIBRESOLV=-lresolv)
+  LIBS="$LIBRESOLV $LIBS"
+fi
 if test "$ac_cv_func_hstrerror" = yes; then
   AC_CHECK_DECL(hstrerror, , , [#include <netdb.h>])
 else
@@ -814,6 +820,8 @@ if test "$ac_cv_func_hstrerror" = yes \
   # `Host lookup error N'.
   AC_DEFINE([HAVE_HSTRERROR], 1, [Define to one if you have hstrerror.])
 fi
+LIBS=$save_LIBS
+AC_SUBST(LIBRESOLV)
 
 # OpenSolaris does not provide an external reference.
 AC_CHECK_DECLS(telcmds, , ,
diff --git a/src/Makefile.am b/src/Makefile.am
index 0cc6e4f..26c8252 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,6 +44,7 @@ EXTRA_PROGRAMS =
 
 bin_PROGRAMS += $(hostname_BUILD)
 hostname_SOURCES = hostname.c
+hostname_LDADD = $(LDADD) $(LIBRESOLV)
 EXTRA_PROGRAMS += hostname
 
 bin_PROGRAMS += $(dnsdomainname_BUILD)
diff --git a/src/hostname.c b/src/hostname.c
index 95a2698..13886fd 100644
--- a/src/hostname.c
+++ b/src/hostname.c
@@ -212,7 +212,8 @@ get_name (const hostname_arguments *const args)
         error (EXIT_FAILURE, errno, "strdup");
     }
 
-  puts (name);
+  if (name && *name)
+    puts (name);
 
   free (name);
   free (sname);
@@ -257,7 +258,7 @@ get_aliases (const char *const host_name)
 
   ht = gethostbyname (host_name);
   if (ht == NULL)
-    strcpy (aliases, "(none)");
+    strcpy (aliases, "");      /* Be honest about missing aliases.  */
   else
     {
       for (i = 0; ht->h_aliases[i] != NULL; i++)
@@ -288,7 +289,7 @@ get_fqdn (const char *const host_name)
 
   ht = gethostbyname (host_name);
   if (ht == NULL)
-    fqdn = strdup ("(none)");
+    fqdn = strdup (host_name); /* Fall back to system name.  */
   else
     fqdn = strdup (ht->h_name);
 
@@ -313,7 +314,11 @@ get_ip_addresses (const char *const host_name)
 
   ht = gethostbyname (host_name);
   if (ht == NULL)
+#if HAVE_HSTRERROR
+    error (EXIT_FAILURE, 0, "gethostbyname: %s", hstrerror (h_errno));
+#else
     strcpy (addresses, "(none)");
+#endif
   else
     {
       for (i = 0; ht->h_addr_list[i] != NULL; i++)
diff --git a/tests/hostname.sh b/tests/hostname.sh
index 7ba0d29..a12b7fb 100755
--- a/tests/hostname.sh
+++ b/tests/hostname.sh
@@ -21,10 +21,12 @@
 #
 #  * Shell: SVR3 Bourne shell, or newer.
 #
-#  * id(1), uname(1).
+#  * id(1), mktemp(1), uname(1).
 
 . ./tools.sh
 
+$need_mktemp || exit_no_mktemp
+
 hostname=${hostname:-../src/hostname$EXEEXT}
 
 if [ $VERBOSE ]; then
@@ -34,22 +36,43 @@ fi
 
 errno=0
 
+posttest () {
+    test -n "$NAMEFILE" && test -r "$NAMEFILE" && rm "$NAMEFILE"
+}
+
 $hostname || errno=$?
 test $errno -eq 0 || echo "Failed to get hostname." >&2
 test $errno -eq 0 || exit $errno
 
 test `$hostname` = `uname -n` || errno=$?
-test $errno -eq 0 || echo "Failed to get hostname." >&2
+test $errno -eq 0 || echo "Failed to get same hostname as uname does." >&2
 test $errno -eq 0 || exit $errno
 
-if [ `func_id_uid` != 0 ]; then
+if test `func_id_uid` != 0; then
     echo "hostname: skipping tests to set host name"
 else
     # Only run this if hostname succeeded...
-    if [ $errno -eq 0 ]; then
+    if test $errno -eq 0; then
        $hostname `$hostname` || errno=$?
        test $errno -eq 0 || echo "Failed to set hostname." >&2
        test $errno -eq 0 || exit $errno
+
+       NAMEFILE=`$MKTEMP tmp.XXXXXXXXXX` || errno=$?
+       test $errno -eq 0 || echo >&2 'Cannot create test file.'
+       test $errno -eq 0 || exit $errno
+
+       trap posttest 0 1 2 3 15
+
+       SAVEDNAME=`hostname` || errno=$?
+       echo $SAVEDNAME > $NAMEFILE
+
+       if test $errno -eq 0 && test -s $NAMEFILE; then
+           $hostname -F $NAMEFILE || errno=$?
+           test $errno -eq 0 || echo >&2 'Failed to set hostname.'
+
+           # Attempt to rescue name using the first method.
+           test $errno -eq 0 || $hostname "$SAVEDNAME" || errno=$?
+       fi
     fi
 fi
 

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog         |   26 ++++++++++++++++++++++++++
 configure.ac      |   10 +++++++++-
 src/Makefile.am   |    1 +
 src/hostname.c    |   11 ++++++++---
 tests/hostname.sh |   31 +++++++++++++++++++++++++++----
 5 files changed, 71 insertions(+), 8 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]