Proper exception handling for add/remove failures 65/321965/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 1 Apr 2025 15:34:47 +0000 (17:34 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 2 Apr 2025 17:54:42 +0000 (19:54 +0200)
Change-Id: I138578dda11a3f21a17c5114e3eb1c1de4fafd16

src/service/src/fs_helpers.cpp
src/service/src/main_context.hpp

index d0abc368062e3f6b9c56db7e7960cab484d717a5..7caf80eb4c9b9cd12849994dfca48b64037f4f91 100644 (file)
@@ -238,6 +238,7 @@ void add_user_subsession(const int session_uid, const std::string_view subsessio
                } catch (const std::exception& ex) {
                        LOGE("Logic exception while copying skel into temporary dir [session_uid=%d subsession_id=%s]: %s", session_uid, subsession_id.data(), ex.what());
                        backend.AddSubsessionCleanupFailure(tmp_subsession_path, subsession_path);
+                       throw;
                }
        }
        catch (std::system_error const &ex) {
index 406a14891ca2dcee8e02b830e56106fbc1e89758..7ed8252c650c44ec406d4fda09bf481583a06893 100644 (file)
@@ -246,7 +246,13 @@ struct sessiond_context {
                        return;
                }
 
-               do_add_user(session_uid, subsession_id, DirBackendAddRegularDir {});
+               try {
+                       do_add_user(session_uid, subsession_id, DirBackendAddRegularDir {});
+               } catch (const std::exception &ex) {
+                       g_dbus_method_invocation_return_dbus_error(invocation,
+                               get_dbus_error_mapping(SUBSESSION_ERROR_IO_ERROR), "Failed to add subsession");
+                       return;
+               }
 
                g_dbus_method_invocation_return_value(invocation, nullptr);
        }
@@ -269,7 +275,13 @@ struct sessiond_context {
                        return;
                }
 
-               do_add_user(session_uid, subsession_id, DirBackendAddFixedSize {size_kB});
+               try {
+                       do_add_user(session_uid, subsession_id, DirBackendAddFixedSize {size_kB});
+               } catch (const std::exception &ex) {
+                       g_dbus_method_invocation_return_dbus_error(invocation,
+                               get_dbus_error_mapping(SUBSESSION_ERROR_IO_ERROR), "Failed to add subsession");
+                       return;
+               }
 
                g_dbus_method_invocation_return_value(invocation, nullptr);
        }
@@ -293,7 +305,13 @@ struct sessiond_context {
                        return;
                }
 
-               do_remove_user(session_uid, subsession_id);
+               try {
+                       do_remove_user(session_uid, subsession_id);
+               } catch (const std::exception &ex) {
+                       g_dbus_method_invocation_return_dbus_error(invocation,
+                               get_dbus_error_mapping(SUBSESSION_ERROR_IO_ERROR), "Failed to remove subsession");
+                       return;
+               }
 
                g_dbus_method_invocation_return_value(invocation, nullptr);
        }