CTRL-C caused the weston process to exit
[platform/core/system/tlm.git] / src / sessiond / tlm-session.c
index 137f33e..976ddc7 100644 (file)
@@ -42,6 +42,7 @@
 #include <ctype.h>
 #include <sys/socket.h>
 #include <netdb.h>
+#include <linux/kd.h>
 
 #include <glib.h>
 #include <glib/gstdio.h>
@@ -59,6 +60,10 @@ G_DEFINE_TYPE (TlmSession, tlm_session, G_TYPE_OBJECT);
 #define TLM_SESSION_PRIV(obj) \
     G_TYPE_INSTANCE_GET_PRIVATE ((obj), TLM_TYPE_SESSION, TlmSessionPrivate)
 
+#ifndef KDSKBMUTE
+#define KDSKBMUTE   0x4B51
+#endif
+
 enum {
     PROP_0,
     PROP_CONFIG,
@@ -391,6 +396,13 @@ _set_terminal (TlmSessionPrivate *priv)
     if (ioctl (tty_fd, TIOCSPGRP, &tty_pgid)) {
         WARN ("ioctl(TIOCSPGRP) failed: %s", strerror(errno));
     }
+
+    /* TODO: unset the mode on session cleanup */
+    if (ioctl(tty_fd, KDSKBMUTE, 1) &&
+        ioctl(tty_fd, KDSKBMODE, K_OFF)) {
+        WARN ("ioctl(KDSKBMODE) failed: %s", strerror(errno));
+    }
+
     /*if (tcsetpgrp (tty_fd, getpgrp ()))
         WARN ("tcsetpgrp() failed: %s", strerror(errno));*/
 
@@ -437,10 +449,9 @@ _set_environment (TlmSessionPrivate *priv)
     shell = tlm_user_get_shell (priv->username);
     if (shell) _setenv_to_session ("SHELL", shell, priv);
 
-    // seat is not set for fake seats
     if (!tlm_config_has_key (priv->config,
-                            TLM_CONFIG_GENERAL,
-                            TLM_CONFIG_GENERAL_NSEATS))
+                             TLM_CONFIG_GENERAL,
+                             TLM_CONFIG_GENERAL_NSEATS))
         _setenv_to_session ("XDG_SEAT", priv->seat_id, priv);
 
     const gchar *xdg_data_dirs =
@@ -569,7 +580,7 @@ _exec_user_session (
     open_max = sysconf (_SC_OPEN_MAX);
     for (fd = 3; fd < open_max; fd++) {
         if (fcntl (fd, F_SETFD, FD_CLOEXEC) < -1) {
-            WARN("Failed to close desriptor '%d', error: %s",
+            WARN ("Failed to close desriptor '%d', error: %s",
                 fd, strerror(errno));
         }
     }
@@ -732,8 +743,15 @@ tlm_session_start (TlmSession *session,
     g_object_set (G_OBJECT (session), "seat", seat_id, "service", service,
             "username", username, "environment", environment, NULL);
 
+    priv->vtnr = tlm_config_get_uint (priv->config,
+                                      priv->seat_id,
+                                      TLM_CONFIG_SEAT_VTNR,
+                                      0);
+    gchar *tty_name = priv->vtnr > 0 ?
+        g_strdup_printf ("tty%u", priv->vtnr) : NULL;
     priv->auth_session = tlm_auth_session_new (priv->service, priv->username,
-            password);
+            password, tty_name);
+    g_free (tty_name);
 
     if (!priv->auth_session) {
         error = TLM_GET_ERROR_FOR_ID (TLM_ERROR_SESSION_CREATION_FAILURE,
@@ -743,10 +761,6 @@ tlm_session_start (TlmSession *session,
         return FALSE;
     }
 
-    priv->vtnr = tlm_config_get_uint (priv->config,
-                                      priv->seat_id,
-                                      TLM_CONFIG_SEAT_VTNR,
-                                      0);
     session_type = tlm_config_get_string (priv->config,
                                           priv->seat_id,
                                           TLM_CONFIG_GENERAL_SESSION_TYPE);
@@ -755,8 +769,8 @@ tlm_session_start (TlmSession *session,
                                               TLM_CONFIG_GENERAL,
                                               TLM_CONFIG_GENERAL_SESSION_TYPE);
     if (!tlm_config_has_key (priv->config,
-                            TLM_CONFIG_GENERAL,
-                            TLM_CONFIG_GENERAL_NSEATS))
+                             TLM_CONFIG_GENERAL,
+                             TLM_CONFIG_GENERAL_NSEATS))
         tlm_auth_session_putenv (priv->auth_session,
                                  "XDG_SEAT",
                                  priv->seat_id);