Add delayed login logic 63/91363/3 accepted/tizen/3.0/ivi/20161028.133950 accepted/tizen/3.0/mobile/20161028.133104 accepted/tizen/3.0/tv/20161028.133407 accepted/tizen/3.0/wearable/20161028.133715 accepted/tizen/common/20161007.173155 accepted/tizen/ivi/20161007.103929 accepted/tizen/mobile/20161007.103941 accepted/tizen/tv/20161007.103939 accepted/tizen/wearable/20161007.103936 submit/tizen/20161007.074203 submit/tizen_3.0/20161028.062323 submit/tizen_3.0/20161028.082423 submit/tizen_3.0_common/20161104.104000
authorYunmi Ha <yunmi.ha@samsung.com>
Fri, 7 Oct 2016 06:51:53 +0000 (15:51 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Fri, 7 Oct 2016 07:35:08 +0000 (16:35 +0900)
If "/run/systemd/users/%uid%" dir was existed,
it means that previous user session was not ended yet.
In this case, register delayed login and wait.
(check every 3 seconds.)

Change-Id: I9db36bb01e073c15755043d4be83ebac48a0f335
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
configure.ac
src/daemon/Makefile.am
src/daemon/tlm-seat.c [changed mode: 0644->0755]

index f677f4f68c7c7cb21a52eac824bfa986b5b7705c..97cec06a2a6579841dd41ca3bcde93aab7487826 100644 (file)
@@ -33,6 +33,10 @@ PKG_CHECK_MODULES([GMODULE], [gmodule-2.0])
 AC_SUBST(GMODULE_CFLAGS)
 AC_SUBST(GMODULE_LIBS)
 
+PKG_CHECK_MODULES(TZ_PLATFORM_CONFIG, libtzplatform-config)
+AC_SUBST(TZ_PLATFORM_CONFIG_CFLAGS)
+AC_SUBST(TZ_PLATFORM_CONFIG_LIBS)
+
 AC_CHECK_HEADERS([security/pam_appl.h],,[AC_MSG_ERROR("pam-devel is required")])
 AC_CHECK_HEADERS([security/pam_misc.h],,[AC_MSG_ERROR("pam-misc is required")])
 
index 3ebbc30410f2af7860f578913a90d3e5357ec6c7..8dfdbd564f984c923643bb88c79c943f98bf094a 100644 (file)
@@ -33,6 +33,7 @@ tlm_LDADD = \
        $(TLM_LIBS) \
        $(abs_top_builddir)/src/common/libtlm-common.la \
   $(abs_top_builddir)/src/daemon/dbus/libtlm-dbus.la \
+       $(TZ_PLATFORM_CONFIG_LIBS) \
        $(NULL)
 
 EXTRA_DIST = \
old mode 100644 (file)
new mode 100755 (executable)
index c8ab7da..8268df5
@@ -29,6 +29,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 
+#include <tzplatform_config.h>
+
 #include "config.h"
 
 #include "tlm-seat.h"
@@ -566,6 +568,62 @@ _delayed_session (gpointer user_data)
     return G_SOURCE_REMOVE;
 }
 
+gboolean
+_find_user_session(const gchar *username)
+{
+    if (!username) return FALSE;
+
+    uid_t uid = tlm_user_get_uid (username);
+    if (uid == -1) return FALSE;
+
+    const gchar *run_path = tzplatform_getenv(TZ_SYS_RUN);
+    const gchar *sub_path = "/systemd/users/";
+    size_t len = strlen(run_path) + strlen(sub_path) + 6;
+
+    gboolean result = FALSE;
+    gchar *filename = malloc(len);
+
+    if (filename) {
+        g_snprintf(filename, len, "%s%s%d", run_path, sub_path, uid);
+        DBG ("find user runtime dir: %s", filename);
+        if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
+            WARN("Session was not ended yet");
+            result = TRUE;
+        }
+
+        free(filename);
+    }
+
+    return result;
+
+}
+
+gboolean
+_register_delayed_session(TlmSeat *seat,
+                         const gchar *service,
+                         const gchar *username,
+                         const gchar *password,
+                         GHashTable *environment,
+                         guint timeout_sec)
+{
+    WARN ("relogins spinning too fast, delay...");
+    DelayClosure *delay_closure = g_slice_new0 (DelayClosure);
+    if (!delay_closure) {
+      CRITICAL("g_slice_new0 memory allication failure");
+      return FALSE;
+    }
+    delay_closure->seat = g_object_ref (seat);
+    delay_closure->service = g_strdup (service);
+    delay_closure->username = g_strdup (username);
+    delay_closure->password = g_strdup (password);
+    if (environment)
+        delay_closure->environment = g_hash_table_ref (environment);
+    g_timeout_add_seconds (timeout_sec, _delayed_session, delay_closure);
+
+    return TRUE;
+
+}
+
 gboolean
 tlm_seat_create_session (TlmSeat *seat,
                          const gchar *service,
@@ -584,6 +642,12 @@ tlm_seat_create_session (TlmSeat *seat,
         return FALSE;
     }
 
+    // Check same user's session was existed, or not.
+    // If TRUE, run _delayed_session. (try again after 3sec)
+    if (_find_user_session(username)) {
+        return _register_delayed_session(seat, service, username, password, environment, 3);
+    }
+
     // Prevent short-delay relogin.
     // If the login delay is too fast (<1s), run _delayed_session()
     if (g_get_monotonic_time () - priv->prev_time < 1000000) {
@@ -591,20 +655,7 @@ tlm_seat_create_session (TlmSeat *seat,
         priv->prev_time = g_get_monotonic_time ();
         priv->prev_count++;
         if (priv->prev_count > 3) {
-            WARN ("relogins spinning too fast, delay...");
-            DelayClosure *delay_closure = g_slice_new0 (DelayClosure);
-            if (!delay_closure) {
-              CRITICAL("g_slice_new0 memory allication failure");
-              return FALSE;
-            }
-            delay_closure->seat = g_object_ref (seat);
-            delay_closure->service = g_strdup (service);
-            delay_closure->username = g_strdup (username);
-            delay_closure->password = g_strdup (password);
-            if (environment)
-                delay_closure->environment = g_hash_table_ref (environment);
-            g_timeout_add_seconds (10, _delayed_session, delay_closure);
-            return TRUE;
+            return _register_delayed_session(seat, service, username, password, environment, 10);
         }
     } else {
         priv->prev_time = g_get_monotonic_time ();