From b0036b91d947bc7d11bcbbcb14cd43564bc04a8a Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 27 Mar 2017 18:32:55 +0900 Subject: [PATCH] Change the dbus signal listening to monitor new user activation Unlike the previous "UserNew" signal, "UserSessionStartupFinished" is called when the user session is actually ready, i.e., the necessary directories are mounted. Change-Id: I39894c7602698e65c0ab2a75a940885311556710 Signed-off-by: Mu-Woong Lee --- src/server/ActiveUserMonitor.cpp | 44 +++++++++++++++++++++++--------- src/server/ActiveUserMonitor.h | 2 +- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/server/ActiveUserMonitor.cpp b/src/server/ActiveUserMonitor.cpp index 7ed9f8e..526b4ba 100644 --- a/src/server/ActiveUserMonitor.cpp +++ b/src/server/ActiveUserMonitor.cpp @@ -15,9 +15,11 @@ */ #include +#include #include "ActiveUserMonitor.h" #define ROOT_UID 0 +#define USER_CHK_DELAY 3000 using namespace ctx; @@ -42,14 +44,14 @@ void ActiveUserMonitor::start(GDBusConnection* conn, uid_cb_t activateUser, uid_ __deactivateUser = deactivateUser; __userNewSignalId = g_dbus_connection_signal_subscribe(__connection, - NULL, "org.freedesktop.login1.Manager", "UserNew", NULL, - NULL, G_DBUS_SIGNAL_FLAGS_NONE, __onUserNew, this, NULL); + NULL, "org.freedesktop.systemd1.Manager", "UserSessionStartupFinished", NULL, + NULL, G_DBUS_SIGNAL_FLAGS_NONE, __onUserSessionStarted, this, NULL); __userRemovedSignalId = g_dbus_connection_signal_subscribe(__connection, NULL, "org.freedesktop.login1.Manager", "UserRemoved", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __onUserRemoved, this, NULL); - g_timeout_add(200, __checkCurrentUser, this); + g_timeout_add(USER_CHK_DELAY, __checkCurrentUser, this); } void ActiveUserMonitor::stop() @@ -58,12 +60,16 @@ void ActiveUserMonitor::stop() g_dbus_connection_signal_unsubscribe(__connection, __userRemovedSignalId); } -void ActiveUserMonitor::__onUserNew(GDBusConnection* conn, const gchar* sender, +void ActiveUserMonitor::__onUserSessionStarted(GDBusConnection* conn, const gchar* sender, const gchar* path, const gchar* iface, const gchar* name, GVariant* param, gpointer userData) { uint32_t uid = 0; - g_variant_get_child(param, 0, "u", &uid); + guint64 uid64 = 0; + + g_variant_get_child(param, 0, "t", &uid64); + uid = static_cast(uid64); + IF_FAIL_VOID_TAG(uid > 0, _W, "UID == 0"); _D("UID: %u", uid); @@ -107,6 +113,18 @@ void ActiveUserMonitor::__onUserRemoved(GDBusConnection* conn, const gchar* send monitor->__activeUid = ROOT_UID; } +static bool __isUserDirectoryReady(uid_t uid) +{ + std::string dbDir = PathUtil::getUserPath(uid, TZ_USER_DB, EMPTY_STR); + DIR* dir = opendir(dbDir.c_str()); + if (!dir) { + _W("User not ready"); + return false; + } + closedir(dir); + return true; +} + gboolean ActiveUserMonitor::__checkCurrentUser(gpointer userData) { ActiveUserMonitor* monitor = static_cast(userData); @@ -114,16 +132,18 @@ gboolean ActiveUserMonitor::__checkCurrentUser(gpointer userData) uid_t* users = NULL; int numUsers = sd_get_active_uids(&users); + IF_FAIL_RETURN(numUsers > 0, G_SOURCE_CONTINUE); - if (numUsers > 0) - monitor->__activeUid = users[0]; - + uid_t activeUid = users[0]; g_free(users); - if (monitor->__activeUid != ROOT_UID) { - _D("UID: %u", monitor->__activeUid); - monitor->__activateUser(monitor->__activeUid); - } + if (activeUid == ROOT_UID || !__isUserDirectoryReady(activeUid)) + return G_SOURCE_CONTINUE; + + monitor->__activeUid = activeUid; + + _D("UID: %u", monitor->__activeUid); + monitor->__activateUser(monitor->__activeUid); return G_SOURCE_REMOVE; } diff --git a/src/server/ActiveUserMonitor.h b/src/server/ActiveUserMonitor.h index f349c85..7ed0fa2 100644 --- a/src/server/ActiveUserMonitor.h +++ b/src/server/ActiveUserMonitor.h @@ -33,7 +33,7 @@ namespace ctx { void stop(); private: - static void __onUserNew(GDBusConnection* conn, const gchar* sender, + static void __onUserSessionStarted(GDBusConnection* conn, const gchar* sender, const gchar* path, const gchar* iface, const gchar* name, GVariant* param, gpointer userData); -- 2.34.1