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: 2016-07-14

Index: openmpi-2.0.1/ompi/runtime/ompi_mpi_abort.c
===================================================================
--- openmpi-2.0.1.orig/ompi/runtime/ompi_mpi_abort.c
+++ openmpi-2.0.1/ompi/runtime/ompi_mpi_abort.c
@@ -119,7 +119,7 @@ int
 ompi_mpi_abort(struct ompi_communicator_t* comm,
                int errcode)
 {
-    char *msg, *host, hostname[OPAL_MAXHOSTNAMELEN];
+    char *msg, *host, hostname = NULL;
     pid_t pid = 0;
 
     /* Protection for recursive invocation */
@@ -133,8 +133,11 @@ ompi_mpi_abort(struct ompi_communicator_
     if (ompi_rte_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));
     }
     pid = getpid();
 
Index: openmpi-2.0.1/ompi/runtime/ompi_mpi_finalize.c
===================================================================
--- openmpi-2.0.1.orig/ompi/runtime/ompi_mpi_finalize.c
+++ openmpi-2.0.1/ompi/runtime/ompi_mpi_finalize.c
@@ -114,10 +114,14 @@ int ompi_mpi_finalize(void)
         /* Note that if we're not initialized or already finalized, we
            cannot raise an MPI exception.  The best that we can do is
            write something to stderr. */
-        char hostname[OPAL_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));        
+            
         if (ompi_mpi_initialized) {
             opal_show_help("help-mpi-runtime.txt",
                            "mpi_finalize: not initialized",
@@ -127,6 +131,7 @@ int ompi_mpi_finalize(void)
                            "mpi_finalize:invoked_multiple_times",
                            true, hostname, pid);
         }
+        free(hostname);
         opal_mutex_unlock(&ompi_mpi_bootstrap_mutex);
         return MPI_ERR_OTHER;
     }
Index: openmpi-2.0.1/opal/util/stacktrace.c
===================================================================
--- openmpi-2.0.1.orig/opal/util/stacktrace.c
+++ openmpi-2.0.1/opal/util/stacktrace.c
@@ -436,8 +436,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-2.0.1/orte/mca/odls/base/odls_base_default_fns.c
===================================================================
--- openmpi-2.0.1.orig/orte/mca/odls/base/odls_base_default_fns.c
+++ openmpi-2.0.1/orte/mca/odls/base/odls_base_default_fns.c
@@ -627,7 +627,12 @@ void orte_odls_base_default_launch_local
     orte_proc_t *child=NULL;
     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;
@@ -641,7 +646,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))) {
@@ -1635,8 +1644,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),
@@ -1646,7 +1660,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-2.0.1/opal/mca/shmem/mmap/shmem_mmap_module.c
===================================================================
--- openmpi-2.0.1.orig/opal/mca/shmem/mmap/shmem_mmap_module.c
+++ openmpi-2.0.1/opal/mca/shmem/mmap/shmem_mmap_module.c
@@ -60,6 +60,10 @@
 
 /* for tons of debug output: -mca shmem_base_verbose 70 */
 
+#ifndef MAXHOSTNAMELEN
+# define MAXHOSTNAMELEN 256
+#endif
+
 /* ////////////////////////////////////////////////////////////////////////// */
 /*local functions */
 /* local functions */
Index: openmpi-2.0.1/opal/mca/shmem/posix/shmem_posix_common_utils.h
===================================================================
--- openmpi-2.0.1.orig/opal/mca/shmem/posix/shmem_posix_common_utils.h
+++ openmpi-2.0.1/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-2.0.1/opal/mca/shmem/sysv/shmem_sysv_module.c
===================================================================
--- openmpi-2.0.1.orig/opal/mca/shmem/sysv/shmem_sysv_module.c
+++ openmpi-2.0.1/opal/mca/shmem/sysv/shmem_sysv_module.c
@@ -62,6 +62,10 @@
 
 /* for tons of debug output: -mca shmem_base_verbose 70 */
 
+#ifndef MAXHOSTNAMELEN
+# define MAXHOSTNAMELEN 256
+#endif
+
 /* ////////////////////////////////////////////////////////////////////////// */
 /* local functions */
 static int
Index: openmpi-2.0.1/opal/mca/memory/linux/configure.m4
===================================================================
--- openmpi-2.0.1.orig/opal/mca/memory/linux/configure.m4
+++ openmpi-2.0.1/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])
+
     ######################################################################
     # if memory hook available
     ######################################################################
Index: openmpi-2.0.1/ompi/include/ompi_config.h
===================================================================
--- openmpi-2.0.1.orig/ompi/include/ompi_config.h
+++ openmpi-2.0.1/ompi/include/ompi_config.h
@@ -28,6 +28,10 @@
 
 #include "opal_config.h"
 
+#ifndef PATH_MAX /* Hurd */
+#define PATH_MAX 65535
+#endif
+
 #define OMPI_IDENT_STRING OPAL_IDENT_STRING
 
 /***********************************************************************
Index: openmpi-2.0.1/opal/mca/base/mca_base_var.c
===================================================================
--- openmpi-2.0.1.orig/opal/mca/base/mca_base_var.c
+++ openmpi-2.0.1/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-2.0.1/test/util/opal_path_nfs.c
===================================================================
--- openmpi-2.0.1.orig/test/util/opal_path_nfs.c
+++ openmpi-2.0.1/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
