Author: pebender
Date: Fri Sep 5 21:00:19 2008
New Revision: 3704
Modified:
trunk/gar-minimyth/html/minimyth/document-changelog.txt
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_sleep
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_sleep_on_ss
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_ss_suspend
Log:
- Converted mm_ss_suspend and mm_sleep_on_ss to perl.
- Converted mm_sleep to use MiniMyth::x_screensaver_deactivate.
Modified: trunk/gar-minimyth/html/minimyth/document-changelog.txt
==============================================================================
--- trunk/gar-minimyth/html/minimyth/document-changelog.txt (original)
+++ trunk/gar-minimyth/html/minimyth/document-changelog.txt Fri Sep 5
21:00:19 2008
@@ -1,7 +1,7 @@
MiniMyth Changelog
--------------------------------------------------------------------------------
-Changes since 57 (2008-09-03):
+Changes since 57 (2008-09-05):
Current MythTV versions
MythTV 0.21: version 0.21.0, release-0-21-fixes branch svn 18228.
@@ -26,6 +26,8 @@
mm_game_exit
mm_game_start
mm_sleep
+ mm_sleep_on_ss
+ mm_ss_suspend
mm_term_exit
mm_term_start
- Converted web page CGI scripts to perl.
Modified:
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_sleep
==============================================================================
---
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_sleep
(original)
+++
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_sleep
Fri Sep 5 21:00:19 2008
@@ -5,10 +5,13 @@
require File::Basename;
require File::Path;
+require File::Spec;
require MiniMyth;
my $minimyth = new MiniMyth;
+my $devnull = File::Spec->devnull;
+
# Only allow one running instance of mm_sleep.
my @pids = $minimyth->application_pids(File::Basename::basename(__FILE__));
if ($#pids > 0)
@@ -70,6 +73,9 @@
{
$minimyth->x_start();
}
+
+# Deactivate any screensavers.
+$minimyth->x_screensaver_deactivate();
# If mm_sleep_on_ss was running before suspend, then restart it.
if (-e "/var/lib/mm_sleep.$$/mm_sleep_on_ss")
Modified:
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_sleep_on_ss
==============================================================================
---
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_sleep_on_ss
(original)
+++
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_sleep_on_ss
Fri Sep 5 21:00:19 2008
@@ -1,51 +1,126 @@
-#!/bin/sh
+#!/usr/bin/perl
-. /etc/rc.d/functions
+use strict;
+use warnings;
-trap "_exit_" 0 1 2 3 15
+require File::Spec;
+require MiniMyth;
-_exit_()
+my $minimyth = new MiniMyth;
+
+my $devnull = File::Spec->devnull;
+
+$SIG{'HUP'} = \&clean_up;
+$SIG{'INT'} = \&clean_up;
+$SIG{'QUIT'} = \&clean_up;
+$SIG{'TERM'} = \&clean_up;
+
+END
+{
+ clean_up();
+}
+
+sub clean_up
{
- ps -o ppid,pid,args \
- | sed -e 's% *% %g' -e 's%^ %%' -e 's% $%%' \
- | grep "^$$ " \
- | grep '/bin/sleep [^ ]*$' \
- | cut -d ' ' -f 2 \
- | while read pid ; do
- kill $pid
- done
-
- ps -o ppid,pid,args \
- | sed -e 's% *% %g' -e 's%^ %%' -e 's% $%%' \
- | grep "^$$ " \
- | grep '/usr/bin/xscreensaver-command -watch$' \
- | cut -d ' ' -f 2 \
- | while read pid ; do
- kill $pid
- done
+ # Use the ps command to list information needed about each process.
+ my $ps_command = undef;
+ if (open($ps_command, '-|', '/bin/ps ax -o ppid,pid,args'))
+ {
+ # Create two hashes: one containing each PID's parent PID and one
containing each PID's arguments.
+ # We will use these hashes to locate the process(es) spawned by
this script that we need to kill.
+ my %ppid_hash = ();
+ my %args_hash = ();
+ while (<$ps_command>)
+ {
+ chomp;
+ if (/^ *(\d+) +(\d+) +(.+) *$/)
+ {
+ $ppid_hash{$2} = $1;
+ $args_hash{$2} = $3;
+ }
+ }
+ close($ps_command);
+ $ps_command = undef;
+
+ # Find the xscreensaver watch command that was spawned by this
script and kill it.
+ # This will enable the script to terminate more cleanly.
+ foreach my $pid (keys %args_hash)
+ {
+ if ($args_hash{$pid} eq '/usr/bin/xscreensaver-command -watch')
+ {
+ my $ppid = $pid;
+ while ((exists($ppid_hash{$ppid})) && ($ppid != 0) &&
($ppid != $$))
+ {
+ $ppid = $ppid_hash{$ppid};
+ }
+ if ($ppid eq $$)
+ {
+ system(qq(/bin/kill $pid));
+ }
+ }
+ }
+ }
}
-if /usr/bin/test `/usr/bin/id -u` -ne 0 ; then
- exit 1
-fi
-
-/bin/sleep 10
-if /usr/bin/test -n "`/bin/pidof xscreensaver`" ; then
- /usr/bin/xscreensaver-command -deactivate > /dev/null 2>&1
- /usr/bin/xscreensaver-command -watch 2> /dev/null | while read watch ;
do
- state=`/bin/echo ${watch} | /bin/sed -e 's% *% %g' | /usr/bin/cut
-d ' ' -f 1`
- if /usr/bin/test "${state}" = "BLANK" ; then
- # Do not sleep when in MythMusic or MythStream.
- mythfrontend_location=`mm_mythfrontend_networkcontrol "query
location"`
- if /usr/bin/test ! "${mythfrontend_location}" = "playmusic"
&& \
- /usr/bin/test ! "${mythfrontend_location}" = "mythstream" ;
then
- /usr/bin/mm_sleep
- if /usr/bin/test -n "`/bin/pidof xscreensaver`" ; then
- /usr/bin/xscreensaver-command -deactivate > /dev/null
2>&1
- fi
- fi
- fi
- done
-fi
+# Make sure we are root.
+{
+ my $user = '';
+ if (open(FILE, '-|', '/usr/bin/id -u'))
+ {
+ while (<FILE>)
+ {
+ chomp;
+ $user = getpwuid($_);
+ last;
+ }
+ close(FILE);
+ }
+ if ($user ne 'root')
+ {
+ die;
+ }
+}
+
+# Sleep in order to give xscreensaver time to start. What a hack.
+sleep 10;
+
+if ($minimyth->application_running('xscreensaver'))
+{
+ # Deactivate the xscreensaver in case it has already activated.
+ # Otherwise, we would miss the transition to blank and never sleep.
+ $minimyth->x_screensaver_deactivate();
+
+ # Use the xscreensaver watch command to watch for when xscreensaver
goes blank.
+ # When the xscreensaver goes blank, go to sleep unless MythMusic or
MythStream are running.
+ my $watch_command = undef;
+ if (open($watch_command, '-|', qq(/usr/bin/xscreensaver-command -watch
2> $devnull)))
+ {
+ while (<$watch_command>)
+ {
+ my $state = '';
+ if (/^([^ ]+) +.*$/)
+ {
+ $state = $1;
+ }
+ if ($state eq 'BLANK')
+ {
+ # Do not sleep when in MythMusic or MythStream.
+ my $mythfrontend_location = join("\n",
@{$minimyth->mythfrontend_networkcontrol('query location')});
+ if (($mythfrontend_location ne 'playmusic' ) &&
+ ($mythfrontend_location ne 'mythstream'))
+ {
+ system(qq(/usr/bin/mm_sleep));
+ if ($minimyth->application_running('xscreensaver'))
+ {
+ # Deactivate the xscreensaver so that we can start
all over again.
+ $minimyth->x_screensaver_deactivate();
+ }
+ }
+ }
+ }
+ close($watch_command);
+ $watch_command = undef;
+ }
+}
-exit 0
+1;
Modified:
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_ss_suspend
==============================================================================
---
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_ss_suspend
(original)
+++
trunk/gar-minimyth/script/meta/minimyth/files/source/rootfs/usr/bin/mm_ss_suspend
Fri Sep 5 21:00:19 2008
@@ -1,27 +1,18 @@
-#!/bin/sh
+#!/usr/bin/perl
-trap "_exit_" 0 1 2 3 15
+use strict;
+use warnings;
-_exit_()
-{
- ps -o ppid,pid,args \
- | sed -e 's% *% %g' -e 's%^ %%' -e 's% $%%' \
- | grep "^$$ " \
- | grep '/bin/sleep [^ ]*$' \
- | cut -d ' ' -f 2 \
- | while read pid ; do
- kill $pid
- done
-}
+require MiniMyth;
+
+my $program = shift;
-program=$1
+my $minimyth = new MiniMyth;
-while /usr/bin/test -n "`/bin/pidof ${program}`" ; do
- /usr/bin/xset s reset
- if /usr/bin/test -n "`/bin/pidof xscreensaver`" ; then
- /usr/bin/xscreensaver-command -deactivate
- fi
- /bin/sleep 30
-done
+while ($minimyth->application_running($program))
+{
+ $minimyth->x_screensaver_deactivate();
+ sleep 30;
+}
-exit 0
+1;
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"minimyth-commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/minimyth-commits?hl=en
-~----------~----~----~----~------~----~------~--~---