Back to index

lightdm  1.3.2
Functions | Variables
vt.c File Reference
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <glib/gstdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "vt.h"
#include "configuration.h"

Go to the source code of this file.

Functions

static gint open_console (void)
gint vt_get_active (void)
void vt_set_active (gint number)
static gboolean vt_is_used (gint number)
gint vt_get_min (void)
gint vt_get_unused (void)
void vt_ref (gint number)
void vt_unref (gint number)

Variables

static GList * used_vts = NULL

Function Documentation

static gint open_console ( void  ) [static]

Definition at line 29 of file vt.c.

{
    int fd;

    fd = g_open ("/dev/console", O_RDONLY | O_NOCTTY, 0);
    if (fd < 0)
        g_warning ("Error opening /dev/console: %s", strerror (errno));
    return fd;
}

Here is the caller graph for this function:

gint vt_get_active ( void  )

Definition at line 40 of file vt.c.

{
#ifdef __linux__
    gint console_fd;
    gint active = -1;

    /* Pretend always active */
    if (getuid () != 0)
        return 1;

    console_fd = open_console ();
    if (console_fd >= 0)
    {
        struct vt_stat console_state = { 0 };
        if (ioctl (console_fd, VT_GETSTATE, &console_state) < 0)
            g_warning ("Error using VT_GETSTATE on /dev/console: %s", strerror (errno));
        else
            active = console_state.v_active;
        close (console_fd);
    }

    return active;
#else
    return -1;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

gint vt_get_min ( void  )

Definition at line 114 of file vt.c.

{
    gint number;

    number = config_get_integer (config_get_instance (), "LightDM", "minimum-vt");
    if (number < 1)
        number = 1;

    return number;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gint vt_get_unused ( void  )

Definition at line 126 of file vt.c.

{
    gint number;

    if (getuid () != 0)
        return -1;

    number = vt_get_min ();
    while (vt_is_used (number))
        number++;
 
    return number;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean vt_is_used ( gint  number) [static]

Definition at line 99 of file vt.c.

{
    GList *link;

    for (link = used_vts; link; link = link->next)
    {
        int n = GPOINTER_TO_INT (link->data);
        if (n == number)
            return TRUE;
    }

    return FALSE;
}

Here is the caller graph for this function:

void vt_ref ( gint  number)

Definition at line 141 of file vt.c.

{
    g_debug ("Using VT %d", number);
    used_vts = g_list_append (used_vts, GINT_TO_POINTER (number)); 
}

Here is the caller graph for this function:

void vt_set_active ( gint  number)

Definition at line 68 of file vt.c.

{
#ifdef __linux__
    gint console_fd;

    g_debug ("Activating VT %d", number);

    /* Pretend always active */
    if (getuid () != 0)
        return;   

    console_fd = open_console ();
    if (console_fd >= 0)
    {
        int n = number;

        if (ioctl (console_fd, VT_ACTIVATE, n) < 0)
            g_warning ("Error using VT_ACTIVATE %d on /dev/console: %s", n, strerror (errno));

        /* Wait for the VT to become active to avoid a suspected
         * race condition somewhere between LightDM, X, ConsoleKit and the kernel.
         * See https://bugs.launchpad.net/bugs/851612 */
        if (ioctl (console_fd, VT_WAITACTIVE) < 0)
            g_warning ("Error using VT_WAITACTIVE %d on /dev/console: %s", n, strerror (errno));

        close (console_fd);
    }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void vt_unref ( gint  number)

Definition at line 148 of file vt.c.

{
    g_debug ("Releasing VT %d", number);
    used_vts = g_list_remove (used_vts, GINT_TO_POINTER (number));
}

Here is the caller graph for this function:


Variable Documentation

GList* used_vts = NULL [static]

Definition at line 26 of file vt.c.