diff options
author | a7x <ubuntu-a7x@scientician.org> | 2013-08-21 23:06:57 +0000 |
---|---|---|
committer | Tarmac <> | 2013-08-21 23:06:57 +0000 |
commit | 3429ab2438d1d51dd48fe470b316f2fcdef0baba (patch) | |
tree | a52ce31ceddd17d515207fedee3dece52f766bc0 | |
parent | 31385deb1f9e4d0ec23968cd8bcc647bac7c194a (diff) | |
parent | 222096ff9a9899aba3574b9448b2d370d4284dac (diff) | |
download | lightdm-3429ab2438d1d51dd48fe470b316f2fcdef0baba.tar.gz |
Extend logging to make it easier to troubleshoot multiseat setups.
Approved by PS Jenkins bot, Robert Ancell, Thomi Richards.
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/display-server.c | 23 | ||||
-rw-r--r-- | src/display-server.h | 1 | ||||
-rw-r--r-- | src/greeter.c | 54 | ||||
-rw-r--r-- | src/lightdm.c | 8 | ||||
-rw-r--r-- | src/logger.c | 81 | ||||
-rw-r--r-- | src/logger.h | 60 | ||||
-rw-r--r-- | src/seat-unity.c | 62 | ||||
-rw-r--r-- | src/seat-xlocal.c | 20 | ||||
-rw-r--r-- | src/seat-xremote.c | 14 | ||||
-rw-r--r-- | src/seat.c | 143 | ||||
-rw-r--r-- | src/seat.h | 1 | ||||
-rw-r--r-- | src/session.c | 55 | ||||
-rw-r--r-- | src/session.h | 1 | ||||
-rw-r--r-- | src/x-server-local.c | 22 | ||||
-rw-r--r-- | src/x-server-xvnc.c | 22 | ||||
-rw-r--r-- | src/x-server.c | 7 |
17 files changed, 409 insertions, 167 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 1be9a5d7..457d7063 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,8 @@ lightdm_SOURCES = \ guest-account.c \ guest-account.h \ lightdm.c \ + logger.c \ + logger.h \ login1.c \ login1.h \ mir-server.c \ diff --git a/src/display-server.c b/src/display-server.c index 5042b389..cd9673b6 100644 --- a/src/display-server.c +++ b/src/display-server.c @@ -32,7 +32,11 @@ struct DisplayServerPrivate gboolean stopped; }; -G_DEFINE_TYPE (DisplayServer, display_server, G_TYPE_OBJECT); +static void display_server_logger_iface_init (LoggerInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (DisplayServer, display_server, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE ( + LOGGER_TYPE, display_server_logger_iface_init)); void display_server_set_name (DisplayServer *server, const gchar *name) @@ -176,3 +180,20 @@ display_server_class_init (DisplayServerClass *klass) NULL, G_TYPE_NONE, 0); } + +static gint +display_server_real_logprefix (Logger *self, gchar *buf, gulong buflen) +{ + DisplayServer *server = DISPLAY_SERVER (self); + const gchar *name = display_server_get_name (server); + if (name) + return g_snprintf (buf, buflen, "DisplayServer %s: ", name); + else + return g_snprintf (buf, buflen, "DisplayServer: "); +} + +static void +display_server_logger_iface_init (LoggerInterface *iface) +{ + iface->logprefix = &display_server_real_logprefix; +} diff --git a/src/display-server.h b/src/display-server.h index 50347edb..971151b3 100644 --- a/src/display-server.h +++ b/src/display-server.h @@ -16,6 +16,7 @@ typedef struct DisplayServer DisplayServer; +#include "logger.h" #include "session.h" G_BEGIN_DECLS diff --git a/src/greeter.c b/src/greeter.c index 52bf5987..d6d04bd5 100644 --- a/src/greeter.c +++ b/src/greeter.c @@ -164,7 +164,7 @@ write_message (Greeter *greeter, guint8 *message, gsize message_length) g_io_channel_write_chars (greeter->priv->to_greeter_channel, (gchar *) message, message_length, NULL, &error); if (error) - g_warning ("Error writing to greeter: %s", error->message); + l_warning (greeter, "Error writing to greeter: %s", error->message); g_clear_error (&error); g_io_channel_flush (greeter->priv->to_greeter_channel, NULL); } @@ -225,7 +225,7 @@ handle_connect (Greeter *greeter, const gchar *version) GHashTableIter iter; gpointer key, value; - g_debug ("Greeter connected version=%s", version); + l_debug (greeter, "Greeter connected version=%s", version); length = string_length (VERSION); g_hash_table_iter_init (&iter, greeter->priv->hints); @@ -260,7 +260,7 @@ pam_messages_cb (Session *session, Greeter *greeter) messages_length = session_get_messages_length (session); /* Respond to d-bus query with messages */ - g_debug ("Prompt greeter with %d message(s)", messages_length); + l_debug (greeter, "Prompt greeter with %d message(s)", messages_length); size = int_length () + string_length (session_get_username (session)) + int_length (); for (i = 0; i < messages_length; i++) size += int_length () + string_length (messages[i].msg); @@ -308,16 +308,16 @@ authentication_complete_cb (Session *session, Greeter *greeter) { int result; - g_debug ("Authenticate result for user %s: %s", session_get_username (session), session_get_authentication_result_string (session)); + l_debug (greeter, "Authenticate result for user %s: %s", session_get_username (session), session_get_authentication_result_string (session)); result = session_get_authentication_result (session); if (session_get_is_authenticated (session)) { if (session_get_user (session)) - g_debug ("User %s authorized", session_get_username (session)); + l_debug (greeter, "User %s authorized", session_get_username (session)); else { - g_debug ("User %s authorized, but no account of that name exists", session_get_username (session)); + l_debug (greeter, "User %s authorized, but no account of that name exists", session_get_username (session)); result = PAM_USER_UNKNOWN; } } @@ -349,11 +349,11 @@ handle_login (Greeter *greeter, guint32 sequence_number, const gchar *username) if (username[0] == '\0') { - g_debug ("Greeter start authentication"); + l_debug (greeter, "Greeter start authentication"); username = NULL; } else - g_debug ("Greeter start authentication for %s", username); + l_debug (greeter, "Greeter start authentication for %s", username); reset_session (greeter); @@ -392,13 +392,13 @@ handle_login (Greeter *greeter, guint32 sequence_number, const gchar *username) static void handle_login_as_guest (Greeter *greeter, guint32 sequence_number) { - g_debug ("Greeter start authentication for guest account"); + l_debug (greeter, "Greeter start authentication for guest account"); reset_session (greeter); if (!greeter->priv->allow_guest) { - g_debug ("Guest account is disabled"); + l_debug (greeter, "Guest account is disabled"); send_end_authentication (greeter, sequence_number, "", PAM_USER_UNKNOWN); return; } @@ -449,11 +449,11 @@ handle_login_remote (Greeter *greeter, const gchar *session_name, const gchar *u if (username[0] == '\0') { - g_debug ("Greeter start authentication for remote session %s", session_name); + l_debug (greeter, "Greeter start authentication for remote session %s", session_name); username = NULL; } else - g_debug ("Greeter start authentication for remote session %s as user %s", session_name, username); + l_debug (greeter, "Greeter start authentication for remote session %s as user %s", session_name, username); reset_session (greeter); @@ -518,7 +518,7 @@ handle_continue_authentication (Greeter *greeter, gchar **secrets) return; } - g_debug ("Continue authentication"); + l_debug (greeter, "Continue authentication"); /* Build response */ response = calloc (messages_length, sizeof (struct pam_response)); @@ -548,7 +548,7 @@ handle_cancel_authentication (Greeter *greeter) if (greeter->priv->authentication_session == NULL) return; - g_debug ("Cancel authentication"); + l_debug (greeter, "Cancel authentication"); reset_session (greeter); } @@ -573,15 +573,15 @@ handle_start_session (Greeter *greeter, const gchar *session) if (greeter->priv->guest_account_authenticated || session_get_is_authenticated (greeter->priv->authentication_session)) { if (session) - g_debug ("Greeter requests session %s", session); + l_debug (greeter, "Greeter requests session %s", session); else - g_debug ("Greeter requests default session"); + l_debug (greeter, "Greeter requests default session"); greeter->priv->start_session = TRUE; g_signal_emit (greeter, signals[START_SESSION], 0, session_type, session, &result); } else { - g_debug ("Ignoring start session request, user is not authorized"); + l_debug (greeter, "Ignoring start session request, user is not authorized"); result = FALSE; } @@ -597,18 +597,18 @@ handle_set_language (Greeter *greeter, const gchar *language) if (!greeter->priv->guest_account_authenticated && !session_get_is_authenticated (greeter->priv->authentication_session)) { - g_debug ("Ignoring set language request, user is not authorized"); + l_debug (greeter, "Ignoring set language request, user is not authorized"); return; } // FIXME: Could use this if (greeter->priv->guest_account_authenticated) { - g_debug ("Ignoring set language request for guest user"); + l_debug (greeter, "Ignoring set language request for guest user"); return; } - g_debug ("Greeter sets language %s", language); + l_debug (greeter, "Greeter sets language %s", language); user = session_get_user (greeter->priv->authentication_session); user_set_language (user, language); } @@ -620,7 +620,7 @@ read_int (Greeter *greeter, gsize *offset) guint8 *buffer; if (greeter->priv->n_read - *offset < sizeof (guint32)) { - g_warning ("Not enough space for int, need %zu, got %zu", sizeof (guint32), greeter->priv->n_read - *offset); + l_warning (greeter, "Not enough space for int, need %zu, got %zu", sizeof (guint32), greeter->priv->n_read - *offset); return 0; } buffer = greeter->priv->read_buffer + *offset; @@ -640,7 +640,7 @@ get_message_length (Greeter *greeter) if (HEADER_SIZE + payload_length < HEADER_SIZE) { - g_warning ("Payload length of %u octets too long", payload_length); + l_warning (greeter, "Payload length of %u octets too long", payload_length); return HEADER_SIZE; } @@ -656,7 +656,7 @@ read_string_full (Greeter *greeter, gsize *offset, void* (*alloc_fn)(size_t n)) length = read_int (greeter, offset); if (greeter->priv->n_read - *offset < length) { - g_warning ("Not enough space for string, need %u, got %zu", length, greeter->priv->n_read - *offset); + l_warning (greeter, "Not enough space for string, need %u, got %zu", length, greeter->priv->n_read - *offset); return g_strdup (""); } @@ -697,7 +697,7 @@ read_cb (GIOChannel *source, GIOCondition condition, gpointer data) if (condition == G_IO_HUP) { - g_debug ("Greeter closed communication channel"); + l_debug (greeter, "Greeter closed communication channel"); return FALSE; } @@ -715,7 +715,7 @@ read_cb (GIOChannel *source, GIOCondition condition, gpointer data) &n_read, &error); if (error) - g_warning ("Error reading from greeter: %s", error->message); + l_warning (greeter, "Error reading from greeter: %s", error->message); g_clear_error (&error); if (status != G_IO_STATUS_NORMAL) return TRUE; @@ -767,7 +767,7 @@ read_cb (GIOChannel *source, GIOCondition condition, gpointer data) max_secrets = (G_MAXUINT32 - 1) / sizeof (gchar *); if (n_secrets > max_secrets) { - g_warning ("Array length of %u elements too long", n_secrets); + l_warning (greeter, "Array length of %u elements too long", n_secrets); return FALSE; } secrets = g_malloc (sizeof (gchar *) * (n_secrets + 1)); @@ -793,7 +793,7 @@ read_cb (GIOChannel *source, GIOCondition condition, gpointer data) g_free (language); break; default: - g_warning ("Unknown message from greeter: %d", id); + l_warning (greeter, "Unknown message from greeter: %d", id); break; } diff --git a/src/lightdm.c b/src/lightdm.c index 45292713..f92bc5ef 100644 --- a/src/lightdm.c +++ b/src/lightdm.c @@ -1168,8 +1168,9 @@ main (int argc, char **argv) gchar *config_section = *i; gchar *type; Seat *seat; + const gchar *const seatpfx = "Seat:"; - if (!g_str_has_prefix (config_section, "Seat:")) + if (!g_str_has_prefix (config_section, seatpfx)) continue; g_debug ("Loading seat %s", config_section); @@ -1180,6 +1181,11 @@ main (int argc, char **argv) g_free (type); if (seat) { + const gsize seatpfxlen = strlen(seatpfx); + gchar *seatname = config_section + seatpfxlen; + + seat_set_property (seat, "seat-name", seatname); + set_seat_properties (seat, config_section); display_manager_add_seat (display_manager, seat); g_object_unref (seat); diff --git a/src/logger.c b/src/logger.c new file mode 100644 index 00000000..23bce206 --- /dev/null +++ b/src/logger.c @@ -0,0 +1,81 @@ +#include "logger.h" + +G_DEFINE_INTERFACE (Logger, logger, G_TYPE_INVALID); + +static void +logger_logv_default (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap); + +static void +logger_default_init (LoggerInterface *iface) +{ + iface->logv = &logger_logv_default; +} + +gint +logger_logprefix (Logger *self, gchar *buf, gulong buflen) +{ + g_return_val_if_fail (IS_LOGGER (self), -1); + return LOGGER_GET_INTERFACE (self)->logprefix (self, buf, buflen); +} + +void +logger_logv (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap) +{ + g_return_if_fail (IS_LOGGER (self)); + LOGGER_GET_INTERFACE (self)->logv (self, log_level, format, ap); +} + +void +logger_logv_default (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap) +{ + va_list ap_copy; + gint tmp; + + /* figure out how long the prefix is */ + tmp = logger_logprefix (self, NULL, 0); + if (tmp < 0) + { + g_error ("failed to get log prefix"); + return; + } + + /* print the prefix to a variable length array (to avoid malloc) */ + gchar pfx[tmp + 1]; + tmp = logger_logprefix (self, pfx, sizeof(pfx)); + if (tmp < 0) + { + g_error ("failed to get log prefix"); + return; + } + + /* figure out how long the formatted message is */ + va_copy (ap_copy, ap); + tmp = g_vsnprintf (NULL, 0, format, ap_copy); + va_end (ap_copy); + if (tmp < 0) + { + g_error ("failed to format log message"); + return; + } + + /* print the message to a variable length array (to avoid malloc) */ + gchar msg[tmp+1]; + tmp = g_vsnprintf (msg, sizeof(msg), format, ap); + if (tmp < 0) + { + g_error ("failed to format log message"); + return; + } + + /* log the message with the prefix */ + g_log (G_LOG_DOMAIN, log_level, "%s%s", pfx, msg); +} + +void +logger_log (Logger *self, GLogLevelFlags log_level, const gchar *format, ...) +{ + va_list ap; + va_start (ap, format); + logger_logv (self, log_level, format, ap); + va_end (ap); +} diff --git a/src/logger.h b/src/logger.h new file mode 100644 index 00000000..f139e78b --- /dev/null +++ b/src/logger.h @@ -0,0 +1,60 @@ +#ifndef LOGGER_H_ +#define LOGGER_H_ + +#include <glib-object.h> + +#ifdef __cplusplus +#include <cstdarg> /* for va_list */ +#else +#include <stdarg.h> /* for va_list */ +#endif + +G_BEGIN_DECLS + +#define LOGGER_TYPE (logger_get_type ()) +#define LOGGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOGGER_TYPE, Logger)) +#define IS_LOGGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOGGER_TYPE)) +#define LOGGER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), LOGGER_TYPE, LoggerInterface)) + +typedef struct Logger Logger; + +typedef struct { + GTypeInterface parent; + + gint (*logprefix) (Logger *self, gchar *buf, gulong buflen); + void (*logv) (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap); +} LoggerInterface; + +GType logger_get_type (void); + +/*! + * \brief instruct \c self to generate a log message prefix + * + * the semantics of the \c buf and \c buflen arguments and the return + * value are the same as g_snprintf() + * + * there is no default implementation + */ +gint logger_logprefix (Logger *self, gchar *buf, gulong buflen); + +/*! + * \brief instruct \c self to log the given message + * + * the default implementation prefixes the log message with the + * output of logger_logprefix() and then passes the result to + * g_log() + */ +void logger_logv (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap); + +/*! \brief convenience wrapper around \c logger_logv() */ +void logger_log (Logger *self, GLogLevelFlags log_level, const gchar *format, ...); + +/* convenience wrappers around logger_log() */ +#define l_debug(self, ...) \ + logger_log (LOGGER (self), G_LOG_LEVEL_DEBUG, __VA_ARGS__) +#define l_warning(self, ...) \ + logger_log (LOGGER (self), G_LOG_LEVEL_WARNING, __VA_ARGS__) + +G_END_DECLS + +#endif /* !LOGGER_H_ */ diff --git a/src/seat-unity.c b/src/seat-unity.c index c0d25c35..a449aece 100644 --- a/src/seat-unity.c +++ b/src/seat-unity.c @@ -108,13 +108,13 @@ compositor_stopped_cb (Process *process, SeatUnity *seat) /* If stopped before it was ready, then revert to VT mode */ if (!seat->priv->compositor_ready) { - g_debug ("Compositor failed to start, switching to VT mode"); + l_debug (seat, "Compositor failed to start, switching to VT mode"); seat->priv->use_vt_switching = TRUE; SEAT_CLASS (seat_unity_parent_class)->start (SEAT (seat)); return; } - g_debug ("Stopping Unity seat, compositor terminated"); + l_debug (seat, "Stopping Unity seat, compositor terminated"); seat_stop (SEAT (seat)); } @@ -136,7 +136,7 @@ compositor_run_cb (Process *process, SeatUnity *seat) fd = g_open (seat->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd < 0) - g_warning ("Failed to open log file %s: %s", seat->priv->log_file, g_strerror (errno)); + l_warning (seat, "Failed to open log file %s: %s", seat->priv->log_file, g_strerror (errno)); else { dup2 (fd, STDOUT_FILENO); @@ -161,7 +161,7 @@ write_message (SeatUnity *seat, guint16 id, const guint8 *payload, guint16 paylo errno = 0; if (write (seat->priv->to_compositor_pipe[1], data, data_length) != data_length) - g_warning ("Failed to write to compositor: %s", strerror (errno)); + l_warning (seat, "Failed to write to compositor: %s", strerror (errno)); } static gboolean @@ -174,7 +174,7 @@ read_cb (GIOChannel *source, GIOCondition condition, gpointer data) if (condition == G_IO_HUP) { - g_debug ("Compositor closed communication channel"); + l_debug (seat, "Compositor closed communication channel"); return FALSE; } @@ -204,7 +204,7 @@ read_cb (GIOChannel *source, GIOCondition condition, gpointer data) &n_read, &error); if (error) - g_warning ("Failed to read from compositor: %s", error->message); + l_warning (seat, "Failed to read from compositor: %s", error->message); if (status != G_IO_STATUS_NORMAL) return TRUE; g_clear_error (&error); @@ -225,28 +225,28 @@ read_cb (GIOChannel *source, GIOCondition condition, gpointer data) switch (id) { case USC_MESSAGE_PING: - g_debug ("PING!"); + l_debug (seat, "PING!"); write_message (seat, USC_MESSAGE_PONG, NULL, 0); break; case USC_MESSAGE_PONG: - g_debug ("PONG!"); + l_debug (seat, "PONG!"); break; case USC_MESSAGE_READY: - g_debug ("READY"); + l_debug (seat, "READY"); if (!seat->priv->compositor_ready) { seat->priv->compositor_ready = TRUE; - g_debug ("Compositor ready"); + l_debug (seat, "Compositor ready"); g_source_remove (seat->priv->compositor_timeout); seat->priv->compositor_timeout = 0; SEAT_CLASS (seat_unity_parent_class)->start (SEAT (seat)); } break; case USC_MESSAGE_SESSION_CONNECTED: - g_debug ("SESSION CONNECTED"); + l_debug (seat, "SESSION CONNECTED"); break; default: - g_warning ("Ingoring unknown message %d with %d octets from system compositor", id, payload_length); + l_warning (seat, "Ignoring unknown message %d with %d octets from system compositor", id, payload_length); break; } @@ -310,7 +310,7 @@ seat_unity_start (Seat *seat) plymouth_quit (TRUE); } else - g_debug ("Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ()); + l_debug (seat, "Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ()); } if (plymouth_get_is_active ()) plymouth_quit (FALSE); @@ -318,7 +318,7 @@ seat_unity_start (Seat *seat) SEAT_UNITY (seat)->priv->vt = vt_get_unused (); if (SEAT_UNITY (seat)->priv->vt < 0) { - g_debug ("Failed to get a VT to run on"); + l_debug (seat, "Failed to get a VT to run on"); return FALSE; } vt_ref (SEAT_UNITY (seat)->priv->vt); @@ -326,7 +326,7 @@ seat_unity_start (Seat *seat) /* Create pipes to talk to compositor */ if (pipe (SEAT_UNITY (seat)->priv->to_compositor_pipe) < 0 || pipe (SEAT_UNITY (seat)->priv->from_compositor_pipe) < 0) { - g_debug ("Failed to create compositor pipes: %s", g_strerror (errno)); + l_debug (seat, "Failed to create compositor pipes: %s", g_strerror (errno)); return FALSE; } @@ -341,7 +341,7 @@ seat_unity_start (Seat *seat) /* Setup logging */ dir = config_get_string (config_get_instance (), "LightDM", "log-directory"); SEAT_UNITY (seat)->priv->log_file = g_build_filename (dir, "unity-system-compositor.log", NULL); - g_debug ("Logging to %s", SEAT_UNITY (seat)->priv->log_file); + l_debug (seat, "Logging to %s", SEAT_UNITY (seat)->priv->log_file); g_free (dir); SEAT_UNITY (seat)->priv->mir_socket_filename = g_strdup ("/tmp/mir_socket"); // FIXME: Use this socket by default as XMir is hardcoded to this @@ -372,7 +372,7 @@ seat_unity_start (Seat *seat) timeout = seat_get_integer_property (seat, "unity-compositor-timeout"); if (timeout <= 0) timeout = 60; - g_debug ("Waiting for system compositor for %ds", timeout); + l_debug (seat, "Waiting for system compositor for %ds", timeout); SEAT_UNITY (seat)->priv->compositor_timeout = g_timeout_add (timeout * 1000, compositor_timeout_cb, seat); return TRUE; @@ -386,7 +386,7 @@ create_x_server (Seat *seat) gboolean allow_tcp; gint port = 0; - g_debug ("Starting X server on Unity compositor"); + l_debug (seat, "Starting X server on Unity compositor"); x_server = x_server_local_new (); @@ -441,7 +441,7 @@ create_x_server (Seat *seat) keys = g_key_file_new (); result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error); if (error) - g_debug ("Error getting key %s", error->message); + l_debug (seat, "Error getting key %s", error->message); g_clear_error (&error); if (result) @@ -451,7 +451,7 @@ create_x_server (Seat *seat) if (g_key_file_has_key (keys, "keyring", key_name, NULL)) key = g_key_file_get_string (keys, "keyring", key_name, NULL); else - g_debug ("Key %s not defined", key_name); + l_debug (seat, "Key %s not defined", key_name); if (key) x_server_local_set_xdmcp_key (x_server, key); @@ -498,7 +498,7 @@ seat_unity_create_display_server (Seat *seat, const gchar *session_type) return create_mir_server (seat); else { - g_warning ("Can't create unsupported display server '%s'", session_type); + l_warning (seat, "Can't create unsupported display server '%s'", session_type); return NULL; } } @@ -507,15 +507,21 @@ static Greeter * seat_unity_create_greeter_session (Seat *seat) { Greeter *greeter_session; + const gchar *xdg_seat; greeter_session = SEAT_CLASS (seat_unity_parent_class)->create_greeter_session (seat); - session_set_env (SESSION (greeter_session), "XDG_SEAT", "seat0"); + xdg_seat = "seat0"; + l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat); + session_set_env (SESSION (greeter_session), "XDG_SEAT", xdg_seat); if (!SEAT_UNITY (seat)->priv->use_vt_switching) { gchar *value = g_strdup_printf ("%d", SEAT_UNITY (seat)->priv->vt); + l_debug (seat, "Setting XDG_VTNR=%s", value); session_set_env (SESSION (greeter_session), "XDG_VTNR", value); g_free (value); } + else + l_debug (seat, "Not setting XDG_VTNR"); return greeter_session; } @@ -524,15 +530,21 @@ static Session * seat_unity_create_session (Seat *seat) { Session *session; + const gchar *xdg_seat; session = SEAT_CLASS (seat_unity_parent_class)->create_session (seat); - session_set_env (session, "XDG_SEAT", "seat0"); + xdg_seat = "seat0"; + l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat); + session_set_env (session, "XDG_SEAT", xdg_seat); if (!SEAT_UNITY (seat)->priv->use_vt_switching) { gchar *value = g_strdup_printf ("%d", SEAT_UNITY (seat)->priv->vt); + l_debug (seat, "Setting XDG_VTNR=%s", value); session_set_env (SESSION (session), "XDG_VTNR", value); g_free (value); } + else + l_debug (seat, "Not setting XDG_VTNR"); return session; } @@ -571,11 +583,11 @@ seat_unity_set_active_session (Seat *seat, Session *session) if (id) { - g_debug ("Switching to Mir session %s", id); + l_debug (seat, "Switching to Mir session %s", id); write_message (SEAT_UNITY (seat), USC_MESSAGE_SET_ACTIVE_SESSION, (const guint8 *) id, strlen (id)); } else - g_warning ("Failed to work out session ID"); + l_warning (seat, "Failed to work out session ID"); } SEAT_CLASS (seat_unity_parent_class)->set_active_session (seat, session); diff --git a/src/seat-xlocal.c b/src/seat-xlocal.c index d3fd0d13..7b626de8 100644 --- a/src/seat-xlocal.c +++ b/src/seat-xlocal.c @@ -69,9 +69,9 @@ seat_xlocal_create_display_server (Seat *seat, const gchar *session_type) gint vt = -1, port = 0; if (vt > 0) - g_debug ("Starting local X display on VT %d", vt); + l_debug (seat, "Starting local X display on VT %d", vt); else - g_debug ("Starting local X display"); + l_debug (seat, "Starting local X display"); x_server = x_server_local_new (); @@ -95,7 +95,7 @@ seat_xlocal_create_display_server (Seat *seat, const gchar *session_type) plymouth_deactivate (); } else - g_debug ("Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ()); + l_debug (seat, "Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ()); } if (plymouth_get_is_active ()) plymouth_quit (FALSE); @@ -138,7 +138,7 @@ seat_xlocal_create_display_server (Seat *seat, const gchar *session_type) keys = g_key_file_new (); result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error); if (error) - g_debug ("Error getting key %s", error->message); + l_debug (seat, "Error getting key %s", error->message); g_clear_error (&error); if (result) @@ -148,7 +148,7 @@ seat_xlocal_create_display_server (Seat *seat, const gchar *session_type) if (g_key_file_has_key (keys, "keyring", key_name, NULL)) key = g_key_file_get_string (keys, "keyring", key_name, NULL); else - g_debug ("Key %s not defined", key_name); + l_debug (seat, "Key %s not defined", key_name); if (key) x_server_local_set_xdmcp_key (x_server, key); @@ -166,9 +166,12 @@ static Greeter * seat_xlocal_create_greeter_session (Seat *seat) { Greeter *greeter_session; + const gchar *xdg_seat; greeter_session = SEAT_CLASS (seat_xlocal_parent_class)->create_greeter_session (seat); - session_set_env (SESSION (greeter_session), "XDG_SEAT", "seat0"); + xdg_seat = "seat0"; + l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat); + session_set_env (SESSION (greeter_session), "XDG_SEAT", xdg_seat); return greeter_session; } @@ -177,9 +180,12 @@ static Session * seat_xlocal_create_session (Seat *seat) { Session *session; + const gchar *xdg_seat; session = SEAT_CLASS (seat_xlocal_parent_class)->create_session (seat); - session_set_env (SESSION (session), "XDG_SEAT", "seat0"); + xdg_seat = "seat0"; + l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat); + session_set_env (SESSION (session), "XDG_SEAT", xdg_seat); return session; } diff --git a/src/seat-xremote.c b/src/seat-xremote.c index 0e60717f..05b25e0c 100644 --- a/src/seat-xremote.c +++ b/src/seat-xremote.c @@ -33,7 +33,7 @@ seat_xremote_create_display_server (Seat *seat, const gchar *session_type) if (strcmp (session_type, "x") != 0) { - g_warning ("X remote seat only supports X display servers, not '%s'", session_type); + l_warning (seat, "X remote seat only supports X display servers, not '%s'", session_type); return NULL; } @@ -42,7 +42,7 @@ seat_xremote_create_display_server (Seat *seat, const gchar *session_type) hostname = "localhost"; number = seat_get_integer_property (seat, "xserver-display-number"); - g_debug ("Starting remote X display %s:%d", hostname, number); + l_debug (seat, "Starting remote X display %s:%d", hostname, number); x_server = x_server_remote_new (hostname, number, NULL); @@ -53,9 +53,12 @@ static Greeter * seat_xremote_create_greeter_session (Seat *seat) { Greeter *greeter_session; + const gchar *xdg_seat; greeter_session = SEAT_CLASS (seat_xremote_parent_class)->create_greeter_session (seat); - session_set_env (SESSION (greeter_session), "XDG_SEAT", "seat0"); + xdg_seat = "seat0"; + l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat); + session_set_env (SESSION (greeter_session), "XDG_SEAT", xdg_seat); return greeter_session; } @@ -64,9 +67,12 @@ static Session * seat_xremote_create_session (Seat *seat) { Session *session; + const gchar *xdg_seat; session = SEAT_CLASS (seat_xremote_parent_class)->create_session (seat); - session_set_env (SESSION (session), "XDG_SEAT", "seat0"); + xdg_seat = "seat0"; + l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat); + session_set_env (SESSION (session), "XDG_SEAT", xdg_seat); return session; } @@ -66,7 +66,11 @@ struct SeatPrivate #define USER_SERVICE "lightdm" #define AUTOLOGIN_SERVICE "lightdm-autologin" -G_DEFINE_TYPE (Seat, seat, G_TYPE_OBJECT); +static void seat_logger_iface_init (LoggerInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (Seat, seat, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE ( + LOGGER_TYPE, seat_logger_iface_init)); typedef struct { @@ -198,7 +202,7 @@ seat_set_active_session (Seat *seat, Session *session) if (IS_GREETER (s)) { - g_debug ("Stopping greeter"); + l_debug (seat, "Stopping greeter"); session_stop (s); } } @@ -277,7 +281,7 @@ run_script (Seat *seat, DisplayServer *display_server, const gchar *script_name, exit_status = process_get_exit_status (script); if (WIFEXITED (exit_status)) { - g_debug ("Exit status of %s: %d", script_name, WEXITSTATUS (exit_status)); + l_debug (seat, "Exit status of %s: %d", script_name, WEXITSTATUS (exit_status)); result = WEXITSTATUS (exit_status) == EXIT_SUCCESS; } } @@ -315,7 +319,7 @@ check_stopped (Seat *seat) g_list_length (seat->priv->sessions) == 0) { seat->priv->stopped = TRUE; - g_debug ("Seat stopped"); + l_debug (seat, "Stopped"); g_signal_emit (seat, signals[STOPPED], 0); } } @@ -332,7 +336,7 @@ display_server_stopped_cb (DisplayServer *display_server, Seat *seat) GList *list, *link; Session *active_session; - g_debug ("Display server stopped"); + l_debug (seat, "Display server stopped"); g_signal_handlers_disconnect_matched (display_server, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat); seat->priv->display_servers = g_list_remove (seat->priv->display_servers, display_server); @@ -360,11 +364,11 @@ display_server_stopped_cb (DisplayServer *display_server, Seat *seat) !session_get_is_started (session) && g_list_length (seat->priv->display_servers) == 0) { - g_debug ("Stopping seat, greeter display server failed to start"); + l_debug (seat, "Stopping; greeter display server failed to start"); seat_stop (seat); } - g_debug ("Stopping session"); + l_debug (seat, "Stopping session"); session_stop (session); } g_list_free_full (list, g_object_unref); @@ -375,7 +379,7 @@ display_server_stopped_cb (DisplayServer *display_server, Seat *seat) active_session = seat_get_active_session (seat); if (!active_session || session_get_display_server (active_session) == display_server) { - g_debug ("Active display server stopped, starting greeter"); + l_debug (seat, "Active display server stopped, starting greeter"); seat_switch_to_greeter (seat); } } @@ -412,7 +416,7 @@ switch_to_greeter_from_failed_session (Seat *seat, Session *session) display_server = create_display_server (seat, session_get_session_type (session)); if (!display_server_start (display_server)) { - g_debug ("Failed to start display server for greeter"); + l_debug (seat, "Failed to start display server for greeter"); seat_stop (seat); } @@ -447,12 +451,12 @@ start_session (Seat *seat, Session *session) if (IS_GREETER (session)) { - g_debug ("Failed to start greeter"); + l_debug (seat, "Failed to start greeter"); display_server_stop (session_get_display_server (session)); return; } - g_debug ("Failed to start session, starting greeter"); + l_debug (seat, "Failed to start session, starting greeter"); switch_to_greeter_from_failed_session (seat, session); } @@ -467,7 +471,7 @@ run_session (Seat *seat, Session *session) script = seat_get_string_property (seat, "session-setup-script"); if (script && !run_script (seat, session_get_display_server (session), script, NULL)) { - g_debug ("Switching to greeter due to failed setup script"); + l_debug (seat, "Switching to greeter due to failed setup script"); switch_to_greeter_from_failed_session (seat, session); return; } @@ -495,17 +499,17 @@ session_authentication_complete_cb (Session *session, Seat *seat) { if (session_get_is_authenticated (session)) { - g_debug ("Session authenticated, running command"); + l_debug (seat, "Session authenticated, running command"); run_session (seat, session); } else if (!IS_GREETER (session)) { - g_debug ("Switching to greeter due to failed authentication"); + l_debug (seat, "Switching to greeter due to failed authentication"); switch_to_greeter_from_failed_session (seat, session); } else { - g_debug ("Stopping session that failed authentication"); + l_debug (seat, "Stopping session that failed authentication"); session_stop (session); } } @@ -515,7 +519,7 @@ session_stopped_cb (Session *session, Seat *seat) { DisplayServer *display_server; - g_debug ("Session stopped"); + l_debug (seat, "Session stopped"); g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat); seat->priv->sessions = g_list_remove (seat->priv->sessions, session); @@ -578,12 +582,12 @@ session_stopped_cb (Session *session, Seat *seat) if (session_get_is_authenticated (s)) { - g_debug ("Greeter stopped, running session"); + l_debug (seat, "Greeter stopped, running session"); run_session (seat, s); } else { - g_debug ("Greeter stopped, starting session authentication"); + l_debug (seat, "Greeter stopped, starting session authentication"); start_session (seat, s); } break; @@ -595,13 +599,13 @@ session_stopped_cb (Session *session, Seat *seat) g_list_length (seat->priv->display_servers) == 1 && g_list_nth_data (seat->priv->display_servers, 0) == display_server) { - g_debug ("Stopping seat, failed to start a greeter"); + l_debug (seat, "Stopping; failed to start a greeter"); seat_stop (seat); } /* If we were the active session, switch to a greeter */ else if (!IS_GREETER (session) && session == seat_get_active_session (seat)) { - g_debug ("Active session stopped, starting greeter"); + l_debug (seat, "Active session stopped, starting greeter"); seat_switch_to_greeter (seat); } @@ -621,7 +625,7 @@ session_stopped_cb (Session *session, Seat *seat) } if (n_sessions == 0) { - g_debug ("Stopping display server, no sessions require it"); + l_debug (seat, "Stopping display server, no sessions require it"); display_server_stop (display_server); } } @@ -678,7 +682,7 @@ create_session (Seat *seat, gboolean autostart) } static gchar ** -get_session_argv (SessionConfig *session_config, const gchar *session_wrapper) +get_session_argv (Seat *seat, SessionConfig *session_config, const gchar *session_wrapper) { gboolean result; int argc; @@ -699,7 +703,7 @@ get_session_argv (SessionConfig *session_config, const gchar *session_wrapper) /* Split command into an array listing and make command absolute */ result = g_shell_parse_argv (session_config_get_command (session_config), &argc, &argv, &error); if (error) - g_debug ("Invalid session command '%s': %s", session_config_get_command (session_config), error->message); + l_debug (seat, "Invalid session command '%s': %s", session_config_get_command (session_config), error->message); g_clear_error (&error); if (!result) return NULL; @@ -714,7 +718,7 @@ get_session_argv (SessionConfig *session_config, const gchar *session_wrapper) } static SessionConfig * -find_session_config (const gchar *sessions_dir, const gchar *session_name) +find_session_config (Seat *seat, const gchar *sessions_dir, const gchar *session_name) { gchar **dirs; SessionConfig *session_config = NULL; @@ -738,7 +742,7 @@ find_session_config (const gchar *sessions_dir, const gchar *session_name) break; if (dirs[i+1] == NULL) - g_debug ("Failed to find session configuration %s", session_name); + l_debug (seat, "Failed to find session configuration %s", session_name); g_clear_error (&error); } g_strfreev (dirs); @@ -755,13 +759,13 @@ create_user_session (Seat *seat, const gchar *username) SessionConfig *session_config; Session *session = NULL; - g_debug ("Creating user session"); + l_debug (seat, "Creating user session"); /* Load user preferences */ user = accounts_get_user_by_name (username); if (!user) { - g_debug ("Can't login unknown user '%s'", username); + l_debug (seat, "Can't login unknown user '%s'", username); return NULL; } session_name = user_get_xsession (user); @@ -770,7 +774,7 @@ create_user_session (Seat *seat, const gchar *username) if (!session_name) session_name = seat_get_string_property (seat, "user-session"); sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory"); - session_config = find_session_config (sessions_dir, session_name); + session_config = find_session_config (seat, sessions_dir, session_name); g_free (sessions_dir); if (session_config) { @@ -792,14 +796,14 @@ create_user_session (Seat *seat, const gchar *username) session_set_pam_service (session, AUTOLOGIN_SERVICE); session_set_username (session, username); session_set_do_authenticate (session, TRUE); - argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper")); + argv = get_session_argv (seat, session_config, seat_get_string_property (seat, "session-wrapper")); session_set_argv (session, argv); g_strfreev (argv); g_object_unref (session_config); } else - g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session")); + l_debug (seat, "Can't find session '%s'", seat_get_string_property (seat, "user-session")); g_object_unref (user); @@ -815,11 +819,11 @@ create_guest_session (Seat *seat) Session *session; sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory"); - session_config = find_session_config (sessions_dir, seat_get_string_property (seat, "user-session")); + session_config = find_session_config (seat, sessions_dir, seat_get_string_property (seat, "user-session")); g_free (sessions_dir); if (!session_config) { - g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session")); + l_debug (seat, "Can't find session '%s'", seat_get_string_property (seat, "user-session")); return NULL; } @@ -827,7 +831,7 @@ create_guest_session (Seat *seat) session_set_session_type (session, session_config_get_session_type (session_config)); session_set_do_authenticate (session, TRUE); session_set_is_guest (session, TRUE); - argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper")); + argv = get_session_argv (seat, session_config, seat_get_string_property (seat, "session-wrapper")); g_object_unref (session_config); session_set_argv (session, argv); g_strfreev (argv); @@ -915,7 +919,7 @@ greeter_start_session_cb (Greeter *greeter, SessionType type, const gchar *sessi existing_session = find_user_session (seat, username); if (existing_session && session != existing_session) { - g_debug ("Returning to existing user session %s", username); + l_debug (seat, "Returning to existing user session %s", username); session_stop (session); seat_set_active_session (seat, existing_session); return TRUE; @@ -946,16 +950,16 @@ greeter_start_session_cb (Greeter *greeter, SessionType type, const gchar *sessi if (user) user_set_xsession (session_get_user (session), session_name); - session_config = find_session_config (sessions_dir, session_name); + session_config = find_session_config (seat, sessions_dir, session_name); g_free (sessions_dir); if (!session_config) { - g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session")); + l_debug (seat, "Can't find session '%s'", seat_get_string_property (seat, "user-session")); return FALSE; } session_set_session_type (session, session_config_get_session_type (session_config)); - argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper")); + argv = get_session_argv (seat, session_config, seat_get_string_property (seat, "session-wrapper")); session_set_argv (session, argv); g_strfreev (argv); session_set_env (session, "DESKTOP_SESSION", session_name); @@ -973,7 +977,7 @@ greeter_start_session_cb (Greeter *greeter, SessionType type, const gchar *sessi if (can_share_display_server (seat, display_server) && strcmp (display_server_get_session_type (display_server), session_get_session_type (session)) == 0) { - g_debug ("Stopping greeter; display server will be re-used for user session"); + l_debug (seat, "Stopping greeter; display server will be re-used for user session"); /* Run on the same display server after the greeter has stopped */ session_set_display_server (session, display_server); @@ -990,7 +994,7 @@ greeter_start_session_cb (Greeter *greeter, SessionType type, const gchar *sessi session_set_display_server (session, display_server); if (!display_server_start (display_server)) { - g_debug ("Failed to start display server for new session"); + l_debug (seat, "Failed to start display server for new session"); return FALSE; } @@ -1007,15 +1011,15 @@ create_greeter_session (Seat *seat) gchar *greeter_user; const gchar *greeter_wrapper; - g_debug ("Creating greeter session"); + l_debug (seat, "Creating greeter session"); sessions_dir = config_get_string (config_get_instance (), "LightDM", "greeters-directory"); - session_config = find_session_config (sessions_dir, seat_get_string_property (seat, "greeter-session")); + session_config = find_session_config (seat, sessions_dir, seat_get_string_property (seat, "greeter-session")); g_free (sessions_dir); if (!session_config) return NULL; - argv = get_session_argv (session_config, NULL); + argv = get_session_argv (seat, session_config, NULL); greeter_wrapper = seat_get_string_property (seat, "greeter-wrapper"); if (greeter_wrapper) { @@ -1082,7 +1086,7 @@ display_server_ready_cb (DisplayServer *display_server, Seat *seat) script = seat_get_string_property (seat, "display-setup-script"); if (script && !run_script (seat, display_server, script, NULL)) { - g_debug ("Stopping display server due to failed setup script"); + l_debug (seat, "Stopping display server due to failed setup script"); display_server_stop (display_server); return; } @@ -1099,18 +1103,18 @@ display_server_ready_cb (DisplayServer *display_server, Seat *seat) { if (session_get_is_authenticated (session)) { - g_debug ("Display server ready, running session"); + l_debug (seat, "Display server ready, running session"); run_session (seat, session); } else { - g_debug ("Display server ready, starting session authentication"); + l_debug (seat, "Display server ready, starting session authentication"); start_session (seat, session); } } else { - g_debug ("Stopping not required display server"); + l_debug (seat, "Stopping not required display server"); display_server_stop (display_server); } } @@ -1120,7 +1124,7 @@ create_display_server (Seat *seat, const gchar *session_type) { DisplayServer *display_server; - g_debug ("Creating display server of type %s", session_type); + l_debug (seat, "Creating display server of type %s", session_type); display_server = SEAT_GET_CLASS (seat)->create_display_server (seat, session_type); if (!display_server) @@ -1163,7 +1167,7 @@ seat_switch_to_greeter (Seat *seat) greeter_session = find_greeter_session (seat); if (greeter_session) { - g_debug ("Switching to existing greeter"); + l_debug (seat, "Switching to existing greeter"); seat_set_active_session (seat, SESSION (greeter_session)); return TRUE; } @@ -1193,12 +1197,12 @@ seat_switch_to_user (Seat *seat, const gchar *username, const gchar *session_nam if (!seat->priv->can_switch) return FALSE; - g_debug ("Switching to user %s", username); + l_debug (seat, "Switching to user %s", username); session = find_user_session (seat, username); if (session) { - g_debug ("Switching to existing user session %s", username); + l_debug (seat, "Switching to existing user session %s", username); seat_set_active_session (seat, session); return TRUE; } @@ -1249,7 +1253,7 @@ seat_switch_to_guest (Seat *seat, const gchar *session_name) session = find_guest_session (seat); if (session) { - g_debug ("Switching to existing guest account %s", session_get_username (session)); + l_debug (seat, "Switching to existing guest account %s", session_get_username (session)); seat_set_active_session (seat, session); return TRUE; } @@ -1282,13 +1286,13 @@ seat_lock (Seat *seat, const gchar *username) if (!seat->priv->can_switch) return FALSE; - g_debug ("Locking seat"); + l_debug (seat, "Locking"); /* Switch to greeter if one open (shouldn't be though) */ greeter_session = find_greeter_session (seat); if (greeter_session) { - g_debug ("Switching to existing greeter"); + l_debug (seat, "Switching to existing greeter"); seat_set_active_session (seat, SESSION (greeter_session)); return TRUE; } @@ -1320,7 +1324,7 @@ seat_stop (Seat *seat) if (seat->priv->stopping) return; - g_debug ("Stopping seat"); + l_debug (seat, "Stopping"); seat->priv->stopping = TRUE; SEAT_GET_CLASS (seat)->stop (seat); } @@ -1352,7 +1356,7 @@ seat_real_start (Seat *seat) gboolean autologin_in_background; Session *session = NULL, *background_session = NULL; - g_debug ("Starting seat"); + l_debug (seat, "Starting"); /* If this display server doesn't have a session running on it, just start it */ if (!get_start_local_sessions (seat)) @@ -1400,7 +1404,7 @@ seat_real_start (Seat *seat) session_set_display_server (session, display_server); if (!display_server || !display_server_start (display_server)) { - g_debug ("Can't create display server for automatic login"); + l_debug (seat, "Can't create display server for automatic login"); session_stop (session); if (display_server) display_server_stop (display_server); @@ -1418,7 +1422,7 @@ seat_real_start (Seat *seat) greeter_session = create_greeter_session (seat); if (!greeter_session) { - g_debug ("Failed to create greeter session"); + l_debug (seat, "Failed to create greeter session"); return FALSE; } @@ -1444,7 +1448,7 @@ seat_real_start (Seat *seat) session_set_display_server (session, display_server); if (!display_server || !display_server_start (display_server)) { - g_debug ("Can't create display server for greeter"); + l_debug (seat, "Can't create display server for greeter"); session_stop (session); if (display_server) display_server_stop (display_server); @@ -1467,7 +1471,7 @@ seat_real_start (Seat *seat) background_display_server = create_display_server (seat, session_get_session_type (background_session)); session_set_display_server (background_session, background_display_server); if (!display_server_start (background_display_server)) - g_warning ("Failed to start display server for background session"); + l_warning (seat, "Failed to start display server for background session"); } seat->priv->started = TRUE; @@ -1516,7 +1520,7 @@ seat_real_stop (Seat *seat) DisplayServer *display_server = link->data; if (!display_server_get_is_stopping (display_server)) { - g_debug ("Stopping display server"); + l_debug (seat, "Stopping display server"); display_server_stop (display_server); } } @@ -1529,7 +1533,7 @@ seat_real_stop (Seat *seat) Session *session = link->data; if (!session_get_is_stopping (session)) { - g_debug ("Stopping session"); + l_debug (seat, "Stopping session"); session_stop (session); } } @@ -1625,3 +1629,20 @@ seat_class_init (SeatClass *klass) NULL, G_TYPE_NONE, 0); } + +static gint +seat_real_logprefix (Logger *self, gchar *buf, gulong buflen) +{ + Seat *seat = SEAT (self); + const gchar *name = seat_get_string_property (seat, "seat-name"); + if (name) + return g_snprintf (buf, buflen, "Seat %s: ", name); + else + return g_snprintf (buf, buflen, "Seat: "); +} + +static void +seat_logger_iface_init (LoggerInterface *iface) +{ + iface->logprefix = &seat_real_logprefix; +} @@ -17,6 +17,7 @@ #include "greeter.h" #include "session.h" #include "process.h" +#include "logger.h" G_BEGIN_DECLS diff --git a/src/session.c b/src/session.c index ecba9f4c..1ad341c4 100644 --- a/src/session.c +++ b/src/session.c @@ -120,7 +120,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) @@ -338,7 +342,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 +386,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 +402,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 +418,18 @@ session_watch_cb (GPid pid, gint status, gpointer data) { Session *session = data; - session->priv->pid = 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 +478,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 +492,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 +515,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); } @@ -616,7 +621,7 @@ session_real_start (Session *session) 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 +732,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 +745,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); @@ -819,7 +824,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 } @@ -920,3 +925,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; +} diff --git a/src/session.h b/src/session.h index eb2dad4c..11182b5c 100644 --- a/src/session.h +++ b/src/session.h @@ -21,6 +21,7 @@ typedef struct Session Session; #include "display-server.h" #include "accounts.h" #include "x-authority.h" +#include "logger.h" G_BEGIN_DECLS diff --git a/src/x-server-local.c b/src/x-server-local.c index ae3481c3..12c32e15 100644 --- a/src/x-server-local.c +++ b/src/x-server-local.c @@ -333,7 +333,7 @@ run_cb (Process *process, XServerLocal *server) fd = g_open (server->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd < 0) - g_warning ("Failed to open log file %s: %s", server->priv->log_file, g_strerror (errno)); + l_warning (server, "Failed to open log file %s: %s", server->priv->log_file, g_strerror (errno)); else { dup2 (fd, STDOUT_FILENO); @@ -352,7 +352,7 @@ got_signal_cb (Process *process, int signum, XServerLocal *server) if (signum == SIGUSR1 && !server->priv->got_signal) { server->priv->got_signal = TRUE; - g_debug ("Got signal from X server :%d", x_server_get_display_number (X_SERVER (server))); + l_debug (server, "Got signal from X server :%d", x_server_get_display_number (X_SERVER (server))); // FIXME: Check return value DISPLAY_SERVER_CLASS (x_server_local_parent_class)->start (DISPLAY_SERVER (server)); @@ -362,7 +362,7 @@ got_signal_cb (Process *process, int signum, XServerLocal *server) static void stopped_cb (Process *process, XServerLocal *server) { - g_debug ("X server stopped"); + l_debug (server, "X server stopped"); /* Release VT and display number for re-use */ if (server->priv->have_vt_ref) @@ -374,7 +374,7 @@ stopped_cb (Process *process, XServerLocal *server) if (x_server_get_authority (X_SERVER (server)) && server->priv->authority_file) { - g_debug ("Removing X server authority %s", server->priv->authority_file); + l_debug (server, "Removing X server authority %s", server->priv->authority_file); g_unlink (server->priv->authority_file); @@ -404,17 +404,17 @@ write_authority_file (XServerLocal *server) dir = g_build_filename (run_dir, "root", NULL); g_free (run_dir); if (g_mkdir_with_parents (dir, S_IRWXU) < 0) - g_warning ("Failed to make authority directory %s: %s", dir, strerror (errno)); + l_warning (server, "Failed to make authority directory %s: %s", dir, strerror (errno)); server->priv->authority_file = g_build_filename (dir, x_server_get_address (X_SERVER (server)), NULL); g_free (dir); } - g_debug ("Writing X server authority to %s", server->priv->authority_file); + l_debug (server, "Writing X server authority to %s", server->priv->authority_file); x_authority_write (authority, XAUTH_WRITE_MODE_REPLACE, server->priv->authority_file, &error); if (error) - g_warning ("Failed to write authority: %s", error->message); + l_warning (server, "Failed to write authority: %s", error->message); g_clear_error (&error); } @@ -442,14 +442,14 @@ x_server_local_start (DisplayServer *display_server) filename = g_strdup_printf ("%s.log", display_server_get_name (display_server)); dir = config_get_string (config_get_instance (), "LightDM", "log-directory"); server->priv->log_file = g_build_filename (dir, filename, NULL); - g_debug ("Logging to %s", server->priv->log_file); + l_debug (display_server, "Logging to %s", server->priv->log_file); g_free (filename); g_free (dir); absolute_command = get_absolute_command (server->priv->command); if (!absolute_command) { - g_debug ("Can't launch X server %s, not found in path", server->priv->command); + l_debug (display_server, "Can't launch X server %s, not found in path", server->priv->command); stopped_cb (server->priv->x_server_process, X_SERVER_LOCAL (server)); return FALSE; } @@ -496,7 +496,7 @@ x_server_local_start (DisplayServer *display_server) process_set_command (server->priv->x_server_process, command->str); g_string_free (command, TRUE); - g_debug ("Launching X Server"); + l_debug (display_server, "Launching X Server"); /* If running inside another display then pass through those variables */ if (g_getenv ("DISPLAY")) @@ -524,7 +524,7 @@ x_server_local_start (DisplayServer *display_server) result = process_start (server->priv->x_server_process, FALSE); if (result) - g_debug ("Waiting for ready signal from X server :%d", x_server_get_display_number (X_SERVER (server))); + l_debug (display_server, "Waiting for ready signal from X server :%d", x_server_get_display_number (X_SERVER (server))); if (!result) stopped_cb (server->priv->x_server_process, X_SERVER_LOCAL (server)); diff --git a/src/x-server-xvnc.c b/src/x-server-xvnc.c index 3595ddef..0897725d 100644 --- a/src/x-server-xvnc.c +++ b/src/x-server-xvnc.c @@ -144,7 +144,7 @@ run_cb (Process *process, XServerXVNC *server) fd = g_open (server->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd < 0) - g_warning ("Failed to open log file %s: %s", server->priv->log_file, g_strerror (errno)); + l_warning (server, "Failed to open log file %s: %s", server->priv->log_file, g_strerror (errno)); else { dup2 (fd, STDERR_FILENO); @@ -162,7 +162,7 @@ got_signal_cb (Process *process, int signum, XServerXVNC *server) if (signum == SIGUSR1 && !server->priv->got_signal) { server->priv->got_signal = TRUE; - g_debug ("Got signal from Xvnc server :%d", x_server_get_display_number (X_SERVER (server))); + l_debug (server, "Got signal from Xvnc server :%d", x_server_get_display_number (X_SERVER (server))); // FIXME: Check return value DISPLAY_SERVER_CLASS (x_server_xvnc_parent_class)->start (DISPLAY_SERVER (server)); @@ -172,14 +172,14 @@ got_signal_cb (Process *process, int signum, XServerXVNC *server) static void stopped_cb (Process *process, XServerXVNC *server) { - g_debug ("Xvnc server stopped"); + l_debug (server, "Xvnc server stopped"); g_object_unref (server->priv->x_server_process); server->priv->x_server_process = NULL; x_server_local_release_display_number (x_server_get_display_number (X_SERVER (server))); - g_debug ("Removing X server authority %s", server->priv->authority_file); + l_debug (server, "Removing X server authority %s", server->priv->authority_file); g_unlink (server->priv->authority_file); g_free (server->priv->authority_file); @@ -219,14 +219,14 @@ x_server_xvnc_start (DisplayServer *display_server) filename = g_strdup_printf ("%s.log", display_server_get_name (display_server)); dir = config_get_string (config_get_instance (), "LightDM", "log-directory"); server->priv->log_file = g_build_filename (dir, filename, NULL); - g_debug ("Logging to %s", server->priv->log_file); + l_debug (display_server, "Logging to %s", server->priv->log_file); g_free (filename); g_free (dir); absolute_command = get_absolute_command (server->priv->command); if (!absolute_command) { - g_debug ("Can't launch X server %s, not found in path", server->priv->command); + l_debug (display_server, "Can't launch X server %s, not found in path", server->priv->command); stopped_cb (server->priv->x_server_process, X_SERVER_XVNC (server)); return FALSE; } @@ -241,16 +241,16 @@ x_server_xvnc_start (DisplayServer *display_server) dir = g_build_filename (run_dir, "root", NULL); g_free (run_dir); if (g_mkdir_with_parents (dir, S_IRWXU) < 0) - g_warning ("Failed to make authority directory %s: %s", dir, strerror (errno)); + l_warning (display_server, "Failed to make authority directory %s: %s", dir, strerror (errno)); server->priv->authority_file = g_build_filename (dir, x_server_get_address (X_SERVER (server)), NULL); g_free (dir); - g_debug ("Writing X server authority to %s", server->priv->authority_file); + l_debug (display_server, "Writing X server authority to %s", server->priv->authority_file); x_authority_write (authority, XAUTH_WRITE_MODE_REPLACE, server->priv->authority_file, &error); if (error) - g_warning ("Failed to write authority: %s", error->message); + l_warning (display_server, "Failed to write authority: %s", error->message); g_clear_error (&error); command = g_string_new (absolute_command); @@ -267,7 +267,7 @@ x_server_xvnc_start (DisplayServer *display_server) process_set_command (server->priv->x_server_process, command->str); g_string_free (command, TRUE); - g_debug ("Launching Xvnc server"); + l_debug (display_server, "Launching Xvnc server"); /* Variable required for regression tests */ if (g_getenv ("LIGHTDM_TEST_ROOT")) @@ -279,7 +279,7 @@ x_server_xvnc_start (DisplayServer *display_server) result = process_start (server->priv->x_server_process, FALSE); if (result) - g_debug ("Waiting for ready signal from Xvnc server :%d", x_server_get_display_number (X_SERVER (server))); + l_debug (display_server, "Waiting for ready signal from Xvnc server :%d", x_server_get_display_number (X_SERVER (server))); if (!result) stopped_cb (server->priv->x_server_process, X_SERVER_XVNC (server)); diff --git a/src/x-server.c b/src/x-server.c index aafba97e..94154601 100644 --- a/src/x-server.c +++ b/src/x-server.c @@ -133,11 +133,11 @@ x_server_start (DisplayServer *display_server) } /* Open connection */ - g_debug ("Connecting to XServer %s", x_server_get_address (server)); + l_debug (server, "Connecting to XServer %s", x_server_get_address (server)); server->priv->connection = xcb_connect_to_display_with_auth_info (x_server_get_address (server), auth, NULL); if (xcb_connection_has_error (server->priv->connection)) { - g_debug ("Error connecting to XServer %s", x_server_get_address (server)); + l_debug (server, "Error connecting to XServer %s", x_server_get_address (server)); return FALSE; } @@ -161,9 +161,12 @@ x_server_connect_session (DisplayServer *display_server, Session *session) g_free (t); t = g_strdup_printf ("%d", vt); + l_debug (session, "Setting XDG_VTNR=%s", t); session_set_env (session, "XDG_VTNR", t); g_free (t); } + else + l_debug (session, "Not setting XDG_VTNR"); session_set_env (session, "DISPLAY", x_server_get_address (X_SERVER (display_server))); session_set_tty (session, x_server_get_address (X_SERVER (display_server))); |