Change the dbus signal listening to monitor new user activation 41/121241/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 27 Mar 2017 09:32:55 +0000 (18:32 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 27 Mar 2017 09:32:55 +0000 (18:32 +0900)
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 <muwoong.lee@samsung.com>
src/server/ActiveUserMonitor.cpp
src/server/ActiveUserMonitor.h

index 7ed9f8e..526b4ba 100644 (file)
  */
 
 #include <systemd/sd-login.h>
+#include <PathUtil.h>
 #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<uint32_t>(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<ActiveUserMonitor*>(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;
 }
index f349c85..7ed0fa2 100644 (file)
@@ -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);