Main Wrapper
From OpenTViX
The main wrapper is a dynamic library written by octessence and can be used to intercept calls to the c standard libraries to block certain behaviour or to perform actions such as running scripts when buttons are pressed.
Contents |
Features
Remote control interception - This feature allows you to capture button presses on the remote control and fire off scripts. These scripts can do anything you want, for example send a Wake-On-LAN packet to your NAS or PC.
Inetd Blocking - The main process on the M-6500 creates the /etc/inetd.conf file when it starts up and then runs the inetd daemon. This prevents us having control over services started by inetd (ftpd, smbd and nmbd), and also stops us adding new ones. This feature prevents the main process accessing the inetd.conf file and stops it starting and stopping the inetd daemon and the daemons. This allows us more control over the TViX.
Blocking module control - The main process inserts and romoved modules when it starts/stops. In particular it removes the network module (r8169). This feature blocks insmod() and rmmod().
Signal Handler - This implements a signal handler and closes the ir, fip, mum0 and em86xx0 devices. This allows them to be used by other processes should we ever write any.
Installation
Firstly, you need to download the wrapper tar file from the downloads area. This file contains a pre-built and tested dynamic library called main_wrapper.so. You need to copy this file to the /tvix directory on your TViX M-6500.
scp main_wrapper.so root@tvix:/tvix/
Next you have to update the /tvix/main script to use the main wrapper. An example main file is included in the main_wrapper tar file. The best way to do this is to set up the script to only use the main wrapper when a file on the usb stick is present. This means you can remove the USB stick to disable the feature if things go wrong and you can't access the TViX to reconfigure it.
To do this, you need to replace the start_dvico_main() function of the /tvix/main script with this. (I will explain the configuration settings next).
start_dvico_main()
{
mount -t vfat /dev/sda1 /tmp/mnt/usb1
if [ -f /tmp/mnt/usb1/wrapmain ]; then
exec > /tmp/mnt/usb1/wrapmain.log 2>&1
#export MAINWRAP_BLOCK_INETD=1
#export MAINWRAP_BLOCK_INSMOD=1
#export MAINWRAP_BLOCK_RMMOD=1
#export MAINWRAP_CLEAN_SHUTDOWN=1 (experimental)
export MAINWRAP_MONITOR_IR=1
#export MAINWRAP_KEY_GUIDE="/root/guide_script.sh &"
export MAINWRAP_KEY_REC=/root/wake_pc.sh
LD_PRELOAD=$TVIX_ROOT/main_wrapper.so $TVIX_ROOT/main.dvico $* &
else
# Fall back on main when nomain file not found on usb1
umount /tmp/mnt/usb1
$TVIX_ROOT/opentvix/exec $TVIX_ROOT/main.dvico $* &
fi
}
Notice that the script mounts the usb stick and then checks for the wrapmain file. In this example we only have the remote control monitor enabled and this runs the script /root/wake_pc.sh
You should do you best to make sure this method it correct before you reboot. Check it and double check it to make sure. If you mess this up the TViX will not boot properly and you will not be able to have access to the TViX since the main program controls the network. This will result in you needing to do a safe mode upgrade. Although this should rescue you TViX, needing to use the safe mode upgrade always makes me nervous.
Configuration
In the example start_dvico_main() above ,you will notice that before running the wrapped main process, a bunch of environment variables are set. These control what features are enabled in the wrapper library. The following settings are available:
- MAINWRAP_BLOCK_INETD - Block control over inetd and its daemons and configuration
- MAINWRAP_BLOCK_INSMOD - Block all calls to insmod
- MAINWRAP_BLOCK_RMMOD - Block all calls to rmmod
- MAINWRAP_CLEAN_SHUTDOWN - Create a signal handler and close devices on exit.
- MAINWRAP_MONITOR_IR - Enable monitoring of remote buttons.
The final option will allow the use of the following variables to run scripts when buttons are pressed:
- MAINWRAP_KEY_POWER0
- MAINWRAP_KEY_POWER1
- MAINWRAP_KEY_MUTE
- MAINWRAP_KEY_DTV
- MAINWRAP_KEY_VIDEO
- MAINWRAP_KEY_AUDIO
- MAINWRAP_KEY_PHOTO
- MAINWRAP_KEY_0
- MAINWRAP_KEY_1
- MAINWRAP_KEY_2
- MAINWRAP_KEY_3
- MAINWRAP_KEY_4
- MAINWRAP_KEY_5
- MAINWRAP_KEY_6
- MAINWRAP_KEY_7
- MAINWRAP_KEY_8
- MAINWRAP_KEY_9
- MAINWRAP_KEY_SCROLL
- MAINWRAP_KEY_ZOOM
- MAINWRAP_KEY_FBACK
- MAINWRAP_KEY_FFORWARD
- MAINWRAP_KEY_UP
- MAINWRAP_KEY_DOWN
- MAINWRAP_KEY_RIGHT
- MAINWRAP_KEY_LEFT
- MAINWRAP_KEY_PLAY
- MAINWRAP_KEY_STOP
- MAINWRAP_KEY_RIGHT
- MAINWRAP_KEY_CHAN_UP
- MAINWRAP_KEY_CHAN_DOWN
- MAINWRAP_KEY_VOL_UP
- MAINWRAP_KEY_VOL_DOWN
- MAINWRAP_KEY_INFO
- MAINWRAP_KEY_GOTO
- MAINWRAP_KEY_SUBTITLE
- MAINWRAP_KEY_BOOKMARK
- MAINWRAP_KEY_SETUP
- MAINWRAP_KEY_MENU
- MAINWRAP_KEY_TITLE
- MAINWRAP_KEY_FUNCTION
- MAINWRAP_KEY_SHUFFLE
- MAINWRAP_KEY_TVOUT
- MAINWRAP_KEY_ANGLE
- MAINWRAP_KEY_REPEAT
- MAINWRAP_KEY_DELETE
- MAINWRAP_KEY_GUIDE
- MAINWRAP_KEY_REC
Example
In the start_dvico_main() example above, I have set the record button to run the wake_pc.sh script in /root. I don't have a tuner so the button doesn't usually do anything for me. As an example, this is what the file contains on my configuration. It sends a WOL packet to my PC and then remounts my automount directories.
#!/bin/sh datestr=`date +%Y-%m-%dT%H-%M-%S` echo "$datestr -- Wake oroboros" ether-wake 00:22:15:1B:68:52 sleep 5 /opt/opentvix/conf/init.automount