public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] debuginfod: Try without MHD_USE_DUAL_STACK if MHD_start_daemon fails
@ 2022-05-05 22:37 Mark Wielaard
  2022-05-11 22:57 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2022-05-05 22:37 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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      |  7 ++++
 debuginfod/debuginfod.cxx | 74 +++++++++++++++++++++++++++------------
 2 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 619ebd8c..e108f847 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -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-04  Frank Ch. Eigler <fche@redhat.com>
 	    Mark Wielaard  <mark@klomp.org>
 
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 4aaf41c0..c02540f1 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -3899,40 +3899,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
@@ -4053,6 +4080,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)
     {
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] debuginfod: Try without MHD_USE_DUAL_STACK if MHD_start_daemon fails
  2022-05-05 22:37 [PATCH] debuginfod: Try without MHD_USE_DUAL_STACK if MHD_start_daemon fails Mark Wielaard
@ 2022-05-11 22:57 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2022-05-11 22:57 UTC (permalink / raw)
  To: elfutils-devel

Hi,

On Fri, May 06, 2022 at 12:37:35AM +0200, Mark Wielaard wrote:
> 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

Pushed after OK on irc from Frank and some testing in Fedora.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-11 22:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05 22:37 [PATCH] debuginfod: Try without MHD_USE_DUAL_STACK if MHD_start_daemon fails Mark Wielaard
2022-05-11 22:57 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).