With Kernel 2.6.26.32-rc6 suspend-2-ram (aka sleep/standby) finally works on my machine! However OSSv4 does not support suspend/hibernate which means that OSS must be unloaded.
This scripts does the following:
- Stop/Start specific Daemons
- Stop/Starts specific Programs
- Informs you of any programs that are preventing OSS from unloading
In my case I have the script stop mpd. Then it kills ossxmix and attempts to unload oss. On spawn it starts mpd again and loads ossxmix.
Here it is:
oss_s.py
#!/usr/bin/env python
import subprocess
import sys
import os
#Daemons that need to be stopped
daemons=('mpd',)
#Programs that are safe to kill
kill_apps=('ossxmix','vlc','mplayer','xine','xmms','audacious',)
#Programs to load on spawn/resume
load_apps=('ossxmix -xb',)
#User to start apps as
user='pyther'
def start():
p=subprocess.Popen(['soundon'])
p.wait()
for d in daemons:
p=subprocess.Popen(['/etc/rc.d/' + d, 'start'])
p.wait()
for a in load_apps:
#Load the program as a user, not root
os.system('sudo su -c \'' + a + ' &\' ' + user)
return
def stop():
for d in daemons:
p=subprocess.Popen(['/etc/rc.d/' + d, 'stop'])
p.wait()
for a in kill_apps:
p=subprocess.Popen(['killall',a])
p.wait()
o=subprocess.Popen(['soundoff'],stdout=subprocess.PIPE)
output=o.stdout.readlines()
list=[]
for line in output:
#If the line is empty skip it
line = line.rstrip("\n")
if line == '':
pass
#Otherwise lets split the line by spaces
else:
line=line.rsplit(' ')
#Going to see if the first word is an int
try:
pid=int(line[0])
except ValueError:
#Must not be an int
pass
#Good it is an int... lets continue
else:
app=line[1] #The second word is the name of the app
#If the list has no values, we will add the first running program
if len(list) == 0:
list.append([pid,app])
#Now lets check and see if the pid is already in the list
else:
inList=0 #Set to False by default
#Scanning items already in the list
#If we find a match we set inList to True and break out of the loop
for x in list:
if int(x[0]) == int(pid):
inList=1
break
if not inList:
list.append([pid,app])
if list:
print("Apps that need to be killed:")
for x in list:
pid=x[0]
app=x[1]
subprocess.Popen(['notify-send', '-u', 'normal', '-i', 'audio-card', '-t', '120000', 'PID: ' + str(pid) + ' is using OSS', str(pid) + ' - ' + app + '\nPlease kill this application.' ])
print("PID: " + str(pid) + " - " + app)
#Exit abnormally
sys.exit(1)
return
if __name__ == "__main__":
if len(sys.argv) <= 1:
print("Usage: start or stop")
sys.exit(1)
if os.geteuid() != 0:
print "You must be root to run this script."
sys.exit(1)
if sys.argv[1] == "start":
start()
elif sys.argv[1] == "stop":
stop()
else:
print "Usage: start or stop"
Usage is simple enough:
./oss_s.py start
./oss_s.py stop
Then to get the script to run on suspend/wake:
Save this as /etc/pm/sleep.d/48oss
#!/bin/bash
case $1 in
hibernate)
/home/pyther/bin/oss_s.py stop
;;
suspend)
/home/pyther/bin/oss_s.py stop
;;
thaw)
/home/pyther/bin/oss_s.py start
;;
resume)
/home/pyther/bin/oss_s.py start
;;
esac
Then make it executable
chmod +x /etc/pm/sleep.d/48oss
Of course you will have to modify the code as necessary.
Leave a Reply