#include "console-kit.h"
#include "login1.h"
#include "guest-account.h"
+#include "shared-data-manager.h"
enum {
GOT_MESSAGES,
/* File to log to */
gchar *log_filename;
- /* Seat class */
- gchar *class;
-
/* tty this session is running on */
gchar *tty;
/* 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)
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)
{
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)
{
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
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;
}
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;
}
{
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);
/* 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;
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;
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);
}
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);
}
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)
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;
}
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 */
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);
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);
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
}
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)
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;
+}