2013-06-06, 06:06
[ Background ]
I'm borrowing and mangling the SteamLauncher add-on from teeedubb, to suit my own XBMC/Steam setup.
I have a Perl script that forks X, then on a loop checks for the existence of /home/mediacenter/.xbmc/steam-run. If that file doesn't exist, XBMC is started on the X server that was previously spawned. This is set up to respawn on tty1 in inittab, so that if anything (other than launching Steam) kills either XBMC or X it will respawn quickly.
Then, from the SteamLauncher add-on, I fire a bash script that touches /home/mediacenter/.xbmc/steam-run, kills XBMC, and launches Steam:
[ Problem Description ]
If I call default.py from XBMC, Steam's setup scripts are unable to execute some of their steps. This causes issues in path setup, and Steam ends up trying to write to /steamapps instead of $HOME/.local/share/Steam/SteamApps/
If I call default.py from the command line, Steam launches normally - the .steam_exec_test.sh test succeeds, and game data is written to the correct location.
How can I call my script properly from XBMC, to avoid this "No child processes" error?
I'm borrowing and mangling the SteamLauncher add-on from teeedubb, to suit my own XBMC/Steam setup.
I have a Perl script that forks X, then on a loop checks for the existence of /home/mediacenter/.xbmc/steam-run. If that file doesn't exist, XBMC is started on the X server that was previously spawned. This is set up to respawn on tty1 in inittab, so that if anything (other than launching Steam) kills either XBMC or X it will respawn quickly.
Code:
#!/usr/bin/perl
# startxbmc
use strict;
use warnings;
my($myDisplay,$myUser,$pid) = (0,"mediacenter");
my @xLocks = </tmp/.X*-lock>;
if ( @xLocks ) {
$xLocks[$#xLocks] =~ /.X(\d)/;
$myDisplay = $1;
$myDisplay++;
print "Locks exist. myDisplay = " . $myDisplay . "\n";
} else {
$myDisplay = 0;
print "No locks exist. myDisplay = " . $myDisplay . "\n";
}
my $xCommand = "/bin/su - " . $myUser . " --command X :" . $myDisplay . " >/dev/null 2>&1";
my $xbmcCommand = "DISPLAY=:" . $myDisplay . " /bin/su - $myUser --command xbmc";
unless ($pid = fork) {
unless (fork) {
exec $xCommand;
die "exec failed!";
}
exit 0;
}
waitpid($pid, 0);
{
sleep(5);
if ( -e "/home/mediacenter/.xbmc/steam-run" ) {
redo;
} elsif ( -e "/tmp/.X$myDisplay-lock" ) {
print $xbmcCommand . "\n";
system($xbmcCommand);
print "Next loop\n";
redo;
} else {
print "No X server is accessible.\n";
exit;
}
}
Then, from the SteamLauncher add-on, I fire a bash script that touches /home/mediacenter/.xbmc/steam-run, kills XBMC, and launches Steam:
Code:
# default.py
import os
import subprocess
try:
pid = os.fork()
except OSError, e:
raise Exception, "%s [%d]" % (e.strerror, e.errno)
if (pid == 0):
os.setsid()
try:
pid2 = os.fork() # Fork a second child.
except OSError, e:
raise Exception, "%s [%d]" % (e.strerror, e.errno)
if (pid2 == 0): # The second child.
os._exit(0)
else:
os._exit(1) # Exit parent (the first child) of the second child.
subprocess.Popen('/usr/local/bin/launchSteam')
Code:
#!/bin/bash
# launchSteam
touch /home/mediacenter/.xbmc/steam-run
killall -9 xbmc.bin
sleep 5
/usr/bin/steam -bigpicture; e=$?
rm -f /home/mediacenter/.xbmc/steam-run
exit $e
[ Problem Description ]
If I call default.py from XBMC, Steam's setup scripts are unable to execute some of their steps. This causes issues in path setup, and Steam ends up trying to write to /steamapps instead of $HOME/.local/share/Steam/SteamApps/
Code:
Failed system("/home/mediacenter/.local/share/Steam/.steam_exec_test.sh") in execute test: No child processes
How can I call my script properly from XBMC, to avoid this "No child processes" error?