]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- improved error handling 1143/head
authorArvin Schnell <aschnell@suse.de>
Thu, 11 Jun 2026 12:33:46 +0000 (14:33 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 11 Jun 2026 12:33:46 +0000 (14:33 +0200)
dbus/DBusConnection.cc
dbus/DBusMessage.h
package/snapper.changes
server/snapperd.cc

index 145d1d3d0c3aa42ea791cb9b57000c3fcf3a77e6..4b290a23722800687130f167c810d59b0ea3883b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2012 Novell, Inc.
- * Copyright (c) 2023 SUSE LLC
+ * Copyright (c) [2023-2026] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -45,8 +45,10 @@ namespace DBus
 
        if (!conn)
        {
-           SN_THROW(FatalException());
+           SN_THROW(FatalException("dbus_bus_get() returned null"));
        }
+
+       dbus_connection_set_exit_on_disconnect(conn, false);
     }
 
 
@@ -72,7 +74,7 @@ namespace DBus
 
        if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
        {
-           SN_THROW(FatalException());
+           SN_THROW(FatalException("dbus_bus_request_name() failed"));
        }
     }
 
@@ -84,7 +86,7 @@ namespace DBus
 
        if (!dbus_connection_send(conn, m.get_message(), NULL))
        {
-           SN_THROW(FatalException());
+           SN_THROW(FatalException("dbus_connection_send() failed"));
        }
     }
 
@@ -120,7 +122,7 @@ namespace DBus
        if (dbus_error_is_set(&err))
        {
            dbus_error_free(&err);
-           SN_THROW(FatalException());
+           SN_THROW(FatalException("dbus_bus_add_match() failed"));
        }
     }
 
@@ -137,7 +139,7 @@ namespace DBus
        if (dbus_error_is_set(&err))
        {
            dbus_error_free(&err);
-           SN_THROW(FatalException());
+           SN_THROW(FatalException("dbus_bus_remove_match() failed"));
        }
     }
 
@@ -147,7 +149,20 @@ namespace DBus
     {
        boost::lock_guard<boost::mutex> lock(mutex);
 
-       return dbus_connection_pop_message(conn);
+       DBusMessage* msg = dbus_connection_pop_message(conn);
+
+       // Being disconnected by dbus can be simulated with something like "strace -e
+       // fault=recvmsg:error=ECONNRESET:when=10+ /usr/sbin/snapperd --logger-type
+       // stdout".
+
+       if (msg &&
+           strcmp(dbus_message_get_interface(msg), DBUS_INTERFACE_LOCAL) == 0 &&
+           strcmp(dbus_message_get_member(msg), "Disconnected") == 0)
+       {
+           throw FatalException("disconnected from dbus");
+       }
+
+       return msg;
     }
 
 
@@ -159,7 +174,7 @@ namespace DBus
        const string sender = m.get_sender();
        if (sender.empty())
        {
-           SN_THROW(FatalException());
+           SN_THROW(FatalException("get_sender() returned empty sender"));
        }
 
        DBusError err;
index d3d89912d434b427a8f188b3128f6c1f5ce7c9c2..6a8ee89ac423ccb7cf2c167fe8ea4a0599600771 100644 (file)
@@ -77,6 +77,7 @@ namespace DBus
     struct FatalException : public Exception
     {
        explicit FatalException() : Exception("dbus fatal exception") {}
+       explicit FatalException(const string& msg) : Exception("dbus fatal exception: " + msg) {}
     };
 
 
index 3a3a702baebea0e62d37c52ec659515ae731dd5b..5de6a59d1c9e249c54d7f5e7b9dec8de0f96fe5d 100644 (file)
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Thu Jun 11 10:21:28 CEST 2026 - Arvin Schnell <aschnell@suse.com>
+
+- improved error handling when disconnected by dbus (see
+  gh#openSUSE/snapper#223)
+
 -------------------------------------------------------------------
 Wed Jun 10 09:13:13 CEST 2026 - Arvin Schnell <aschnell@suse.com>
 
index d8091f1c657115e929e5446cf64e2ad64f6a3234..ecce5a2bee1324453b5f6bb506a15aa875145152 100644 (file)
@@ -312,47 +312,47 @@ main(int argc, char** argv)
 
     signal(SIGPIPE, SIG_IGN);
 
-    dbus_threads_init_default();
+    try
+    {
+       dbus_threads_init_default();
 
-    MyMainLoop mainloop(DBUS_BUS_SYSTEM);
+       MyMainLoop mainloop(DBUS_BUS_SYSTEM);
 
-    mainloop.set_idle_timeout(idle_time);
+       mainloop.set_idle_timeout(idle_time);
 
-    y2mil("Requesting DBus name");
+       y2mil("Requesting DBus name");
 
-    try
-    {
        mainloop.request_name(SERVICE, DBUS_NAME_FLAG_REPLACE_EXISTING);
-    }
-    catch (const Exception& e)
-    {
-       SN_CAUGHT(e);
 
-       y2err("Failed to request DBus name");
+       y2mil("Loading snapper configs");
 
-       return EXIT_FAILURE;
-    }
+       try
+       {
+           meta_snappers.init();
+       }
+       catch (const Exception& e)
+       {
+           SN_CAUGHT(e);
 
-    y2mil("Loading snapper configs");
+           y2err("Failed to load snapper configs");
 
-    try
-    {
-       meta_snappers.init();
+           return EXIT_FAILURE;
+       }
+
+       y2mil("Listening for method calls and signals");
+
+       mainloop.run();
+
+       y2mil("Exiting");
+
+       meta_snappers.unload();
     }
     catch (const Exception& e)
     {
        SN_CAUGHT(e);
 
-       y2err("Failed to load snapper configs");
+       return EXIT_FAILURE;
     }
 
-    y2mil("Listening for method calls and signals");
-
-    mainloop.run();
-
-    y2mil("Exiting");
-
-    meta_snappers.unload();
-
     return EXIT_SUCCESS;
 }