Back to index

lightdm  1.3.2
seat-xlocal.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010-2011 Robert Ancell.
00003  * Author: Robert Ancell <robert.ancell@canonical.com>
00004  * 
00005  * This program is free software: you can redistribute it and/or modify it under
00006  * the terms of the GNU General Public License as published by the Free Software
00007  * Foundation, either version 3 of the License, or (at your option) any later
00008  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
00009  * license.
00010  */
00011 
00012 #include <string.h>
00013 
00014 #include "seat-xlocal.h"
00015 #include "configuration.h"
00016 #include "xserver-local.h"
00017 #include "xsession.h"
00018 #include "vt.h"
00019 
00020 G_DEFINE_TYPE (SeatXLocal, seat_xlocal, SEAT_TYPE);
00021 
00022 static void
00023 seat_xlocal_setup (Seat *seat)
00024 {
00025     seat_set_can_switch (seat, TRUE);
00026     SEAT_CLASS (seat_xlocal_parent_class)->setup (seat);
00027 }
00028 
00029 static DisplayServer *
00030 seat_xlocal_create_display_server (Seat *seat)
00031 {
00032     XServerLocal *xserver;
00033     const gchar *command = NULL, *layout = NULL, *config_file = NULL, *xdmcp_manager = NULL, *key_name = NULL;
00034     gboolean allow_tcp;
00035     gint port = 0;
00036 
00037     g_debug ("Starting local X display");
00038   
00039     xserver = xserver_local_new ();
00040 
00041     /* If running inside an X server use Xephyr instead */
00042     if (g_getenv ("DISPLAY"))
00043         command = "Xephyr";
00044     if (!command)
00045         command = seat_get_string_property (seat, "xserver-command");
00046     if (command)
00047         xserver_local_set_command (xserver, command);
00048 
00049     layout = seat_get_string_property (seat, "xserver-layout");
00050     if (layout)
00051         xserver_local_set_layout (xserver, layout);
00052 
00053     config_file = seat_get_string_property (seat, "xserver-config");
00054     if (config_file)
00055         xserver_local_set_config (xserver, config_file);
00056   
00057     allow_tcp = seat_get_boolean_property (seat, "xserver-allow-tcp");
00058     xserver_local_set_allow_tcp (xserver, allow_tcp);    
00059 
00060     xdmcp_manager = seat_get_string_property (seat, "xdmcp-manager");
00061     if (xdmcp_manager)
00062         xserver_local_set_xdmcp_server (xserver, xdmcp_manager);
00063 
00064     port = seat_get_integer_property (seat, "xdmcp-port");
00065     if (port > 0)
00066         xserver_local_set_xdmcp_port (xserver, port);
00067 
00068     key_name = seat_get_string_property (seat, "xdmcp-key");
00069     if (key_name)
00070     {
00071         gchar *dir, *path;
00072         GKeyFile *keys;
00073         gboolean result;
00074         GError *error = NULL;
00075 
00076         dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
00077         path = g_build_filename (dir, "keys.conf", NULL);
00078         g_free (dir);
00079 
00080         keys = g_key_file_new ();
00081         result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
00082         if (error)
00083             g_debug ("Error getting key %s", error->message);
00084         g_clear_error (&error);      
00085 
00086         if (result)
00087         {
00088             gchar *key = NULL;
00089 
00090             if (g_key_file_has_key (keys, "keyring", key_name, NULL))
00091                 key = g_key_file_get_string (keys, "keyring", key_name, NULL);
00092             else
00093                 g_debug ("Key %s not defined", key_name);
00094 
00095             if (key)
00096                 xserver_local_set_xdmcp_key (xserver, key);
00097             g_free (key);
00098         }
00099 
00100         g_free (path);
00101         g_key_file_free (keys);
00102     }
00103 
00104     return DISPLAY_SERVER (xserver);
00105 }
00106 
00107 static Session *
00108 seat_xlocal_create_session (Seat *seat, Display *display)
00109 {
00110     XServerLocal *xserver;
00111     XSession *session;
00112     gchar *tty;
00113 
00114     xserver = XSERVER_LOCAL (display_get_display_server (display));
00115 
00116     session = xsession_new (XSERVER (xserver));
00117     tty = g_strdup_printf ("/dev/tty%d", xserver_local_get_vt (xserver));
00118     session_set_tty (SESSION (session), tty);
00119     g_free (tty);
00120 
00121     return SESSION (session);
00122 }
00123 
00124 static void
00125 seat_xlocal_set_active_display (Seat *seat, Display *display)
00126 {
00127     gint number = xserver_local_get_vt (XSERVER_LOCAL (XSERVER (display_get_display_server (display))));
00128     if (number >= 0)
00129         vt_set_active (number);
00130 
00131     SEAT_CLASS (seat_xlocal_parent_class)->set_active_display (seat, display);
00132 }
00133 
00134 static void
00135 seat_xlocal_run_script (Seat *seat, Display *display, Process *script)
00136 {
00137     gchar *path;
00138     XServerLocal *xserver;
00139 
00140     xserver = XSERVER_LOCAL (display_get_display_server (display));
00141     path = xserver_local_get_authority_file_path (xserver);
00142     process_set_env (script, "DISPLAY", xserver_get_address (XSERVER (xserver)));
00143     process_set_env (script, "XAUTHORITY", path);
00144     g_free (path);
00145 
00146     SEAT_CLASS (seat_xlocal_parent_class)->run_script (seat, display, script);
00147 }
00148 
00149 static void
00150 seat_xlocal_display_removed (Seat *seat, Display *display)
00151 {
00152     if (seat_get_is_stopping (seat))
00153         return;
00154 
00155     /* If this is the only display and it failed to start then stop this seat */
00156     if (g_list_length (seat_get_displays (seat)) == 0 && !display_get_is_ready (display))
00157     {
00158         g_debug ("Stopping X local seat, failed to start a display");
00159         seat_stop (seat);
00160         return;
00161     }
00162 
00163     /* Show a new greeter */  
00164     if (display == seat_get_active_display (seat))
00165     {
00166         g_debug ("Active display stopped, switching to greeter");
00167         seat_switch_to_greeter (seat);
00168     }
00169 }
00170 
00171 static void
00172 seat_xlocal_init (SeatXLocal *seat)
00173 {
00174 }
00175 
00176 static void
00177 seat_xlocal_class_init (SeatXLocalClass *klass)
00178 {
00179     SeatClass *seat_class = SEAT_CLASS (klass);
00180 
00181     seat_class->setup = seat_xlocal_setup;
00182     seat_class->create_display_server = seat_xlocal_create_display_server;
00183     seat_class->create_session = seat_xlocal_create_session;
00184     seat_class->set_active_display = seat_xlocal_set_active_display;
00185     seat_class->run_script = seat_xlocal_run_script;
00186     seat_class->display_removed = seat_xlocal_display_removed;
00187 }