fix_terminal_vt_mode (GdmSessionWorker  *worker,
                      int                tty_fd)
{
        struct vt_mode getmode_reply = { 0 };
        int kernel_display_mode = 0;
        gboolean mode_fixed = FALSE;
        gboolean succeeded = TRUE;

        if (ioctl (tty_fd, VT_GETMODE, &getmode_reply) < 0) {
                g_debug ("GdmSessionWorker: couldn't query VT mode: %m");
                succeeded = FALSE;
        }

        if (getmode_reply.mode != VT_AUTO) {
                goto out;
        }

        if (ioctl (tty_fd, KDGETMODE, &kernel_display_mode) < 0) {
                g_debug ("GdmSessionWorker: couldn't query kernel display mode: %m");
                succeeded = FALSE;
        }

        if (kernel_display_mode == KD_TEXT) {
                goto out;
        }

        /* VT is in the anti-social state of VT_AUTO + KD_GRAPHICS,
         * fix it.
         */
        succeeded = handle_terminal_vt_switches (worker, tty_fd);
        mode_fixed = TRUE;
out:
        if (!succeeded) {
                g_error ("GdmSessionWorker: couldn't set up terminal, aborting...");
                return;
        }

        g_debug ("GdmSessionWorker: VT mode did %sneed to be fixed",
                 mode_fixed? "" : "not ");
}
fix_terminal_vt_mode (GdmSessionWorker  *worker,
                      int                tty_fd)
{
        struct vt_mode getmode_reply = { 0 };
        int kernel_display_mode = 0;
        gboolean mode_fixed = FALSE;
        gboolean succeeded = TRUE;

        if (ioctl (tty_fd, VT_GETMODE, &getmode_reply) < 0) {
                g_debug ("GdmSessionWorker: couldn't query VT mode: %m");
                succeeded = FALSE;
        }

        if (getmode_reply.mode != VT_AUTO) {
                goto out;
        }

        if (ioctl (tty_fd, KDGETMODE, &kernel_display_mode) < 0) {
                g_debug ("GdmSessionWorker: couldn't query kernel display mode: %m");
                succeeded = FALSE;
        }

        if (kernel_display_mode == KD_TEXT) {
                goto out;
        }

         
        succeeded = handle_terminal_vt_switches (worker, tty_fd);
        mode_fixed = TRUE;
out:
        if (!succeeded) {
                g_error ("GdmSessionWorker: couldn't set up terminal, aborting...");
                return;
        }

        g_debug ("GdmSessionWorker: VT mode did %sneed to be fixed",
                 mode_fixed? "" : "not ");
}