]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
debuginfod: Try without MHD_USE_DUAL_STACK if MHD_start_daemon fails
authorMark Wielaard <mark@klomp.org>
Thu, 5 May 2022 21:59:57 +0000 (23:59 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 11 May 2022 22:54:04 +0000 (00:54 +0200)
On a systems that have ipv6 disabled debuginfod doesn't start up
anymore because libhttpd MHD_USE_DUAL_STACK only works if it can
open an ipv6 socket. If MHD_start_daemon with MHD_USE_DUAL_STACK
fails try again without that flag set.

https://sourceware.org/bugzilla/show_bug.cgi?id=29122

Signed-off-by: Mark Wielaard <mark@klomp.org>
debuginfod/ChangeLog
debuginfod/debuginfod.cxx

index 026908c8500098691b3b20a040dc19ee2052f53d..29480c9c9e33066d7c46988fc0a376a2f039c16d 100644 (file)
@@ -1,3 +1,10 @@
+2022-05-05  Mark Wielaard  <mark@klomp.org>
+
+       * debuginfod.cxx (main): Define mhd_flags. Use mhd_flags for
+       MHD_start_daemon. Try again with MHD_USE_DUAL_STACK removed if
+       that fails. Update clog to say either IPV4 or IPV4 and IPV6.
+       stop either ithe d46 or d4 daemonr.
+
 2022-05-09  Noah Sanci  <nsanci@redhat.com>
 
        * debuginfod.cxx (main): Set nonzero defaults for fdcache.
index fde4e194b52676e700751860556f9c7dbc7cfb0e..8692a424ef1de4b8391a3296068ad585b69f7402 100644 (file)
@@ -3906,40 +3906,67 @@ main (int argc, char *argv[])
         }
     }
 
-  // Start httpd server threads.  Use a single dual-homed pool.
-  MHD_Daemon *d46 = MHD_start_daemon ((connection_pool ? 0 : MHD_USE_THREAD_PER_CONNECTION)
+  unsigned int mhd_flags = ((connection_pool
+                            ? 0 : MHD_USE_THREAD_PER_CONNECTION)
 #if MHD_VERSION >= 0x00095300
-                                     | MHD_USE_INTERNAL_POLLING_THREAD
+                           | MHD_USE_INTERNAL_POLLING_THREAD
 #else
-                                     | MHD_USE_SELECT_INTERNALLY
+                           | MHD_USE_SELECT_INTERNALLY
 #endif
+                           | MHD_USE_DUAL_STACK
 #ifdef MHD_USE_EPOLL
-                                     | MHD_USE_EPOLL
+                           | MHD_USE_EPOLL
 #endif
-                                     | MHD_USE_DUAL_STACK
 #if MHD_VERSION >= 0x00095200
-                                     | MHD_USE_ITC
+                           | MHD_USE_ITC
 #endif
-                                     | MHD_USE_DEBUG, /* report errors to stderr */
-                                     http_port,
-                                     NULL, NULL, /* default accept policy */
-                                     handler_cb, NULL, /* handler callback */
-                                     MHD_OPTION_EXTERNAL_LOGGER, error_cb, NULL,
-                                     (connection_pool ? MHD_OPTION_THREAD_POOL_SIZE : MHD_OPTION_END),
-                                     (connection_pool ? (int)connection_pool : MHD_OPTION_END),
-                                     MHD_OPTION_END);
+                           | MHD_USE_DEBUG); /* report errors to stderr */
 
+  // Start httpd server threads.  Use a single dual-homed pool.
+  MHD_Daemon *d46 = MHD_start_daemon (mhd_flags, http_port,
+                                     NULL, NULL, /* default accept policy */
+                                     handler_cb, NULL, /* handler callback */
+                                     MHD_OPTION_EXTERNAL_LOGGER,
+                                     error_cb, NULL,
+                                     (connection_pool
+                                      ? MHD_OPTION_THREAD_POOL_SIZE
+                                      : MHD_OPTION_END),
+                                     (connection_pool
+                                      ? (int)connection_pool
+                                      : MHD_OPTION_END),
+                                     MHD_OPTION_END);
+
+  MHD_Daemon *d4 = NULL;
   if (d46 == NULL)
     {
-      sqlite3 *database = db;
-      sqlite3 *databaseq = dbq;
-      db = dbq = 0; // for signal_handler not to freak
-      sqlite3_close (databaseq);
-      sqlite3_close (database);
-      error (EXIT_FAILURE, 0, "cannot start http server at port %d", http_port);
-    }
+      // Cannot use dual_stack, use ipv4 only
+      mhd_flags &= ~(MHD_USE_DUAL_STACK);
+      d4 = MHD_start_daemon (mhd_flags, http_port,
+                            NULL, NULL, /* default accept policy */
+                            handler_cb, NULL, /* handler callback */
+                            MHD_OPTION_EXTERNAL_LOGGER,
+                            error_cb, NULL,
+                            (connection_pool
+                             ? MHD_OPTION_THREAD_POOL_SIZE
+                             : MHD_OPTION_END),
+                            (connection_pool
+                             ? (int)connection_pool
+                             : MHD_OPTION_END),
+                            MHD_OPTION_END);
+      if (d4 == NULL)
+       {
+         sqlite3 *database = db;
+         sqlite3 *databaseq = dbq;
+         db = dbq = 0; // for signal_handler not to freak
+         sqlite3_close (databaseq);
+         sqlite3_close (database);
+         error (EXIT_FAILURE, 0, "cannot start http server at port %d",
+                http_port);
+       }
 
-  obatched(clog) << "started http server on IPv4 IPv6 "
+    }
+  obatched(clog) << "started http server on"
+                 << (d4 != NULL ? " IPv4 " : " IPv4 IPv6 ")
                  << "port=" << http_port << endl;
 
   // add maxigroom sql if -G given
@@ -4060,6 +4087,7 @@ main (int argc, char *argv[])
 
   /* Stop all the web service threads. */
   if (d46) MHD_stop_daemon (d46);
+  if (d4) MHD_stop_daemon (d4);
 
   if (! passive_p)
     {