*/
#include <systemd/sd-login.h>
+#include <PathUtil.h>
#include "ActiveUserMonitor.h"
#define ROOT_UID 0
+#define USER_CHK_DELAY 3000
using namespace ctx;
__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()
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);
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);
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;
}