#!/usr/bin/perl -w use strict; my $path_ck_list_sessions = '/usr/bin/ck-list-sessions'; my $path_fgconsole = '/bin/fgconsole'; my $path_chvt = '/bin/chvt'; my $path_logger = '/usr/bin/logger'; my $current_vt = `$path_fgconsole`; chop $current_vt; my $session_list = `$path_ck_list_sessions`; $session_list =~ s/\n//g; my @sessions = split /Session\d+:/, $session_list; my $best_choice = ''; foreach my $session ( @sessions ) { next if !$session; my $vt = ''; my $type = ''; $session =~ /session-type = '([^']*)'/; $type = $1; $session =~ /x11-display-device = '([^']+)'/; $vt = $1; if( $vt eq "/dev/tty$current_vt" ) { exit 0; } if( ! $best_choice ) { $best_choice = $vt; } else { if( $type eq 'LoginWindow' ) { $best_choice = $vt; } } } my $new_vt = $best_choice; $new_vt =~ s#^/dev/tty##; system($path_logger,'-p','notice','-t','gdm-fixer' ,"VT $current_vt not active. Switching to VT $new_vt."); system($path_chvt,$new_vt); exit;