]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - src/session.c
explicitly provide shared dir path to sessions
[sojka/lightdm.git] / src / session.c
index ecba9f4c3da0b2a6d7d1e8e0fe13c836458c7502..f888ec7f662c4dfa6cc593cc2adc9ca48e4232ef 100644 (file)
@@ -26,6 +26,7 @@
 #include "console-kit.h"
 #include "login1.h"
 #include "guest-account.h"
+#include "shared-data-manager.h"
 
 enum {
     GOT_MESSAGES,
@@ -84,9 +85,6 @@ struct SessionPrivate
     /* File to log to */
     gchar *log_filename;
 
-    /* Seat class */
-    gchar *class;
-
     /* tty this session is running on */
     gchar *tty;
 
@@ -120,7 +118,11 @@ struct SessionPrivate
 /* Maximum length of a string to pass between daemon and session */
 #define MAX_STRING_LENGTH 65535
 
-G_DEFINE_TYPE (Session, session, G_TYPE_OBJECT);
+static void session_logger_iface_init (LoggerInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (Session, session, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (
+                             LOGGER_TYPE, session_logger_iface_init));
 
 Session *
 session_new (void)
@@ -195,14 +197,6 @@ session_set_log_file (Session *session, const gchar *filename)
     session->priv->log_filename = g_strdup (filename);
 }
 
-void
-session_set_class (Session *session, const gchar *class)
-{
-    g_return_if_fail (session != NULL);
-    g_free (session->priv->class);
-    session->priv->class = g_strdup (class);
-}
-
 void
 session_set_display_server (Session *session, DisplayServer *display_server)
 {
@@ -298,6 +292,21 @@ session_set_env (Session *session, const gchar *name, const gchar *value)
         session->priv->env = g_list_append (session->priv->env, entry);
 }
 
+const gchar *
+session_get_env (Session *session, const gchar *name)
+{
+    GList *link;
+    gchar *entry;
+
+    link = find_env_entry (session, name);
+    if (!link)
+        return NULL;
+  
+    entry = link->data;
+
+    return entry + strlen (name) + 1;
+}
+
 void
 session_unset_env (Session *session, const gchar *name)
 {
@@ -338,7 +347,7 @@ static void
 write_data (Session *session, const void *buf, size_t count)
 {
     if (write (session->priv->to_child_input, buf, count) != count)
-        g_warning ("Error writing to session: %s", strerror (errno));
+        l_warning (session, "Error writing to session: %s", strerror (errno));
 }
 
 static void
@@ -382,7 +391,7 @@ read_from_child (Session *session, void *buf, size_t count)
     ssize_t n_read;
     n_read = read (session->priv->from_child_output, buf, count);
     if (n_read < 0)
-        g_warning ("Error reading from session: %s", strerror (errno));
+        l_warning (session, "Error reading from session: %s", strerror (errno));
     return n_read;
 }
 
@@ -398,7 +407,7 @@ read_string_from_child (Session *session)
         return NULL;
     if (length > MAX_STRING_LENGTH)
     {
-        g_warning ("Invalid string length %d from child", length);
+        l_warning (session, "Invalid string length %d from child", length);
         return NULL;
     }
 
@@ -414,17 +423,20 @@ session_watch_cb (GPid pid, gint status, gpointer data)
 {
     Session *session = data;
 
-    session->priv->pid = 0;
+    session->priv->child_watch = 0;
 
     if (WIFEXITED (status))
-        g_debug ("Session %d exited with return value %d", pid, WEXITSTATUS (status));
+        l_debug (session, "Exited with return value %d", WEXITSTATUS (status));
     else if (WIFSIGNALED (status))
-        g_debug ("Session %d terminated with signal %d", pid, WTERMSIG (status));
+        l_debug (session, "Terminated with signal %d", WTERMSIG (status));
+
+    /* do this as late as possible for log messages prefix */
+    session->priv->pid = 0;
 
     /* If failed during authentication then report this as an authentication failure */
     if (session->priv->authentication_started && !session->priv->authentication_complete)
     {
-        g_debug ("Session %d failed during authentication", pid);
+        l_debug (session, "Failed during authentication");
         session->priv->authentication_complete = TRUE;
         session->priv->authentication_result = PAM_CONV_ERR;
         g_free (session->priv->authentication_result_string);
@@ -473,7 +485,7 @@ from_child_cb (GIOChannel *source, GIOCondition condition, gpointer data)
     /* Check if authentication completed */
     n_read = read_from_child (session, &auth_complete, sizeof (auth_complete));
     if (n_read < 0)
-        g_debug ("Error reading from child: %s", strerror (errno));
+        l_debug (session, "Error reading from child: %s", strerror (errno));
     if (n_read <= 0)
     {
         session->priv->from_child_watch = 0;
@@ -487,7 +499,7 @@ from_child_cb (GIOChannel *source, GIOCondition condition, gpointer data)
         g_free (session->priv->authentication_result_string);
         session->priv->authentication_result_string = read_string_from_child (session);
 
-        g_debug ("Session %d authentication complete with return value %d: %s", session->priv->pid, session->priv->authentication_result, session->priv->authentication_result_string);
+        l_debug (session, "Authentication complete with return value %d: %s", session->priv->authentication_result, session->priv->authentication_result_string);
 
         /* No longer expect any more messages */
         session->priv->from_child_watch = 0;
@@ -510,7 +522,7 @@ from_child_cb (GIOChannel *source, GIOCondition condition, gpointer data)
             m->msg = read_string_from_child (session);
         }
 
-        g_debug ("Session %d got %d message(s) from PAM", session->priv->pid, session->priv->messages_length);
+        l_debug (session, "Got %d message(s) from PAM", session->priv->messages_length);
 
         g_signal_emit (G_OBJECT (session), signals[GOT_MESSAGES], 0);
     }
@@ -522,7 +534,6 @@ gboolean
 session_start (Session *session)
 {
     g_return_val_if_fail (session != NULL, FALSE);
-    g_return_val_if_fail (session->priv->display_server != NULL, FALSE);
     return SESSION_GET_CLASS (session)->start (session);
 }
 
@@ -541,7 +552,8 @@ session_real_start (Session *session)
 
     g_return_val_if_fail (session->priv->pid == 0, FALSE);
 
-    display_server_connect_session (session->priv->display_server, session);
+    if (session->priv->display_server)
+        display_server_connect_session (session->priv->display_server, session);
 
     /* Create pipes to talk to the child */
     if (pipe (to_child_pipe) < 0 || pipe (from_child_pipe) < 0)
@@ -610,13 +622,13 @@ session_real_start (Session *session)
     write_string (session, session->priv->username);
     write_data (session, &session->priv->do_authenticate, sizeof (session->priv->do_authenticate));
     write_data (session, &session->priv->is_interactive, sizeof (session->priv->is_interactive));
-    write_string (session, session->priv->class);
+    write_string (session, NULL); /* Used to be class, now we just use the environment variable */
     write_string (session, session->priv->tty);
     write_string (session, session->priv->remote_host_name);
     write_string (session, session->priv->xdisplay);
     write_xauth (session, session->priv->x_authority);
 
-    g_debug ("Started session %d with service '%s', username '%s'", session->priv->pid, session->priv->pam_service, session->priv->username);
+    l_debug (session, "Started with service '%s', username '%s'", session->priv->pam_service, session->priv->username);
 
     return TRUE;
 }
@@ -727,7 +739,7 @@ session_real_run (Session *session)
     session->priv->command_run = TRUE;
 
     command = g_strjoinv (" ", session->priv->argv);
-    g_debug ("Session %d running command %s", session->priv->pid, command);
+    l_debug (session, "Running command %s", command);
     g_free (command);
 
     /* Create authority location */
@@ -740,11 +752,11 @@ session_real_run (Session *session)
         g_free (run_dir);
 
         if (g_mkdir_with_parents (dir, S_IRWXU) < 0)
-            g_warning ("Failed to set create system authority dir %s: %s", dir, strerror (errno));          
+            l_warning (session, "Failed to set create system authority dir %s: %s", dir, strerror (errno));
         if (getuid () == 0)
         {
             if (chown (dir, user_get_uid (session_get_user (session)), user_get_gid (session_get_user (session))) < 0)
-                g_warning ("Failed to set ownership of user authority dir: %s", strerror (errno));
+                l_warning (session, "Failed to set ownership of user authority dir: %s", strerror (errno));
         }
 
         x_authority_filename = g_build_filename (dir, "xauthority", NULL);
@@ -753,6 +765,20 @@ session_real_run (Session *session)
     else
         x_authority_filename = g_build_filename (user_get_home_directory (session_get_user (session)), ".Xauthority", NULL);
 
+    /* Make sure shared user directory for this user exists */
+    if (!session->priv->remote_host_name)
+    {
+        gchar *data_dir = shared_data_manager_ensure_user_dir (shared_data_manager_get_instance (), session->priv->username);
+        l_debug(session, "MIKE set XDG_GREETER_DATA_DIR=%s from user %s", data_dir, session->priv->username);
+        if (data_dir)
+        {
+            session_set_env (session, "XDG_GREETER_DATA_DIR", data_dir);
+            g_free (data_dir);
+        }
+    }
+
+    if (session->priv->log_filename)
+        l_debug (session, "Logging to %s", session->priv->log_filename);
     write_string (session, session->priv->log_filename);
     write_string (session, session->priv->tty);
     write_string (session, x_authority_filename);
@@ -819,7 +845,7 @@ session_real_stop (Session *session)
 
     if (session->priv->pid > 0)
     {
-        g_debug ("Session %d: Sending SIGTERM", session->priv->pid);
+        l_debug (session, "Sending SIGTERM");
         kill (session->priv->pid, SIGTERM);
         // FIXME: Handle timeout
     }
@@ -867,7 +893,6 @@ session_finalize (GObject *object)
     g_free (self->priv->messages);
     g_free (self->priv->authentication_result_string);
     g_free (self->priv->log_filename);
-    g_free (self->priv->class);
     g_free (self->priv->tty);
     g_free (self->priv->xdisplay);
     if (self->priv->x_authority)
@@ -920,3 +945,19 @@ session_class_init (SessionClass *klass)
                       NULL,
                       G_TYPE_NONE, 0);
 }
+
+static gint
+session_real_logprefix (Logger *self, gchar *buf, gulong buflen)
+{
+    Session *session = SESSION (self);
+    if (session->priv->pid != 0)
+        return g_snprintf (buf, buflen, "Session pid=%d: ", session->priv->pid);
+    else
+        return g_snprintf (buf, buflen, "Session: ");
+}
+
+static void
+session_logger_iface_init (LoggerInterface *iface)
+{
+    iface->logprefix = &session_real_logprefix;
+}