Zugriff mit system() auf Unix; Rechteproblem? Welchen User nutzt fhem?

Begonnen von Tobias, 07 Januar 2014, 09:29:08

Vorheriges Thema - Nächstes Thema

Tobias

Hi,
ich bin zurZeit dabei ein Test2Speech Modul zu erstellen. Dabei versuche mit system() einen mplayeraufruf zu starten.
Unter dem User "fhem" funktioniert dies perfekt, aber als Aufruf in FHEM findet er das alsa-Device nicht.
Ideen was ich übersehen haben könnte?

{system('/usr/bin/mplayer -ao alsa:device=hw=0.0 -nolirc -noconsolecontrols "http://translate.google.com/translate_tts?tl=de&q=test"')}

Cannot find HOME directory.
MPlayer 1.0rc3-4.4.4 (C) 2000-2009 MPlayer Team

Playing http://translate.google.com/translate_tts?tl=de&q=test.
Resolving translate.google.com for AF_INET6...
Connecting to server translate.google.com[42.0.20.80]: 80...
Failed to connect to server with AF_INET6
Resolving translate.google.com for AF_INET...
Connecting to server translate.google.com[173.194.112.225]: 80...
Cache size set to 320 KBytes

Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Cache fill:  0.00% (0 bytes)   
Audio only file format detected.
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
AUDIO: 16000 Hz, 2 ch, s16le, 32.0 kbit/6.25% (ratio: 4000->64000)
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
[AO_ALSA] alsa-lib: pcm_hw.c:1401:(_snd_pcm_hw_open) Invalid value for card
[AO_ALSA] Playback open error: No such file or directory
Failed to initialize audio driver 'alsa:device=hw=0.0'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video


Exiting... (End of file)


Und direkt auf Unix mit dem User "fhem"
root@Iconnect:~# login fhem
Password:

$ cd /
$ /usr/bin/mplayer -ao alsa:device=hw=0.0 -nolirc -noconsolecontrols "http://translate.google.com/translate_tts?tl=de&q=test"
MPlayer 1.0rc3-4.4.4 (C) 2000-2009 MPlayer Team

Playing http://translate.google.com/translate_tts?tl=de&q=test.
Resolving translate.google.com for AF_INET6...
Connecting to server translate.google.com[42.0.20.80]: 80...
Failed to connect to server with AF_INET6
Resolving translate.google.com for AF_INET...
Connecting to server translate.google.com[173.194.112.225]: 80...
Cache size set to 320 KBytes
Cache fill:  0.00% (0 bytes)
Audio only file format detected.
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
AUDIO: 16000 Hz, 2 ch, s16le, 32.0 kbit/6.25% (ratio: 4000->64000)
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
AO: [alsa] 48000Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A:   0.6 (00.5) of 0.9 (00.9)  8.4% 0%

Exiting... (End of file)


Edit: durch "groups" hab ich endeckt, das fhem nur in der "dialout"-gruppe ist, aber nicht in "audio".
Welchen User nutzt aber nun fhem um diesem der Gruppe "audio" zuzuweisen?

Als Workarround habe ich erstmal sudoers geändert
ALL     ALL = NOPASSWD: /usr/bin/mplayer
Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter

justme1968

mir fällt die 'Cannot find HOME directory.' meldung im ersten fall auf. und das du beim aufruf von hand ein 'cd /' zusätzlich dabei hast.

was passiert wenn du beim aufruf von hand das 'cd /' weg lässt bzw vorhin in s fhem verzeichnis (oder in das Verzeichnis das ein 'pwd' mit wechselst? nimm mal die backticks `...`statt system. dann geht der aufruf genau so über die shell wie beim aufruf von hand.

gruss
  andre
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968