1

tl;dr

$ sudo -u www-data mplayer -slave -input file=/srv/mplayer.fifo -playlist /srv/list &
$ lsof /srv/mplayer.fifo | tail +2
mplayer 21059 www-data    4u  FIFO  179,2      0t0 2359331 /srv/mplayer.fifo

$ cat /var/www/html/test
#!/usr/bin/bash
mplayer -slave -input file=/srv/mplayer.fifo -playlist /srv/list &

$ curl 'http://localhost/test' # mplayer starts playback (and keeps playing)
$ lsof /srv/mplayer.fifo
# no output!?

details

On my Raspberry Pi, I have a lighttpd server running. It's supposed to start and control an mplayer process. The webserver starts mplayer with -slave -input file=/srv/mplayer.fifo. (So mplayer reads and executes commands from that file.) In order to skip to the next song, one of the webserver scripts writes pt_skip 1 to /srv/mplayer.fifo. This indeed works when mplayer was run from command line. But when started from lighttpd, mplayer does not read commands from /srv/mplayer.fifo. I don't understand why. Here's what I did:

Setup

$ mkfifo /srv/mplayer.fifo
$ chmod o+w /srv/mplayer.fifo
$ ls -l /srv/mplayer.fifo
prw-r--rw- 1 root root 0 Aug  7 12:11 /srv/mplayer.fifo

Test (ran from command line)

$ sudo -u www-data mplayer -ao alsa -slave -input file=/srv/mplayer.fifo -playlist /srv/list -shuffle
$ lsof /srv/mplayer.fifo
COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
mplayer 21059 www-data    4u  FIFO  179,2      0t0 2359331 /srv/mplayer.fifo
$ ps aux | grep mplayer
root     21058  0.0  0.2   4680  2400 pts/0    S+   12:13   0:00 sudo -u www-data mplayer -ao alsa -slave -input file=/srv/mplayer.fifo -playlist /srv/list -shuffle
www-data 21059 11.6  3.1 127928 30008 pts/0    SL+  12:13   0:01 mplayer -ao alsa -slave -input file=/srv/mplayer.fifo -playlist /srv/list -shuffle

That's like expected. But if I run mplayer from lighttpd ...

$ cat /var/www/html/play
#!/usr/bin/bash
mplayer -ao alsa -slave -input file=/srv/mplayer.fifo -playlist /srv/list -shuffle &

... it starts mplayer, but the mplayer instance is not reading from /srv/mplayer.fifo. lsof doesn't produce any output:

$ lsof /srv/mplayer.fifo

$ ps aux | grep mplayer
www-data 21177 15.3  3.1 128212 29744 ?        SL   12:30   0:01 mplayer -ao alsa -slave -input file=/srv/mplayer.fifo -playlist /srv/list -shuffle

I can also see mplayer is not reading from the pipe, because writing to it blocks. The mplayer logs don't show anything unusual. Do you have an idea why mplayer doesn't read from the named pipe when run from lighttpd?

2
  • Perhaps mplayer has not yet reached the part where it opens the fifo. You could trace what it is doing by prefixing the command with strace -f -o /tmp/trace, which shows the system calls in the output file. Commented Aug 8, 2022 at 9:16
  • mplayer has started it's playback and keeps playing songs from that list. The output of lsof however stays empty. I'll try strace later, thanks! Commented Aug 8, 2022 at 9:27

1 Answer 1

0

tl;dr

export HOME=/var/www-data

details

I compared the environment variables from command line

sudo -u www-data env

with the environment variables set by lighttpd

#!/usr/bin/bash
env

Turns out, mplayer requires HOME to be set. With this script, lsof /srv/mplayer.fifo shows mplayer:

#!/usr/bin/bash
export HOME=/var/www
mplayer -ao alsa -slave -input file=/srv/mplayer.fifo -playlist /srv/list -shuffle &

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.