summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunmi Ha <yunmi.ha@samsung.com>2016-10-07 15:51:53 +0900
committerYunmi Ha <yunmi.ha@samsung.com>2016-10-07 16:35:08 +0900
commitb76dbe8c10c63b1cf2ddbb91b2c13165da43d08b (patch)
tree741555fc66b32d77e3c4af9535423e490ccac4c8
parent353bb32608a6113d50c843bfdc6fa90d7d0effe5 (diff)
downloadtlm-b76dbe8c10c63b1cf2ddbb91b2c13165da43d08b.tar.gz
tlm-b76dbe8c10c63b1cf2ddbb91b2c13165da43d08b.tar.bz2
tlm-b76dbe8c10c63b1cf2ddbb91b2c13165da43d08b.zip
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>
-rw-r--r--configure.ac4
-rw-r--r--src/daemon/Makefile.am1
-rwxr-xr-x[-rw-r--r--]src/daemon/tlm-seat.c79
3 files changed, 70 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac
index f677f4f..97cec06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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")])
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
index 3ebbc30..8dfdbd5 100644
--- a/src/daemon/Makefile.am
+++ b/src/daemon/Makefile.am
@@ -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 = \
diff --git a/src/daemon/tlm-seat.c b/src/daemon/tlm-seat.c
index c8ab7da..8268df5 100644..100755
--- a/src/daemon/tlm-seat.c
+++ b/src/daemon/tlm-seat.c
@@ -29,6 +29,8 @@
#include <unistd.h>
#include <fcntl.h>
+#include <tzplatform_config.h>
+
#include "config.h"
#include "tlm-seat.h"
@@ -567,6 +569,62 @@ _delayed_session (gpointer user_data)
}
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,
const gchar *username,
@@ -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 ();