return last_subsession;
}
-static void restore_user_session(const fs::path& username, int uid)
+static std::string restore_user_session(const fs::path& username, int uid)
{
std::string last_subsession;
try {
/* At first boot, the last subsession file won't exist.
* This is common and fine - don't rethrow. */
- return;
+ return SUBSESSION_INITIAL_SID;
}
if (!subsession_exists(uid, last_subsession)) {
LOGW("User %s (uid %d) last subsession identified as %s but did not exist - ignoring", username.c_str(), uid, last_subsession.c_str());
- return;
+ return SUBSESSION_INITIAL_SID;
}
if (last_subsession == SUBSESSION_INITIAL_SID) {
LOGI("User %s (uid %d) last subsession was empty - nothing to do", username.c_str(), uid);
- return;
+ return SUBSESSION_INITIAL_SID;
}
LOGI("User %s (uid %d) last subsession identified as \"%s\" - switching", username.c_str(), uid, last_subsession.c_str());
try {
switch_user_subsession(uid, SUBSESSION_INITIAL_SID, last_subsession);
- if (g_sessiond_context)
- g_sessiond_context->save_last_subsession(uid, last_subsession);
} catch (const std::exception &ex) {
LOGE("Could not switch to last subsession %s of user %s (uid %d)", last_subsession.c_str(), username.c_str(), uid);
}
if (lock_fd != -1)
restoration_unlock(lock_fd);
+
+ return last_subsession;
}
static void remount_image_sessions(int uid) try
remount_image_sessions(uid);
LOGI("Restoring last session for user %s (uid %d)", username.c_str(), uid);
- restore_user_session(username, uid);
+ const auto restored_session = restore_user_session(username, uid);
+
+ /* Most of the time we've restored whatever the `.last_subsession` file
+ * told us to restore, so this is a bit redundant, but it's important to
+ * do this to make sure that the entry is always up-to-date. This is not
+ * just for correctness, but also to avoid the slow D-Bus fallback for
+ * GetCurrentSubsession during the performance-sensitive early boot period. */
+ if (!restore_only && g_sessiond_context)
+ g_sessiond_context->save_last_subsession(uid, restored_session);
}
}