From f4702f7a0ca670b3cc4ac289749d420f85dd34f7 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 17 Mar 2005 14:31:55 +0000 Subject: add monitor-probe and monitor-probe-using-X --- monitor-probe-using-X | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100755 monitor-probe-using-X (limited to 'monitor-probe-using-X') diff --git a/monitor-probe-using-X b/monitor-probe-using-X new file mode 100755 index 0000000..6e4fdea --- /dev/null +++ b/monitor-probe-using-X @@ -0,0 +1,133 @@ +#!/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, <