2 * Copyright (C) 2010-2011 Robert Ancell.
3 * Author: Robert Ancell <robert.ancell@canonical.com>
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later
8 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
15 #include <glib/gstdio.h>
18 #include <sys/ioctl.h>
24 #include "configuration.h"
26 static GList *used_vts = NULL;
33 fd = g_open ("/dev/console", O_RDONLY | O_NOCTTY, 0);
35 g_warning ("Error opening /dev/console: %s", strerror (errno));
40 vt_can_multi_seat (void)
42 /* Quick check to see if we can multi seat. This is intentionally the
43 same check logind does, just without actually reading from the files.
44 Existence will prove whether we have CONFIG_VT built into the kernel.
45 (Reading /dev/console like the rest of the code in this file isn't
46 sufficient -- it may still exist if tty0 doesn't and it may not work
47 in situations where tty0 does exist and thus logind will think we are
49 return access ("/dev/tty0", F_OK) == 0 &&
50 access ("/sys/class/tty/tty0/active", F_OK) == 0;
60 /* Pretend always active */
64 console_fd = open_console ();
67 struct vt_stat console_state = { 0 };
68 if (ioctl (console_fd, VT_GETSTATE, &console_state) < 0)
69 g_warning ("Error using VT_GETSTATE on /dev/console: %s", strerror (errno));
71 active = console_state.v_active;
82 vt_set_active (gint number)
87 g_debug ("Activating VT %d", number);
89 /* Pretend always active */
93 console_fd = open_console ();
98 if (ioctl (console_fd, VT_ACTIVATE, n) < 0)
99 g_warning ("Error using VT_ACTIVATE %d on /dev/console: %s", n, strerror (errno));
101 /* Wait for the VT to become active to avoid a suspected
102 * race condition somewhere between LightDM, X, ConsoleKit and the kernel.
103 * See https://bugs.launchpad.net/bugs/851612 */
104 if (ioctl (console_fd, VT_WAITACTIVE) < 0)
105 g_warning ("Error using VT_WAITACTIVE %d on /dev/console: %s", n, strerror (errno));
113 vt_is_used (gint number)
117 for (link = used_vts; link; link = link->next)
119 int n = GPOINTER_TO_INT (link->data);
132 number = config_get_integer (config_get_instance (), "LightDM", "minimum-vt");
147 number = vt_get_min ();
148 while (vt_is_used (number))
157 g_debug ("Using VT %d", number);
158 used_vts = g_list_append (used_vts, GINT_TO_POINTER (number));
162 vt_unref (gint number)
164 g_debug ("Releasing VT %d", number);
165 used_vts = g_list_remove (used_vts, GINT_TO_POINTER (number));