Blame SOURCES/0044-Adapt-to-the-new-behavior-of-disconnect-in-dbus-brok.patch

5e5f7c
From bf409dbab5f5910de6c2691f978bb8644532728a Mon Sep 17 00:00:00 2001
5e5f7c
From: Rob Crittenden <rcritten@redhat.com>
5e5f7c
Date: Mon, 18 May 2020 15:01:02 -0400
5e5f7c
Subject: [PATCH] Adapt to the new behavior of disconnect in dbus-broker
5e5f7c
5e5f7c
The dbus server was replaced in Fedora-29 to use dbus-broker.
5e5f7c
5e5f7c
This server does not allow reconnects on a disconnect. certmonger
5e5f7c
was crashing as a result.
5e5f7c
5e5f7c
The only way to directly pass a message between the dbus queue and
5e5f7c
the main tevent handle is via a signal. So when a disconnect is
5e5f7c
detected send a SIGTERM to getpid() in order to force a graceful
5e5f7c
shutdown.
5e5f7c
5e5f7c
https://bugzilla.redhat.com/show_bug.cgi?id=1687698
5e5f7c
---
5e5f7c
 src/tdbus.c | 61 ++++++++++-------------------------------------------
5e5f7c
 1 file changed, 11 insertions(+), 50 deletions(-)
5e5f7c
5e5f7c
diff --git a/src/tdbus.c b/src/tdbus.c
5e5f7c
index a81b534..402022e 100644
5e5f7c
--- a/src/tdbus.c
5e5f7c
+++ b/src/tdbus.c
5e5f7c
@@ -22,6 +22,7 @@
5e5f7c
 #include <stdlib.h>
5e5f7c
 #include <string.h>
5e5f7c
 #include <unistd.h>
5e5f7c
+#include <signal.h>
5e5f7c
 
5e5f7c
 #include <talloc.h>
5e5f7c
 #include <tevent.h>
5e5f7c
@@ -522,60 +523,24 @@ cm_tdbus_timeout_cleanup(void *data)
5e5f7c
 }
5e5f7c
 
5e5f7c
 static void
5e5f7c
-cm_tdbus_reconnect(struct tevent_context *ec, struct tevent_timer *timer,
5e5f7c
+cm_tdbus_disconnected(struct tevent_context *ec, struct tevent_timer *timer,
5e5f7c
 		   struct timeval current_time, void *pvt)
5e5f7c
 {
5e5f7c
-	const char *bus_desc;
5e5f7c
 	struct tdbus_connection *tdb;
5e5f7c
-	struct timeval later;
5e5f7c
-	dbus_bool_t exit_on_disconnect = TRUE;
5e5f7c
+	pid_t pid;
5e5f7c
 
5e5f7c
 	tdb = pvt;
5e5f7c
 	talloc_free(timer);
5e5f7c
 	if ((tdb->conn == NULL) ||
5e5f7c
 	    !dbus_connection_get_is_connected(tdb->conn)) {
5e5f7c
-		/* Close the current connection and open a new one. */
5e5f7c
+		/* Close the current connection and exit. */
5e5f7c
 		if (tdb->conn != NULL) {
5e5f7c
 			dbus_connection_unref(tdb->conn);
5e5f7c
 			tdb->conn = NULL;
5e5f7c
 		}
5e5f7c
-		bus_desc = NULL;
5e5f7c
-		switch (tdb->conn_type) {
5e5f7c
-		case cm_tdbus_system:
5e5f7c
-			cm_log(1, "Attempting to reconnect to system bus.\n");
5e5f7c
-			tdb->conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
5e5f7c
-			cm_set_conn_ptr(tdb->data, tdb->conn);
5e5f7c
-			/* Don't exit if we get disconnected. */
5e5f7c
-			exit_on_disconnect = FALSE;
5e5f7c
-			bus_desc = "system";
5e5f7c
-			break;
5e5f7c
-		case cm_tdbus_session:
5e5f7c
-			cm_log(1, "Attempting to reconnect to session bus.\n");
5e5f7c
-			tdb->conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
5e5f7c
-			cm_set_conn_ptr(tdb->data, tdb->conn);
5e5f7c
-			/* Exit if we get disconnected. */
5e5f7c
-			exit_on_disconnect = TRUE;
5e5f7c
-			bus_desc = "session";
5e5f7c
-			break;
5e5f7c
-		case cm_tdbus_private:
5e5f7c
-			abort();
5e5f7c
-			break;
5e5f7c
-		}
5e5f7c
-		if ((tdb->conn != NULL) &&
5e5f7c
-		    dbus_connection_get_is_connected(tdb->conn)) {
5e5f7c
-			/* We're reconnected; reset our handlers. */
5e5f7c
-			cm_log(1, "Reconnected to %s bus.\n", bus_desc);
5e5f7c
-			dbus_connection_set_exit_on_disconnect(tdb->conn,
5e5f7c
-							       exit_on_disconnect);
5e5f7c
-			cm_tdbus_setup_public_connection(tdb, tdb->conn,
5e5f7c
-							 bus_desc, NULL);
5e5f7c
-		} else {
5e5f7c
-			/* Try reconnecting again later. */
5e5f7c
-			later = tevent_timeval_current_ofs(CM_DBUS_RECONNECT_TIMEOUT, 0),
5e5f7c
-			tevent_add_timer(ec, tdb, later,
5e5f7c
-					 cm_tdbus_reconnect,
5e5f7c
-					 tdb);
5e5f7c
-		}
5e5f7c
+		pid = getpid();
5e5f7c
+		cm_log(0, "Disconnected from dbus, exiting with SIGTERM.\n");
5e5f7c
+		kill(pid, SIGTERM);
5e5f7c
 	}
5e5f7c
 }
5e5f7c
 
5e5f7c
@@ -585,12 +550,12 @@ cm_tdbus_filter(DBusConnection *conn, DBusMessage *dmessage, void *data)
5e5f7c
 	struct tdbus_connection *tdb = data;
5e5f7c
 	const char *destination, *unique_name, *path, *interface, *member;
5e5f7c
 
5e5f7c
-	/* If we're disconnected, queue a reconnect. */
5e5f7c
+	/* If we're disconnected, queue an exit. */
5e5f7c
 	if ((tdb->conn_type != cm_tdbus_private) &&
5e5f7c
 	    !dbus_connection_get_is_connected(conn)) {
5e5f7c
 		tevent_add_timer(talloc_parent(tdb), tdb,
5e5f7c
 				 tevent_timeval_current(),
5e5f7c
-				 cm_tdbus_reconnect,
5e5f7c
+				 cm_tdbus_disconnected,
5e5f7c
 				 tdb);
5e5f7c
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5e5f7c
 	}
5e5f7c
@@ -745,7 +710,6 @@ cm_tdbus_setup_public(struct tevent_context *ec, enum cm_tdbus_type bus_type,
5e5f7c
 	DBusError err;
5e5f7c
 	const char *bus_desc;
5e5f7c
 	struct tdbus_connection *tdb;
5e5f7c
-	dbus_bool_t exit_on_disconnect;
5e5f7c
 
5e5f7c
 	/* Build our own context. */
5e5f7c
 	tdb = talloc_ptrtype(ec, tdb);
5e5f7c
@@ -764,15 +728,11 @@ cm_tdbus_setup_public(struct tevent_context *ec, enum cm_tdbus_type bus_type,
5e5f7c
 	case cm_tdbus_system:
5e5f7c
 		conn = dbus_bus_get(DBUS_BUS_SYSTEM, error);
5e5f7c
 		cm_set_conn_ptr(data, conn);
5e5f7c
-		/* Don't exit if we get disconnected. */
5e5f7c
-		exit_on_disconnect = FALSE;
5e5f7c
 		bus_desc = "system";
5e5f7c
 		break;
5e5f7c
 	case cm_tdbus_session:
5e5f7c
 		conn = dbus_bus_get(DBUS_BUS_SESSION, error);
5e5f7c
 		cm_set_conn_ptr(data, conn);
5e5f7c
-		/* Exit if we get disconnected. */
5e5f7c
-		exit_on_disconnect = TRUE;
5e5f7c
 		bus_desc = "session";
5e5f7c
 		break;
5e5f7c
 	case cm_tdbus_private:
5e5f7c
@@ -784,7 +744,8 @@ cm_tdbus_setup_public(struct tevent_context *ec, enum cm_tdbus_type bus_type,
5e5f7c
 		talloc_free(tdb);
5e5f7c
 		return -1;
5e5f7c
 	}
5e5f7c
-	dbus_connection_set_exit_on_disconnect(conn, exit_on_disconnect);
5e5f7c
+	/* Exit on disconnect is handled in cm_tdbus_disconnected(). */
5e5f7c
+	dbus_connection_set_exit_on_disconnect(conn, FALSE);
5e5f7c
 	tdb->conn = conn;
5e5f7c
 	tdb->conn_type = bus_type;
5e5f7c
 	tdb->data = data;
5e5f7c
-- 
5e5f7c
2.21.1
5e5f7c