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/tty0", O_RDONLY | O_NOCTTY, 0);
35 g_warning ("Error opening /dev/tty0: %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 return access ("/dev/tty0", F_OK) == 0 &&
46 access ("/sys/class/tty/tty0/active", F_OK) == 0;
56 /* Pretend always active */
63 struct vt_stat vt_state = { 0 };
64 if (ioctl (tty_fd, VT_GETSTATE, &vt_state) < 0)
65 g_warning ("Error using VT_GETSTATE on /dev/tty0: %s", strerror (errno));
67 active = vt_state.v_active;
78 vt_set_active (gint number)
83 g_debug ("Activating VT %d", number);
85 /* Pretend always active */
94 if (ioctl (tty_fd, VT_ACTIVATE, n) < 0)
95 g_warning ("Error using VT_ACTIVATE %d on /dev/tty0: %s", n, strerror (errno));
97 /* Wait for the VT to become active to avoid a suspected
98 * race condition somewhere between LightDM, X, ConsoleKit and the kernel.
99 * See https://bugs.launchpad.net/bugs/851612 */
100 if (ioctl (tty_fd, VT_WAITACTIVE) < 0)
101 g_warning ("Error using VT_WAITACTIVE %d on /dev/tty0: %s", n, strerror (errno));
109 vt_is_used (gint number)
113 for (link = used_vts; link; link = link->next)
115 int n = GPOINTER_TO_INT (link->data);
128 number = config_get_integer (config_get_instance (), "LightDM", "minimum-vt");
143 number = vt_get_min ();
144 while (vt_is_used (number))
153 g_debug ("Using VT %d", number);
154 used_vts = g_list_append (used_vts, GINT_TO_POINTER (number));
158 vt_unref (gint number)
160 g_debug ("Releasing VT %d", number);
161 used_vts = g_list_remove (used_vts, GINT_TO_POINTER (number));