Blame SOURCES/elfutils-0.187-mhd_no_dual_stack.patch

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