#!/bin/perl

#
# delete all Xorg that have a display higher than 5.  Log all the users
# upon reboot and never log them out (see ER below)
# intended to get rid of leaked display from GDM on fedora 17
# see bug https://bugzilla.redhat.com/show_bug.cgi?id=751641
#
# ER:  actually hunt down live users and delete Xorgs that don't have any
use Scalar::Util qw(looks_like_number);


@result = `ps -ef | grep /usr/bin/Xorg`;
foreach (@result) {
    @columns = split( /\s+/, $_);
    $displayNum = substr($columns[8],1);
    if (looks_like_number($displayNum)) {
	if ($displayNum > "5") {
	   print $displayNum . "DISPLAY TO KILL\n";
	   $killcommand  = "/home/patrice/killtree.sh ". $columns[2]." KILL";
	   system($killcommand);
        }
    } else {
    }
}

