Blame SOURCES/elfutils-0.187-mhd_no_dual_stack.patch

98570d
commit ba675ed25a26fd425ffd19b02cf18babf4291b4f
98570d
Author: Mark Wielaard <mark@klomp.org>
98570d
Date:   Thu May 5 23:59:57 2022 +0200
98570d
98570d
    debuginfod: Try without MHD_USE_DUAL_STACK if MHD_start_daemon fails
98570d
    
98570d
    On a systems that have ipv6 disabled debuginfod doesn't start up
98570d
    anymore because libhttpd MHD_USE_DUAL_STACK only works if it can
98570d
    open an ipv6 socket. If MHD_start_daemon with MHD_USE_DUAL_STACK
98570d
    fails try again without that flag set.
98570d
    
98570d
    https://sourceware.org/bugzilla/show_bug.cgi?id=29122
98570d
    
98570d
    Signed-off-by: Mark Wielaard <mark@klomp.org>
98570d
98570d
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
98570d
index 4aaf41c0..c02540f1 100644
98570d
--- a/debuginfod/debuginfod.cxx
98570d
+++ b/debuginfod/debuginfod.cxx
98570d
@@ -3899,40 +3899,67 @@ main (int argc, char *argv[])
98570d
         }
98570d
     }
98570d
 
98570d
-  // Start httpd server threads.  Use a single dual-homed pool.
98570d
-  MHD_Daemon *d46 = MHD_start_daemon ((connection_pool ? 0 : MHD_USE_THREAD_PER_CONNECTION)
98570d
+  unsigned int mhd_flags = ((connection_pool
98570d
+			     ? 0 : MHD_USE_THREAD_PER_CONNECTION)
98570d
 #if MHD_VERSION >= 0x00095300
98570d
-                                     | MHD_USE_INTERNAL_POLLING_THREAD
98570d
+			    | MHD_USE_INTERNAL_POLLING_THREAD
98570d
 #else
98570d
-                                     | MHD_USE_SELECT_INTERNALLY
98570d
+			    | MHD_USE_SELECT_INTERNALLY
98570d
 #endif
98570d
+			    | MHD_USE_DUAL_STACK
98570d
 #ifdef MHD_USE_EPOLL
98570d
-                                     | MHD_USE_EPOLL
98570d
+			    | MHD_USE_EPOLL
98570d
 #endif
98570d
-                                     | MHD_USE_DUAL_STACK
98570d
 #if MHD_VERSION >= 0x00095200
98570d
-                                     | MHD_USE_ITC
98570d
+			    | MHD_USE_ITC
98570d
 #endif
98570d
-                                     | MHD_USE_DEBUG, /* report errors to stderr */
98570d
-                                     http_port,
98570d
-                                     NULL, NULL, /* default accept policy */
98570d
-                                     handler_cb, NULL, /* handler callback */
98570d
-                                     MHD_OPTION_EXTERNAL_LOGGER, error_cb, NULL,
98570d
-                                     (connection_pool ? MHD_OPTION_THREAD_POOL_SIZE : MHD_OPTION_END),
98570d
-                                     (connection_pool ? (int)connection_pool : MHD_OPTION_END),
98570d
-                                     MHD_OPTION_END);
98570d
+			    | MHD_USE_DEBUG); /* report errors to stderr */
98570d
 
98570d
+  // Start httpd server threads.  Use a single dual-homed pool.
98570d
+  MHD_Daemon *d46 = MHD_start_daemon (mhd_flags, http_port,
98570d
+				      NULL, NULL, /* default accept policy */
98570d
+				      handler_cb, NULL, /* handler callback */
98570d
+				      MHD_OPTION_EXTERNAL_LOGGER,
98570d
+				      error_cb, NULL,
98570d
+				      (connection_pool
98570d
+				       ? MHD_OPTION_THREAD_POOL_SIZE
98570d
+				       : MHD_OPTION_END),
98570d
+				      (connection_pool
98570d
+				       ? (int)connection_pool
98570d
+				       : MHD_OPTION_END),
98570d
+				      MHD_OPTION_END);
98570d
+
98570d
+  MHD_Daemon *d4 = NULL;
98570d
   if (d46 == NULL)
98570d
     {
98570d
-      sqlite3 *database = db;
98570d
-      sqlite3 *databaseq = dbq;
98570d
-      db = dbq = 0; // for signal_handler not to freak
98570d
-      sqlite3_close (databaseq);
98570d
-      sqlite3_close (database);
98570d
-      error (EXIT_FAILURE, 0, "cannot start http server at port %d", http_port);
98570d
-    }
98570d
+      // Cannot use dual_stack, use ipv4 only
98570d
+      mhd_flags &= ~(MHD_USE_DUAL_STACK);
98570d
+      d4 = MHD_start_daemon (mhd_flags, http_port,
98570d
+			     NULL, NULL, /* default accept policy */
98570d
+			     handler_cb, NULL, /* handler callback */
98570d
+			     MHD_OPTION_EXTERNAL_LOGGER,
98570d
+			     error_cb, NULL,
98570d
+			     (connection_pool
98570d
+			      ? MHD_OPTION_THREAD_POOL_SIZE
98570d
+			      : MHD_OPTION_END),
98570d
+			     (connection_pool
98570d
+			      ? (int)connection_pool
98570d
+			      : MHD_OPTION_END),
98570d
+			     MHD_OPTION_END);
98570d
+      if (d4 == NULL)
98570d
+	{
98570d
+	  sqlite3 *database = db;
98570d
+	  sqlite3 *databaseq = dbq;
98570d
+	  db = dbq = 0; // for signal_handler not to freak
98570d
+	  sqlite3_close (databaseq);
98570d
+	  sqlite3_close (database);
98570d
+	  error (EXIT_FAILURE, 0, "cannot start http server at port %d",
98570d
+		 http_port);
98570d
+	}
98570d
 
98570d
-  obatched(clog) << "started http server on IPv4 IPv6 "
98570d
+    }
98570d
+  obatched(clog) << "started http server on"
98570d
+                 << (d4 != NULL ? " IPv4 " : " IPv4 IPv6 ")
98570d
                  << "port=" << http_port << endl;
98570d
 
98570d
   // add maxigroom sql if -G given
98570d
@@ -4053,6 +4080,7 @@ main (int argc, char *argv[])
98570d
 
98570d
   /* Stop all the web service threads. */
98570d
   if (d46) MHD_stop_daemon (d46);
98570d
+  if (d4) MHD_stop_daemon (d4);
98570d
 
98570d
   if (! passive_p)
98570d
     {