Package: elk
Severity: important
Tags: patch

Dear Maintainer,

elk currently FTBFS on hurd-i386 because the MAXHOSTNAMELEN is not defined on 
this system. The attached patch should fix this issue.

WRB,
Cyril Roelandt.

-- System Information:
Debian Release: wheezy/sid
  APT prefers unreleased
  APT policy: (500, 'unreleased'), (500, 'unstable')
Architecture: hurd-i386 (i686-AT386)

Kernel: GNU-Mach 1.3.99/Hurd-0.3
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
--- elk-3.99.8.orig/lib/unix/system.c	2011-06-18 10:24:06.000000000 +0000
+++ elk-3.99.8/lib/unix/system.c	2012-05-11 17:13:53.000000000 +0000
@@ -38,6 +38,9 @@
 #ifdef HAVE_NETDB_H
 #  include <netdb.h>
 #endif
+#if defined(HAVE_GETHOSTNAME) && !defined(MAXHOSTNAMELEN)
+#  include <errno.h>
+#endif
 
 #define L_LINK_MAX     0
 #define L_NAME_MAX     1
@@ -170,9 +173,14 @@
 
 static Object P_System_Info(Object ret) {
 #ifdef HAVE_GETHOSTNAME
+#ifdef MAXHOSTNAMELEN
     char hostname[MAXHOSTNAMELEN];
     char *p = hostname;
 #else
+    char *p = NULL;
+    size_t len = 64;
+#endif
+#else
 #ifdef HAVE_UNAME
     struct utsname uts;
     char *p = uts.nodename;
@@ -186,8 +194,29 @@
 
     Check_Result_Vector(ret, 3);
 #ifdef HAVE_GETHOSTNAME
+#ifdef MAXHOSTNAMELEN
     (void)gethostname(hostname, sizeof(hostname));
 #else
+    for (;;)
+    {
+        len *= 2;
+        char *new = realloc(p, len);
+        if (!new) {
+            if (p)
+                free(p);
+            p = strdup("unknown-hostname");
+            break;
+        }
+        p = new;
+        if (gethostname(p, len) == 0)
+            break;
+        if (errno != ENAMETOOLONG) {
+            p = strdup("unknown-hostname");
+            break;
+        }
+    }
+#endif
+#else
 #ifdef HAVE_UNAME
     (void)uname(&uts);
 #endif
@@ -200,6 +229,9 @@
     } else p = "?";
     x = Make_String(systype, strlen(systype)); VECTOR(ret)->data[1] = x;
     x = Make_String(p, strlen(p)); VECTOR(ret)->data[2] = x;
+#if defined(HAVE_GETHOSTNAME) && !defined(MAXHOSTNAMELEN)
+    free(p);
+#endif
     return Void;
 }
 

Reply via email to