#!/usr/bin/perl my ($arg) = @ARGV; @ARGV == 1 && $arg !~ /^-/ or die "usage: monitor-probe-using-X \n"; my $log; if (-e $arg) { #- it is a log file $log = cat_($arg); parse_X_log($log); } else { my $Driver = $arg; $log = probe_using_X($Driver) or warn("X probe failed\n"), exit 1; my $ok = parse_X_log($log); if ($ENV{DEBUG}) { my $log_file = "/tmp/Xorg.log.$Driver"; output($log_file, $log); warn "\n", "Saving log in $log_file.\n", $ok ? "If the detected resolution is wrong" : "If it contains interesting information", ", send $log_file to pixel\@mandrakesoft.com\n\n"; } $ok or warn "Could not find a resolution\n"; } sub cat_ { open(my $F, $_[0]) or return; my @l = <$F>; wantarray() ? @l : join '', @l } sub output { my $f = shift; open(my $F, ">$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; 1 } sub tmpfile() { chomp(my $s = `mktemp /tmp/tmp.XXXXXXXXXX`); #- we could use simply mktemp with new mktemp eval "END { unlink '$s' }"; $s; } sub chvt { my ($vt_number) = @_; my $vt = ''; my ($VT_GETSTATE, $VT_ACTIVATE, $VT_WAITACTIVE) = (0x5603, 0x5606, 0x5607); sysopen(my $C, "/dev/console", 2) or die "failed to open /dev/console: $!"; ioctl($C, $VT_GETSTATE, $vt) && ioctl($C, $VT_ACTIVATE, $vt_number) && ioctl($C, $VT_WAITACTIVE, $vt_number) or die "setVirtual failed"; unpack "S", $vt; } sub probe_using_X { my ($Driver) = @_; my $tmp_conf = tmpfile(); my $tmp_log = tmpfile(); output($tmp_conf, <