Remount image-based subsessions at boot 68/324668/2
authorMichal Bloch <m.bloch@samsung.com>
Thu, 22 May 2025 11:24:04 +0000 (13:24 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 22 May 2025 14:03:29 +0000 (16:03 +0200)
Change-Id: Iffe5bbe3affb2945ef6c24173eee2daddf0c5110

src/service/src/main_restore.cpp

index b791e003faeaaa3205c17b2beaacd6b91c0729c6..7b132513ecec5cc3f2f70b20c06ccf000dd9651b 100644 (file)
@@ -118,6 +118,26 @@ static void restore_user_session(const fs::path& username, int uid)
                restoration_unlock(lock_fd);
 }
 
+static void remount_image_sessions(int uid) try
+{
+       const auto subsessions = get_user_list(uid);
+
+       std::string_view prev = SUBSESSION_INITIAL_SID;
+       for (const auto &subsession : subsessions) {
+
+               /* A bit of a hack. This doesn't actually perform
+                * a switch (no D-Bus events etc) but happens to do
+                * all the needed work (detect backend, remount). */
+               switch_user_subsession(uid, prev, subsession);
+
+               prev = subsession;
+       }
+       switch_user_subsession(uid, prev, SUBSESSION_INITIAL_SID);
+} catch (const std::exception& ex) {
+       LOGE("Could not remount image-based subsessions uid %d: %s", uid, ex.what());
+       throw;
+}
+
 void restore_all_user_sessions()
 {
        /* In theory this should live among OS or FS helpers, but
@@ -142,6 +162,12 @@ void restore_all_user_sessions()
                        continue;
                }
 
+               /* We rely on all image-based subsessions being mounted to
+                * make sure that external updates (e.g. when packages are
+                * installed) are correctly reflected in existing subsessions. */
+               LOGI("Remounting image-based subsessions for user %s (uid %d)", username.c_str(), uid);
+               remount_image_sessions(uid);
+
                LOGI("Restoring last session for user %s (uid %d)", username.c_str(), uid);
                restore_user_session(username, uid);
        }