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