2009-03-18, 21:56
> 1. you could write your script here, it could help or be inspirational to someone else
Just a hacky workaround so ymmv. Will try messing with modprobe later.
waitforlirc.cpp:
Build it:
.xsession
Just a hacky workaround so ymmv. Will try messing with modprobe later.
waitforlirc.cpp:
Code:
#include <sys/socket.h>
#include <sys/un.h>
#include <stdlib.h>
#include <iostream>
#define LIRC_DEVICE "/dev/lircd"
#define MAX_ATTEMPT 20
using namespace std;
int main( int argc, char *argv[] )
{
int attempts = MAX_ATTEMPT;
int attempt = 0;
struct sockaddr_un addr;
int fd = -1;
int status = -1;
if( argc == 2 )
{
attempts = atoi( argv[1] );
}
addr.sun_family = AF_UNIX;
strcpy( addr.sun_path, LIRC_DEVICE );
while( status!=0 && attempt++<=attempts )
{
cout << "Attempt " << attempt << ": ";
fd = socket( AF_UNIX, SOCK_STREAM, 0 );
if( fd == -1 )
{
cout << "Socket failed" << endl;
status = 2;
close(fd);
sleep(1);
continue;
}
if( connect( fd, (struct sockaddr *)&addr, sizeof(addr) ) == -1 )
{
cout << "Connect failed" << endl;
status = 3;
close(fd);
sleep(1);
continue;
}
cout << "Connected!" << endl;
status = 0;
close(fd);
}
if( status!=0 )
{
cout << "Couldn't connect after max attempts." << endl;
}
return status;
}
Build it:
Code:
g++ waitforlirc.cpp -o waitforlirc
.xsession
Code:
export XBMC_PLATFORM_MODE=1
/home/mediabox/bin/waitforlirc 60 > /var/tmp/waitforlirc.log
/usr/share/xbmc/xbmc.bin -q -p --standalone
case "$?" in
0 ) # Quit
touch /tmp/noRestartXBMC
break ;;
64 ) # Shutdown System
sleep 10 ;;
65 ) # Warm Reboot
echo Restarting XBMC ... ;;
66 ) # Reboot System
sleep 10 ;;
* ) ;;
esac