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));
46 /* Pretend always active */
50 console_fd = open_console ();
53 struct vt_stat console_state = { 0 };
54 if (ioctl (console_fd, VT_GETSTATE, &console_state) < 0)
55 g_warning ("Error using VT_GETSTATE on /dev/console: %s", strerror (errno));
57 active = console_state.v_active;
68 vt_set_active (gint number)
73 g_debug ("Activating VT %d", number);
75 /* Pretend always active */
79 console_fd = open_console ();
84 if (ioctl (console_fd, VT_ACTIVATE, n) < 0)
85 g_warning ("Error using VT_ACTIVATE %d on /dev/console: %s", n, strerror (errno));
87 /* Wait for the VT to become active to avoid a suspected
88 * race condition somewhere between LightDM, X, ConsoleKit and the kernel.
89 * See https://bugs.launchpad.net/bugs/851612 */
90 if (ioctl (console_fd, VT_WAITACTIVE) < 0)
91 g_warning ("Error using VT_WAITACTIVE %d on /dev/console: %s", n, strerror (errno));
99 vt_is_used (gint number)
103 for (link = used_vts; link; link = link->next)
105 int n = GPOINTER_TO_INT (link->data);
118 number = config_get_integer (config_get_instance (), "LightDM", "minimum-vt");
133 number = vt_get_min ();
134 while (vt_is_used (number))
143 g_debug ("Using VT %d", number);
144 used_vts = g_list_append (used_vts, GINT_TO_POINTER (number));
148 vt_unref (gint number)
150 g_debug ("Releasing VT %d", number);
151 used_vts = g_list_remove (used_vts, GINT_TO_POINTER (number));