service: session restore: Handle non-existing uids properly 19/323719/3
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 6 May 2025 17:02:44 +0000 (19:02 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 7 May 2025 19:20:52 +0000 (21:20 +0200)
/opt/usr/home/ can contain build artifacts like 'abuild' with no
passwd entry, causing sessiond to terminate at user->uid translation.

Fixes:

  I/SESSIOND(18740): main_restore.cpp: restore_all_user_sessions(135) > Restoring last session for user abuild
  E/SESSIOND(18740): main.cpp: main(46) > Exception Couldn't get Unix uid for `abuild` user - does not exist caught in top scope! Bailing out...

Change-Id: Ida7609da7a122b7f10c8ca05bf0d6b5a25e22018

src/service/src/main_restore.cpp

index 1761c294023b29e7e4e403143698fad31b28b426..fbd8b3f09c3be7a1cd05908a910015c2082fefe6 100644 (file)
@@ -82,10 +82,11 @@ static void restore_user_session(const fs::path& user_home_dir)
         * so it would be good to refactor it so as to be
         * able to take either arg and avoid the syscall. */
        const auto username = user_home_dir.filename();
-       int uid = OS::get_uid_from_name(username.native());
+       int uid = -1;
 
        std::string last_subsession;
        try {
+               uid = OS::get_uid_from_name(username.native());
                std::ifstream(get_last_subsession_path_by_user_id(uid), std::ios::in) >> last_subsession;
        } catch (const std::exception &ex) {
                LOGE("Could not retrieve last subsession of user %s (uid %d)", username.c_str(), uid);