VDR-SXFE + MMS: How is it working?

problems with keyboard, lirc or evdev

Moderator: Moderator

User avatar
acmelabs
Overlord
Posts: 2365
Joined: Mon Feb 20, 2006 9:18 pm
Location: Germany
Contact:

Postby acmelabs » Fri Mar 02, 2007 6:21 am

Code: Select all

kill -HUP $( ps -ef | grep lircd | awk '{ print $2}' )


but why not

Code: Select all

/etc/init.d/lirc stop

a killall could also kill, and a proper way to get a PID would be to start lircd with start-stop-daemon. So you have a proper PID-file in /var/run

I don't like any of these solutions, because I have also an mouse-daemon, irexec and irxevent running. I would have to restart them also. VDR must be able to release lirc, It's impertinent, that it doesn't!! So we have to tinker around and create silly workarounds! :evil:

Regards,
Andreas

User avatar
Uatschitchun
Overlord
Posts: 3189
Joined: Tue Dec 06, 2005 6:55 pm
Location: Germany
Contact:

Postby Uatschitchun » Fri Mar 02, 2007 8:02 am

We cannot stop lirc! Have you ever tried stoppping lirc while MMS is running? CPU-Usage goes up to 100% ...
VDR just looses lirc if it was shutdown and reconnects, but MMS does not like it very much (own experiences and Anders' warning) :wink:

I noticed, that even debian's /etc/init.d/lirc is using signal "1" to reload the config:
reload|force-reload)
if $START_LIRCD; then
start-stop-daemon --stop --quiet --signal 1 --exec /usr/sbin/lircd


And because it is using start-stop-daemon, we do have the pid in:
/var/run/lircd.pid


So I see no reason call it a 'workaround'!
If we disable vdr's remote with a patched-in svdrp command or if we make lirc reload it's config ... seems the second is the cleaner way!

Sadly we cannot use MMS' config option 'tvopts' anymore while using scripts ... but ... the 'tvopts' may be passed to a script as $1, may they?

Damn ... I'm so terrible in scripting ;)

All that is needed is a wrapper, which takes $1 as input (options), keeps alive as long as one is using the external program to keep MMS acting like it is runing and has 4 variables defined in the beginning ((1) original lircd.conf, (2) lircd.conf for MMS, (3) lircd.conf for external app, (4) external app) !?

Lg
Roman

User avatar
Uatschitchun
Overlord
Posts: 3189
Joined: Tue Dec 06, 2005 6:55 pm
Location: Germany
Contact:

Postby Uatschitchun » Fri Mar 02, 2007 8:22 am

For we have a maximum of 9 parameters that may be passed to a script (if not using bash), would it be possible to make MMS pass the 'tvopts' as only _1_ parameter, to avoid overflows?

Up to 9 parameter could be passed like '$*' ... but a 10th?

Should be this line in tv.cpp:
run::my_system((conf->p_tv_path() + ' ' + conf->p_tv_opts()).c_str());


(btw. isn't it a problem calling 'p_tv_opts' when the according line in config is called 'tvopts =' (without '_')?)

Lg
Roman

User avatar
Uatschitchun
Overlord
Posts: 3189
Joined: Tue Dec 06, 2005 6:55 pm
Location: Germany
Contact:

Postby Uatschitchun » Fri Mar 02, 2007 8:46 am

Ok ... found the drawback :cry:

kill -HUP only works as root ...

copying lircd.confs, as long as they are rested in /etc, too ...

This script (pls don't laugh):
#!/bin/sh

echo "Copy lircd.conf"
cp /etc/lirc/lircd.conf.test /etc/lirc/lircd.conf

echo "Reload lircd.conf"
kill -HUP $(pidof lircd)

echo $*
/usr/bin/vdr-sxfe $*

echo "Copy lircd.conf back"
cp /etc/lirc/lircd.conf.roman /etc/lirc/lircd.conf

echo "Reload lircd.conf"
kill -HUP $(pidof lircd)


Works nice, as long as it is running as root ...


Lg
Roman

User avatar
acmelabs
Overlord
Posts: 2365
Joined: Mon Feb 20, 2006 9:18 pm
Location: Germany
Contact:

Postby acmelabs » Fri Mar 02, 2007 9:26 am

$0 represents the whole parameter string. $1, $2, and so forth just parts of it.

User avatar
Uatschitchun
Overlord
Posts: 3189
Joined: Tue Dec 06, 2005 6:55 pm
Location: Germany
Contact:

Postby Uatschitchun » Fri Mar 02, 2007 10:09 am

Thx ... any idea on how to workaround ( :? ) this root thing ?

$0 gives name of the script itself ..

User avatar
Uatschitchun
Overlord
Posts: 3189
Joined: Tue Dec 06, 2005 6:55 pm
Location: Germany
Contact:

Postby Uatschitchun » Fri Mar 02, 2007 11:19 am

Anybody here able to tell me, how make this litte program take and pass parameters to the given script?


Code: Select all

#include <unistd.h>
#include <errno.h>

main( int argc, char ** argv, char ** envp )
{
              if( setgid(getegid()) ) perror( "setgid" );
              if( setuid(geteuid()) ) perror( "setuid" );
              envp = 0; /* blocks IFS attack on non-bash shells */
              system( "/path/to/script", argv, envp );
              perror( argv[0] );
              return errno;
}


Compiling this with:
gcc -Wall suid-wrapper.c -o suid-wrapper

and
chown root suid-wrapper
chmod 4711 suid-wrapper


thus one can define suid.wrapper as tv_path and pass tvopts to it. suid.wrapper passes these options to the start-script (see above), beeing able to perform the root actions (without password and only for this script)

Lg
Roman

User avatar
acmelabs
Overlord
Posts: 2365
Joined: Mon Feb 20, 2006 9:18 pm
Location: Germany
Contact:

Postby acmelabs » Fri Mar 02, 2007 12:28 pm

boah, one million years ago, since I've been using a compiler:

Here's my kindergarden approach. Use it, as long you don't have better solution in c++.

Code: Select all

#include <unistd.h>
#include "errno.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include "system.h"
//#include "config.h"

main( int argc, char ** argv )
{
              int i;
              char mystring[1024] ="ls ";
              if( setgid(getegid()) ) printf ( "setgid\n" );
              if( setuid(geteuid()) ) printf ( "setuid\n" );
              //envp = 0; /* blocks IFS attack on non-bash shells */
              for (i=1; i<argc; i++) {
                printf ("i=%s\n", argv[i]);
                strcat (mystring, argv[i]);
              }

              system( mystring );
              perror( argv[0] );
              return errno;
}


EDIT: for some reason I got an undefined reference if I use gcc, with g++ all works fine ;-)

Regards,
Andreas

ps: sorry, The $0 stuff is awk!

User avatar
Uatschitchun
Overlord
Posts: 3189
Joined: Tue Dec 06, 2005 6:55 pm
Location: Germany
Contact:

Postby Uatschitchun » Fri Mar 02, 2007 12:44 pm

Cool ..

:/suid-wrapper --lirc --audio=alsa

gives '--lirc--audio=alsa' ... missing spaces ;(

LG
Roman

User avatar
acmelabs
Overlord
Posts: 2365
Joined: Mon Feb 20, 2006 9:18 pm
Location: Germany
Contact:

Postby acmelabs » Fri Mar 02, 2007 1:17 pm

Code: Select all

#include <unistd.h>
#include "errno.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include "system.h"
//#include "config.h"

main( int argc, char ** argv )
{
              int i;
              char mystring[1024] ="ls ";
              if( setgid(getegid()) ) printf ( "setgid\n" );
              if( setuid(geteuid()) ) printf ( "setuid\n" );
              //envp = 0; /* blocks IFS attack on non-bash shells */
              for (i=1; i<argc; i++) {
                printf ("i=%s\n", argv[i]);
                strcat (mystring, argv[i]);
                strcat (mystring, " ");
              }

              system( mystring );
              perror( argv[0] );
              return errno;
}

User avatar
Uatschitchun
Overlord
Posts: 3189
Joined: Tue Dec 06, 2005 6:55 pm
Location: Germany
Contact:

Postby Uatschitchun » Fri Mar 02, 2007 2:21 pm

How to use MMS with VDR on the same machine without patching VDR

Scheme

Both, VDR and MMS are using LIRC, but with different keys defined.
*
Starting MMS with LIRC using lircd.conf.mms
*
Menu - > TV
*
Using mmsvdrwrapper to start mmsvdr.sh (with root rights)
*
Change lircd.conf at runtime and make LIRC to reload it with kill -HUP
*
starting vdr-sxfe with '--lirc' forwards lirc commands to VDR using lircd.conf.vdr
*
quitting vdr-sxfe (irexec) re-changes lircd.conf again and reloads it.



Here's a step-by-step procedure:

mmsvdrwrapper.c:

Code: Select all

#include <unistd.h>
#include "errno.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

main( int argc, char ** argv )
{
              int i;
              char mystring[1024] ="/usr/lib/mms/mmsvdr.sh ";
              if( setgid(getegid()) ) perror ( "setgid" );
              if( setuid(geteuid()) ) perror ( "setuid" );
              for (i=1; i<argc; i++) {
                strcat (mystring, argv[i]);
                strcat (mystring, " ");
              }

              system( mystring );
              perror( argv[0] );
              return errno;
}


Compile with:

Code: Select all

gcc -Wall mmsvdrwrapper.c -o mmsvdrwrapper

Code: Select all

chmod 4711 mmsvdrwrapper

Code: Select all

mv ./mmsvdrwrapper /usr/lib/mms/


mmsvdr.sh:

Code: Select all

#!/bin/sh

#
# What Application would you like to watch TV with?
# Pls supply full path
#
tvapp=/usr/bin/vdr-sxfe

#
# Your lircd.conf designed to work with MMS
#
lircd_mms=/etc/lirc/lircd.conf.mms

#
# Your lircd.conf designed to work with VDR
#
lircd_vdr=/etc/lirc/lircd.conf.vdr

#
# Where is your lircd.conf
# normaly you won't have to change this
#
lircd_orig=/etc/lirc/lircd.conf

#
### Do not change after here
#

echo "Copy lircd.conf"
cp $lircd_vdr $lircd_orig

echo "Reload lircd.conf"
kill -HUP $(pidof lircd)

$tvapp $*

echo "Copy lircd.conf back"
cp $lircd_mms $lircd_orig

echo "Reload lircd.conf"
kill -HUP $(pidof lircd)


And save to

Code: Select all

/usr/lib/mms/mmsvdr.sh

(Name is important cause wrapper is calling this scripts)

Code: Select all

chmod a+x /usr/lib/mms/mmsvdr.sh


Copy over your /etc/lirc/lircd.conf:

Code: Select all

cp /etc/lirc/lircd.conf /etc/lirc/lircd.conf.mms

Code: Select all

cp /etc/lirc/lircd.conf /etc/lirc/lircd.conf.vdr


Now edit /etc/lirc/lircd.conf.vdr and give different names for all key ... example:
Before

Code: Select all

          ok                       0x00000020EE11520D
          up                       0x00000020EE11D50A
          left                     0x00000020EE11D20D
          right                    0x00000020EE11D10E
          down                     0x00000020EE11D30C
          exit                     0x00000020EE11C906
          menu                     0x00000020EE11B609

After

Code: Select all

          ok-vdr                       0x00000020EE11520D
          up-vdr                       0x00000020EE11D50A
          left-vdr                     0x00000020EE11D20D
          right-vdr                    0x00000020EE11D10E
          down-vdr                     0x00000020EE11D30C
          exit-vdr                     0x00000020EE11C906
          menu-vdr                     0x00000020EE11B609


Now define lirc-keys in your vdr's remote.conf ... example:

Code: Select all

LIRC.Up         up-vdr
LIRC.Down       down-vdr
LIRC.Menu       menu-vdr
LIRC.Ok         ok-vdr
LIRC.Back       exit-vdr
LIRC.Left       left-vdr
LIRC.Right      right-vdr

and restart vdr

In MMS' config set:

Code: Select all

tv_path = /usr/lib/mms/mmsvdrwrapper

and (example)

Code: Select all

tvopts = --lirc --audio=alsa --video=xv


At last you need irexec with ~/.lircrc:

Code: Select all

begin
  remote = q-sonic
  prog = irexec
  button = av-vdr
  config = killall -9 vdr-sxfe
end

to kill vdr-sxfe by remote (remember to use lircd.conf.vdr's setting cause it's the one beeing active)


Todo:

* mmsvdrwrapper & mmsvdr.sh might be smarter !?

* Redesign the wrapper to only be called when needed! Right now the hole script 'mmsvdr.sh' is running with user=root, but only the copy and kill sections need user=root, not the tvapp.

* Sadly I don't know how to send just 'ESCAPE-KEY' with irexec !?

Lg
Roman

User avatar
acmelabs
Overlord
Posts: 2365
Joined: Mon Feb 20, 2006 9:18 pm
Location: Germany
Contact:

Postby acmelabs » Fri Mar 02, 2007 3:10 pm

Uatschitchun wrote:* Sadly I don't know how to send just 'ESCAPE-KEY' with irexec !?

Is this what you want?
http://mms.kicks-ass.org/wiki/index.php ... te_control

Regards,
Andreas

ps: Sorry, but I've brushed up the code a bit, I thought you would throw out the comments.

User avatar
Uatschitchun
Overlord
Posts: 3189
Joined: Tue Dec 06, 2005 6:55 pm
Location: Germany
Contact:

Postby Uatschitchun » Fri Mar 02, 2007 3:25 pm

Jepp, it works with irxevent, but not with irexec ...

Lg
Roman

P.S. Thx for code cleaning!

User avatar
acmelabs
Overlord
Posts: 2365
Joined: Mon Feb 20, 2006 9:18 pm
Location: Germany
Contact:

Postby acmelabs » Fri Mar 02, 2007 3:36 pm

Uatschitchun wrote:Jepp, it works with irxevent, but not with irexec ...

Lg
Roman

P.S. Thx for code cleaning!

Don't know it right now. Have to look it up at home. But you're right, it's an odd thing. Could be, it doesn't work at all.

Regards,
Andreas

User avatar
arj
Site Admin
Posts: 2316
Joined: Thu Dec 01, 2005 8:51 pm
Location: Denmark
Contact:

Postby arj » Fri Mar 02, 2007 6:22 pm

Uatschitchun wrote:Copy over your /etc/lirc/lircd.conf:

Code: Select all

cp /etc/lirc/lircd.conf /etc/lirc/lircd.conf.mms

Code: Select all

cp /etc/lirc/lircd.conf /etc/lirc/lircd.conf.vdr


Now edit /etc/lirc/lircd.conf.vdr and give different names for all key ... example:
Before

Code: Select all

          ok                       0x00000020EE11520D
          up                       0x00000020EE11D50A
          left                     0x00000020EE11D20D
          right                    0x00000020EE11D10E
          down                     0x00000020EE11D30C
          exit                     0x00000020EE11C906
          menu                     0x00000020EE11B609

After

Code: Select all

          ok-vdr                       0x00000020EE11520D
          up-vdr                       0x00000020EE11D50A
          left-vdr                     0x00000020EE11D20D
          right-vdr                    0x00000020EE11D10E
          down-vdr                     0x00000020EE11D30C
          exit-vdr                     0x00000020EE11C906
          menu-vdr                     0x00000020EE11B609


Now define lirc-keys in your vdr's remote.conf ... example:

Code: Select all

LIRC.Up         up-vdr
LIRC.Down       down-vdr
LIRC.Menu       menu-vdr
LIRC.Ok         ok-vdr
LIRC.Back       exit-vdr
LIRC.Left       left-vdr
LIRC.Right      right-vdr

and restart vdr


Great guide. I'll compare to what I have done with my system at home. Can't remember right now :)

A small note, one should be able to write a small script that creates an /etc/lirc/lircd.conf.vdr and fixes remove.conf automatically.


Return to “input”

Who is online

Users browsing this forum: No registered users and 1 guest