Description: Fix build problems on hurd-i386
 This patch allows Open MPI to build on Debian GNU/HURD.
 .
 Also, the memory:linux MCA component is disabled, since its use of POSIX API
 in malloc hooks called very early at startup causes troubles.
Author: Pino Toscano <pino@debian.org>
Forwarded: partially
Last-Update: 2013-08-21

Index: openmpi-1.10.2/ompi/runtime/ompi_mpi_abort.c
===================================================================
--- openmpi-1.10.2.orig/ompi/runtime/ompi_mpi_abort.c
+++ openmpi-1.10.2/ompi/runtime/ompi_mpi_abort.c
@@ -50,10 +50,11 @@ ompi_mpi_abort(struct ompi_communicator_
                bool kill_remote_of_intercomm)
 {
     int count = 0, i, ret;
-    char *msg, *host, hostname[MAXHOSTNAMELEN];
+    char *msg, *host = NULL;
     pid_t pid = 0;
     ompi_process_name_t *abort_procs;
     int32_t nabort_procs;
+    bool free_host = false;
 
     /* Protection for recursive invocation */
     if (have_been_invoked) {
@@ -66,8 +67,12 @@ ompi_mpi_abort(struct ompi_communicator_
     if (ompi_mpi_initialized) {
         host = ompi_process_info.nodename;
     } else {
-        gethostname(hostname, sizeof(hostname));
-        host = hostname;
+        size_t host_length = 128;
+        do {
+            host_length *= 2;
+            host = realloc(host, host_length);
+        } while ((gethostname(host, host_length) == -1) && (errno == ENAMETOOLONG));
+        free_host = true;
     }
     pid = getpid();
 
Index: openmpi-1.10.2/ompi/runtime/ompi_mpi_finalize.c
===================================================================
--- openmpi-1.10.2.orig/ompi/runtime/ompi_mpi_finalize.c
+++ openmpi-1.10.2/ompi/runtime/ompi_mpi_finalize.c
@@ -106,13 +106,18 @@ int ompi_mpi_finalize(void)
         /* Note that if we're already finalized, we cannot raise an
            MPI exception.  The best that we can do is write something
            to stderr. */
-        char hostname[MAXHOSTNAMELEN];
+        char *hostname=NULL;
+        size_t hostname_length = 128;
         pid_t pid = getpid();
-        gethostname(hostname, sizeof(hostname));
+        do {
+            hostname_length *= 2;
+            hostname = realloc(hostname, hostname_length);
+        } while ((gethostname(hostname, hostname_length) == -1) && (errno == ENAMETOOLONG));
 
         opal_show_help("help-mpi-runtime.txt",
                        "mpi_finalize:invoked_multiple_times",
                        true, hostname, pid);
+        free(hostname);
         return MPI_ERR_OTHER;
     }
 
Index: openmpi-1.10.2/opal/util/stacktrace.c
===================================================================
--- openmpi-1.10.2.orig/opal/util/stacktrace.c
+++ openmpi-1.10.2/opal/util/stacktrace.c
@@ -442,8 +442,12 @@ int opal_util_register_stackhandlers (vo
     }
 
     memset(&act, 0, sizeof(act));
+#ifdef SA_SIGINFO
     act.sa_sigaction = show_stackframe;
     act.sa_flags = SA_SIGINFO;
+#else
+    act.sa_handler = show_stackframe_handler;
+#endif
 #ifdef SA_ONESHOT
     act.sa_flags |= SA_ONESHOT;
 #else
Index: openmpi-1.10.2/orte/mca/odls/base/odls_base_default_fns.c
===================================================================
--- openmpi-1.10.2.orig/orte/mca/odls/base/odls_base_default_fns.c
+++ openmpi-1.10.2/orte/mca/odls/base/odls_base_default_fns.c
@@ -1109,7 +1109,12 @@ void orte_odls_base_default_launch_local
     bool oversubscribed;
     int rc=ORTE_SUCCESS;
     orte_std_cntr_t proc_rank;
+
+#if !defined(MAXPATHLEN) && defined(__GLIBC__)
+    char *basedir=NULL;
+#else
     char basedir[MAXPATHLEN];
+#endif  
     char **argvsav=NULL;
     int inm, j, idx;
     int total_num_local_procs = 0;
@@ -1126,7 +1131,11 @@ void orte_odls_base_default_launch_local
      * bouncing around as we execute various apps, but we will always return
      * to this place as our default directory
      */
+#if !defined(MAXPATHLEN) && defined(__GLIBC__)
+    basedir = get_current_dir_name();
+#else
     getcwd(basedir, sizeof(basedir));
+#endif
 
     /* find the jobdat for this job */
     if (NULL == (jobdat = orte_get_job_data_object(job))) {
@@ -2385,8 +2394,13 @@ int orte_odls_base_default_restart_proc(
     int rc;
     orte_app_context_t *app;
     orte_job_t *jobdat;
+#if !defined(MAXPATHLEN) && defined(__GLIBC__)
+    char *basedir=NULL;
+    char *dir=NULL;
+#else
     char basedir[MAXPATHLEN];
-
+#endif
+    
     OPAL_OUTPUT_VERBOSE((5, orte_odls_base_framework.framework_output,
                          "%s odls:restart_proc for proc %s",
                          ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
@@ -2396,7 +2410,11 @@ int orte_odls_base_default_restart_proc(
      * bouncing around as we execute this app, but we will always return
      * to this place as our default directory
      */
+#if !defined(MAXPATHLEN) && defined(__GLIBC__)
+    basedir = get_current_dir_name();
+#else
     getcwd(basedir, sizeof(basedir));
+#endif
 
     /* find this child's jobdat */
     if (NULL == (jobdat = orte_get_job_data_object(child->name.jobid))) {
Index: openmpi-1.10.2/opal/mca/shmem/mmap/shmem_mmap_module.c
===================================================================
--- openmpi-1.10.2.orig/opal/mca/shmem/mmap/shmem_mmap_module.c
+++ openmpi-1.10.2/opal/mca/shmem/mmap/shmem_mmap_module.c
@@ -62,6 +62,10 @@
 
 /* for tons of debug output: -mca shmem_base_verbose 70 */
 
+#ifndef MAXHOSTNAMELEN
+# define MAXHOSTNAMELEN 256
+#endif
+
 /* ////////////////////////////////////////////////////////////////////////// */
 /*local functions */
 /* local functions */
Index: openmpi-1.10.2/opal/mca/shmem/posix/shmem_posix_common_utils.h
===================================================================
--- openmpi-1.10.2.orig/opal/mca/shmem/posix/shmem_posix_common_utils.h
+++ openmpi-1.10.2/opal/mca/shmem/posix/shmem_posix_common_utils.h
@@ -45,6 +45,10 @@ BEGIN_C_DECLS
 OPAL_DECLSPEC extern int shmem_posix_shm_open(char *posix_file_name_buff,
                                               size_t size);
 
+#ifndef MAXHOSTNAMELEN
+# define MAXHOSTNAMELEN 256
+#endif
+
 END_C_DECLS
 
 #endif /* OPAL_SHMEM_POSIX_COMMON_UTILS_H */
Index: openmpi-1.10.2/opal/mca/shmem/sysv/shmem_sysv_module.c
===================================================================
--- openmpi-1.10.2.orig/opal/mca/shmem/sysv/shmem_sysv_module.c
+++ openmpi-1.10.2/opal/mca/shmem/sysv/shmem_sysv_module.c
@@ -64,6 +64,10 @@
 
 /* for tons of debug output: -mca shmem_base_verbose 70 */
 
+#ifndef MAXHOSTNAMELEN
+# define MAXHOSTNAMELEN 256
+#endif
+
 /* ////////////////////////////////////////////////////////////////////////// */
 /* local functions */
 static int
Index: openmpi-1.10.2/opal/mca/memory/linux/configure.m4
===================================================================
--- openmpi-1.10.2.orig/opal/mca/memory/linux/configure.m4
+++ openmpi-1.10.2/opal/mca/memory/linux/configure.m4
@@ -61,6 +61,10 @@ AC_DEFUN([MCA_opal_memory_linux_CONFIG],
                  [memory_linux_ptmalloc2_happy=no
                   memory_linux_ummu_happy=no])])
 
+    AS_IF([echo "$host_os" | grep '^gnu' >/dev/null 2>/dev/null],
+          [memory_linux_ptmalloc2_happy=no
+           memory_linux_ummu_happy=no])
+
     ######################################################################
     # ptmalloc2
     ######################################################################
Index: openmpi-1.10.2/opal/mca/base/mca_base_component_find.c
===================================================================
--- openmpi-1.10.2.orig/opal/mca/base/mca_base_component_find.c
+++ openmpi-1.10.2/opal/mca/base/mca_base_component_find.c
@@ -992,11 +992,16 @@ static int component_find_check (const c
         }
 
         if (!found) {
-            char h[MAXHOSTNAMELEN];
-            gethostname(h, sizeof(h));
+            char *h = NULL;
+            size_t h_length = 128;
+            do {
+                h_length *= 2;
+                h = realloc(h, h_length);
+            } while ((gethostname(h, h_length) == -1) && (errno == ENAMETOOLONG));            
             opal_show_help("help-mca-base.txt", 
                            "find-available:not-valid", true,
                            h, framework_name, requested_component_names[i]);
+            free(h);
             return OPAL_ERR_NOT_FOUND;
         }
     }
Index: openmpi-1.10.2/ompi/include/ompi_config.h
===================================================================
--- openmpi-1.10.2.orig/ompi/include/ompi_config.h
+++ openmpi-1.10.2/ompi/include/ompi_config.h
@@ -26,6 +26,10 @@
 
 #include "opal_config.h"
 
+#ifndef PATH_MAX /* Hurd */
+#define PATH_MAX 65535
+#endif
+
 #define OMPI_IDENT_STRING OPAL_IDENT_STRING
 
 /***********************************************************************
Index: openmpi-1.10.2/opal/mca/base/mca_base_var.c
===================================================================
--- openmpi-1.10.2.orig/opal/mca/base/mca_base_var.c
+++ openmpi-1.10.2/opal/mca/base/mca_base_var.c
@@ -50,6 +50,14 @@
 #include "opal/util/opal_environ.h"
 #include "opal/runtime/opal.h"
 
+#ifndef MAXPATHLEN /* Hurd */
+#define MAXPATHLEN 65535
+#endif
+
+#ifndef PATH_MAX  /* Hurd */
+#define PATH_MAX 65535
+#endif
+
 /*
  * local variables
  */
Index: openmpi-1.10.2/orte/include/orte_config.h.in
===================================================================
--- openmpi-1.10.2.orig/orte/include/orte_config.h.in
+++ openmpi-1.10.2/orte/include/orte_config.h.in
@@ -24,6 +24,10 @@
 #ifndef ORTE_CONFIG_H
 #define ORTE_CONFIG_H

+#ifndef PATH_MAX
+#define PATH_MAX 65535
+#endif
+
 #include "opal_config.h"

 #define ORTE_IDENT_STRING OPAL_IDENT_STRING
Index: openmpi-1.10.2/test/util/opal_path_nfs.c
===================================================================
--- openmpi-1.10.2.orig/test/util/opal_path_nfs.c
+++ openmpi-1.10.2/test/util/opal_path_nfs.c
@@ -31,8 +31,10 @@
 #include <dirent.h>

 #include <sys/param.h>
+#ifdef HAVE_SYS_MOUNT_H
 #include <sys/mount.h>
-#ifdef HAVE_SYS_STATFS_H
+#endif
+#if defined(__linux__) /* not present on Hurd */
 #include <sys/statfs.h>
 #endif
 #ifdef HAVE_SYS_VFS_H
