8 my $idle_want=$ARGV[0] || 30;
9 die if @ARGV>1 || $idle_want!~/^\d+$/;
14 # Users respected for the 'idle' state (see $IdleMax):
15 my @ValidUsers=qw(root lace jkratoch);
19 my %valid_users=map(($_=>1),@ValidUsers);
20 my($idlebest,$linebest);
21 for my $utmp (User::Utmp::getut()) {
23 next if defined($_=$utmp->{"ut_type"}) && $_!=&User::Utmp::USER_PROCESS();
24 next if defined($_=$utmp->{"ut_user"}) && !$valid_users{$_};
25 next if $utmp->{"ut_line"}=~m{^:\d+}; # X login
26 my $line="/dev/".$utmp->{"ut_line"};
27 my $atime=(stat $line)[8];
28 my $what="user \"".($utmp->{"ut_user"} || "<local>")."\", line \"$line\"";
29 warn "Unable to stat $what" and next if !$atime;
30 my $idle=time()-$atime;
31 warn "atime in future for $what" and next if $idle<0;
32 next if defined $idlebest && $idlebest<=$idle;
36 return !wantarray() ? $idlebest : ($idlebest,$linebest);
42 open F,"/proc/net/unix" or die;
47 /^(?:\S+\s+){6}(\d+)\s/ or die;
53 while (</proc/*/exe>) {
54 (my $fdname=$_)=~s{/exe$}{/fd};
59 my $inode=/^\Qsocket:[\E(\d+)\Q]\E$/ or next;
60 return 1 if $unix{$1};
68 my $idle_is=useridle();
69 if ($idle_is>=$idle_want) {
70 if (!mplayer_running()) {
78 sleep $idle_want-$idle_is;