[opensuse] Trying to play sound from inside a cron job
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have this test line in my user crontab: * * * * * /usr/bin/play /tmp/time.wav But I get this failure message (via mail) and no sound: ALSA lib pcm_dmix.c:1010:(snd_pcm_dmix_open) unable to open slave /usr/bin/play FAIL formats: can't open output file `default': snd_pcm_open error: Device or resource busy Needless to say, that same command line on the CLI works just fine. - -- Cheers, Carlos E. R. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAk169rIACgkQtTMYHG2NR9XcpgCggBneNqldvBRWF+DMwexJeqEN 3RUAnRx2k/I61w/0XdRqmq53xdual3Dg =NDQz -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sat, 12 Mar 2011 05:29:31 +0100 (CET) "Carlos E. R." <carlos.e.r@opensuse.org> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
I have this test line in my user crontab:
* * * * * /usr/bin/play /tmp/time.wav
But I get this failure message (via mail) and no sound:
ALSA lib pcm_dmix.c:1010:(snd_pcm_dmix_open) unable to open slave /usr/bin/play FAIL formats: can't open output file `default': snd_pcm_open error: Device or resource busy
Needless to say, that same command line on the CLI works just fine.
Hi Add your user to the audio group. -- Cheers Malcolm °¿° (Linux Counter #276890) openSUSE 11.4 (x86_64) Kernel 2.6.37.1-1.2-desktop up 1 day 6:17, 3 users, load average: 0.14, 0.14, 0.15 GPU GeForce 8600 GTS Silent - Driver Version: 260.19.26 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
* Malcolm <malcolm_lewis@bellsouth.net> [03-11-11 23:47]:
On Sat, 12 Mar 2011 05:29:31 +0100 (CET) "Carlos E. R." <carlos.e.r@opensuse.org> wrote:
Needless to say, that same command line on the CLI works just fine.
Hi Add your user to the audio group.
"CLI works" would indicate the user was in the audio group. -- (paka)Patrick Shanahan Plainfield, Indiana, USA HOG # US1244711 http://wahoo.no-ip.org Photo Album: http://wahoo.no-ip.org/gallery2 http://en.opensuse.org openSUSE Community Member Registered Linux User #207535 @ http://counter.li.org -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2011-03-12 05:50, Patrick Shanahan wrote:
* Malcolm <> [03-11-11 23:47]:
On Sat, 12 Mar 2011 05:29:31 +0100 (CET) "Carlos E. R." <> wrote:
Needless to say, that same command line on the CLI works just fine.
Hi Add your user to the audio group.
"CLI works" would indicate the user was in the audio group.
Obviously :-) I'm trying to guess what difference there is inside cron. No terminal, of course. Maybe it tries alsa directly instead of pulse, and fails (busy, firefox holds it (flash plugin)). - -- Cheers / Saludos, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAk16/j8ACgkQtTMYHG2NR9X30ACfV5D6QIUbWbevKcdI2i/2tvPf 9GMAn3JU7q8bLdLS99YxfKH0aEWiFd77 =V4he -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sat, 12 Mar 2011 06:01:51 +0100 "Carlos E. R." <robin.listas@telefonica.net> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 2011-03-12 05:50, Patrick Shanahan wrote:
* Malcolm <> [03-11-11 23:47]:
On Sat, 12 Mar 2011 05:29:31 +0100 (CET) "Carlos E. R." <> wrote:
Needless to say, that same command line on the CLI works just fine.
Hi Add your user to the audio group.
"CLI works" would indicate the user was in the audio group.
Obviously :-)
I'm trying to guess what difference there is inside cron. No terminal, of course. Maybe it tries alsa directly instead of pulse, and fails (busy, firefox holds it (flash plugin)).
Tried here and it works both from CLI and cron Gnome DE. The man page for play talks about setting the AUDIODRIVER environment variable, maybe you need to add that. -- Cheers Malcolm °¿° (Linux Counter #276890) openSUSE 11.4 (x86_64) Kernel 2.6.37.1-1.2-desktop up 1 day 6:52, 4 users, load average: 1.71, 1.54, 0.89 GPU GeForce 8600 GTS Silent - Driver Version: 260.19.26 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday, 2011-03-11 at 23:20 -0600, Malcolm wrote:
Tried here and it works both from CLI and cron Gnome DE. The man page for play talks about setting the AUDIODRIVER environment variable, maybe you need to add that.
Interesting... but it doesn't work here. In the CLI I get: cer@Telcontar:~> AUDIODRIVER=oss play /tmp/time.wav play FAIL formats: can't open output file `/dev/dsp': Device or resource busy which is true. With driver "alsa" it succeeds. But inside cron it doesn't. If the driver is oss I get the above error, if it is alsa I get: ALSA lib pcm_dmix.c:1010:(snd_pcm_dmix_open) unable to open slave play FAIL formats: can't open output file `default': snd_pcm_open error: Device or resource busy which is the original error I was getting. Which openSUSE version are you using? Mine is 11.2, and I'm also using gnome. - -- Cheers, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAk17jCwACgkQtTMYHG2NR9XmOACfZX/XIS/uT5U9BDY40/oWXIEs jRQAoIeNg24WwZDYt6X9Guu2C4ub/wd9 =kRsG -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sat, 12 Mar 2011 16:07:17 +0100 (CET) "Carlos E. R." <robin.listas@telefonica.net> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Friday, 2011-03-11 at 23:20 -0600, Malcolm wrote:
Tried here and it works both from CLI and cron Gnome DE. The man page for play talks about setting the AUDIODRIVER environment variable, maybe you need to add that.
Interesting... but it doesn't work here. In the CLI I get:
cer@Telcontar:~> AUDIODRIVER=oss play /tmp/time.wav play FAIL formats: can't open output file `/dev/dsp': Device or resource busy
which is true. With driver "alsa" it succeeds. But inside cron it doesn't. If the driver is oss I get the above error, if it is alsa I get:
ALSA lib pcm_dmix.c:1010:(snd_pcm_dmix_open) unable to open slave play FAIL formats: can't open output file `default': snd_pcm_open error: Device or resource busy
which is the original error I was getting.
Which openSUSE version are you using? Mine is 11.2, and I'm also using gnome.
- -- Cheers, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux)
iEYEARECAAYFAk17jCwACgkQtTMYHG2NR9XmOACfZX/XIS/uT5U9BDY40/oWXIEs jRQAoIeNg24WwZDYt6X9Guu2C4ub/wd9 =kRsG -----END PGP SIGNATURE----- Hi 11.4 here, wonder if it's something in the config files. Do you have a ~/.asoundrc file or maybe one of the ones it /etc which won't be called via cron as there is no environment.
-- Cheers Malcolm °¿° (Linux Counter #276890) openSUSE 11.4 (x86_64) Kernel 2.6.37.1-1.2-desktop up 1 day 17:16, 5 users, load average: 0.36, 0.19, 0.31 GPU GeForce 8600 GTS Silent - Driver Version: 260.19.26 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday, 2011-03-12 at 09:43 -0600, Malcolm wrote:
Hi 11.4 here, wonder if it's something in the config files. Do you have a ~/.asoundrc file or maybe one of the ones it /etc which won't be called via cron as there is no environment.
I rather think it must be a bug that was corrected later than my version. I might try a sox update. I don't have ~/.asoundrc, but something is in /etc - -rw-r--r-- 1 root root 282 2009-10-20 10:50 /etc/asound-pulse.conf - -rw-r--r-- 1 root root 44254 2011-02-26 23:10 /etc/asound.state - -- Cheers, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAk17nEwACgkQtTMYHG2NR9VwPgCdGP26lrQzJ5DY45ti3HqmxJTW kPsAn1oKAy7teJ4CkrjI0MWneG8fw3py =49ar -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
El 12/03/11 01:29, Carlos E. R. escribió:
I have this test line in my user crontab:
* * * * * /usr/bin/play /tmp/time.wav
a) Do you want to get owned ? :-D b) did you mean "aplay" ?
But I get this failure message (via mail) and no sound:
ALSA lib pcm_dmix.c:1010:(snd_pcm_dmix_open) unable to open slave /usr/bin/play FAIL formats: can't open output file `default': snd_pcm_open error: Device or resource busy
Needless to say, that same command line on the CLI works just fine.
strace the process if possible, to see wth goes wrong, most likely the lack of some enviroment variable. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
* Cristian Rodríguez <crrodriguez@opensuse.org> [03-12-11 11:39]:
b) did you mean "aplay" ?
openSUSE 11.2 x86_64 11:58 wahoo:~ > l /usr/bin/play lrwxrwxrwx 1 root root 3 2011-03-04 09:56 /usr/bin/play -> sox 11:58 wahoo:~ > l /usr/bin/aplay -rwxr-xr-x 1 root root 65008 2011-02-01 09:33 /usr/bin/aplay -- (paka)Patrick Shanahan Plainfield, Indiana, USA HOG # US1244711 http://wahoo.no-ip.org Photo Album: http://wahoo.no-ip.org/gallery2 http://en.opensuse.org openSUSE Community Member Registered Linux User #207535 @ http://counter.li.org -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday, 2011-03-12 at 13:38 -0300, Cristian Rodríguez wrote:
El 12/03/11 01:29, Carlos E. R. escribió:
I have this test line in my user crontab:
* * * * * /usr/bin/play /tmp/time.wav
a) Do you want to get owned ? :-D
Huh? What does that mean? A security risk, perhaps? :-? Not a problem here, it's a home network, only one user presently. But what could happen?
b) did you mean "aplay" ?
No, play, part of sox. I'll try the full path to the bin, just in case. Mmm, no, aplay produces the same error (it works in the CLI): ALSA lib pcm_dmix.c:1010:(snd_pcm_dmix_open) unable to open slave aplay: main:608: audio open error: Device or resource busy with play the error was: ALSA lib pcm_dmix.c:1010:(snd_pcm_dmix_open) unable to open slave play FAIL formats: can't open output file `default': snd_pcm_open error: Device or resource busy For clarification, there is a busy resource because I have a page opened in firefox with flash playback paused (SG·U Kino webisodes), which interferes with festival producing sound. I'm testing alternatives, like play, which works in the CLI, because Pulse can simultaneate sound from different applications. But the same app called from cron fails. It maybe that from inside cron it is not accessing pulse daemon.
Needless to say, that same command line on the CLI works just fine.
strace the process if possible, to see wth goes wrong, most likely the lack of some enviroment variable.
I'll try that later, I have to leave. ... I just tried in cron: SDL_AUDIODRIVER=pulse /usr/bin/aplay /tmp/time.wav also fails, same error. Ah! Found it: ALSA_CONFIG_PATH=/etc/alsa-pulse.conf SDL_AUDIODRIVER=pulse /usr/bin/aplay /tmp/time.wav This one works! You gave me the clue, I did: cer@Telcontar:~> set | grep -i pulse ALSA_CONFIG_PATH=/etc/alsa-pulse.conf SDL_AUDIODRIVER=pulse Thanks! - -- Cheers, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAk17qBMACgkQtTMYHG2NR9V61QCghHC2BBjVC59ZxLZqEcF8FRMH aVsAnjeDAIHjepViHWIUCayAjQROvrY4 =vps+ -----END PGP SIGNATURE-----
El 12/03/11 14:06, Carlos E. R. escribió:
On Saturday, 2011-03-12 at 13:38 -0300, Cristian Rodríguez wrote:
El 12/03/11 01:29, Carlos E. R. escribió:
I have this test line in my user crontab:
* * * * * /usr/bin/play /tmp/time.wav
a) Do you want to get owned ? :-D
Huh? What does that mean? A security risk, perhaps? :-?
Not a problem here, it's a home network, only one user presently. But what could happen?
/tmp is writable by any user, someone, somehow can manage to exploit the player to do nasty things, whatever the file your read from there must be created by mktemp utiliity or similar.
Ah! Found it:
ALSA_CONFIG_PATH=/etc/alsa-pulse.conf SDL_AUDIODRIVER=pulse /usr/bin/aplay /tmp/time.wav
This one works!
You gave me the clue, I did:
cer@Telcontar:~> set | grep -i pulse ALSA_CONFIG_PATH=/etc/alsa-pulse.conf SDL_AUDIODRIVER=pulse
Thanks!
Cool, glad the vague hint worked ;-) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday, 2011-03-12 at 16:45 -0300, Cristian Rodríguez wrote:
El 12/03/11 14:06, Carlos E. R. escribió:
/tmp is writable by any user, someone, somehow can manage to exploit the player to do nasty things, whatever the file your read from there must be created by mktemp utiliity or similar.
No one here, but ok, I'll learn new tricks. I have this crontab: - -0,30 * * * * /home/cer/bin/avisar_hablando hora > /dev/null and the script now does (no error checking): ... hora) TEMPORAL=`mktemp /tmp/hora.XXXXXXXXXXXXX` #echo $TEMPORAL LANG=es_ES.ISO-8859-1 LC_ALL=es_ES.ISO-8859-1 /bin/date +"Es %e de %B, y son las %k horas y %-M minutos " | espeak -v es --stdin -a 20 -w $TEMPORAL #play -q $TEMPORAL ALSA_CONFIG_PATH=/etc/alsa-pulse.conf SDL_AUDIODRIVER=pulse /usr/bin/aplay -q $TEMPORAL rm $TEMPORAL A clock that talks :-) (Spanish with English accent...)
Thanks!
Cool, glad the vague hint worked ;-)
Yep, I was thinking of more complicated things, bugs, upgrades and such. An environment var is so much easier ;-) - -- Cheers, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAk177CIACgkQtTMYHG2NR9XkJQCaA9hNW1HIuEBT7E5FKDNGCX1Z 3KAAn3sbNBAHftAv4cXtHpBVP3VPuqle =VS/Y -----END PGP SIGNATURE-----
El 12/03/11 18:56, Carlos E. R. escribió:
and the script now does (no error checking):
...
hora) TEMPORAL=`mktemp /tmp/hora.XXXXXXXXXXXXX` #echo $TEMPORAL LANG=es_ES.ISO-8859-1 LC_ALL=es_ES.ISO-8859-1 /bin/date +"Es %e de %B, y son las %k horas y %-M minutos " | espeak -v es --stdin -a 20 -w $TEMPORAL #play -q $TEMPORAL ALSA_CONFIG_PATH=/etc/alsa-pulse.conf SDL_AUDIODRIVER=pulse /usr/bin/aplay -q $TEMPORAL rm $TEMPORAL
A clock that talks :-)
All right, that's much better , if you add some proper error checking, there is a cookie waiting for you ;-P Just remember, whatever named file/directory you want to open/create/read/write/delete from /tmp or other volatile place must be created 99% of the time with mktemp or the equivalent in your favorite language, otherwise, you are doing it _wrong_ and $deity will kill a kitten ;-) See ya.. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday, 2011-03-12 at 19:27 -0300, Cristian Rodríguez wrote:
El 12/03/11 18:56, Carlos E. R. escribió:
All right, that's much better , if you add some proper error checking, there is a cookie waiting for you ;-P
:-) I added a verification for file existence, that's all. Any problem more I'll learn about in the cron mail.
Just remember, whatever named file/directory you want to open/create/read/write/delete from /tmp or other volatile place must be created 99% of the time with mktemp or the equivalent in your favorite language, otherwise, you are doing it _wrong_ and $deity will kill a kitten ;-)
Ok, I like kittens, so I'll be careful :-p There are many things that as a programmer I never had to think about. I never programmed for a multitasking or multiuser environment, not even networked. Security (of that sort) never was my concern. Nowdays I only write small things for myself. - -- Cheers, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAk19OuIACgkQtTMYHG2NR9VlcwCfc80FszIuQRY7w44SrxXpDqVQ sfUAniB0Qx5NP4+6JCsHU1nTpv+wY3hs =Tnpz -----END PGP SIGNATURE-----
El 13/03/11 18:44, Carlos E. R. escribió:
On Saturday, 2011-03-12 at 19:27 -0300, Cristian Rodríguez wrote:
El 12/03/11 18:56, Carlos E. R. escribió:
All right, that's much better , if you add some proper error checking, there is a cookie waiting for you ;-P
:-)
I added a verification for file existence, that's all.
No, :-P you need to check the return value of mktemp and not if the file exists, mktemp blabla || exit 1... see http://en.wikipedia.org/wiki/Time-of-check-to-time-of-use -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sunday, 2011-03-13 at 20:00 -0300, Cristian Rodríguez wrote:
I added a verification for file existence, that's all.
No, :-P you need to check the return value of mktemp and not if the file exists, mktemp blabla || exit 1... see http://en.wikipedia.org/wiki/Time-of-check-to-time-of-use
Wow. [reading] Mmm...? [Reading] Mmm... Will have to re-read some other day. Just mixed myself a drink. 8-) (Hic!) It is not a risk for me, this is a lone user system. If it were not, I'm sure there are so many things to be aware that I'm not aware of. - -- Cheers, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAk2AEnoACgkQtTMYHG2NR9V9PwCbBYgfv8q7rF9Ja6yZrVUXYuw1 8bcAn3crxbqV88R1T1HXn/uoD692DNsY =3+rI -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sunday, 2011-03-13 at 20:00 -0300, Cristian Rodríguez wrote:
I added a verification for file existence, that's all.
No, :-P you need to check the return value of mktemp and not if the file exists, mktemp blabla || exit 1... see http://en.wikipedia.org/wiki/Time-of-check-to-time-of-use
TEMPORAL=`mktemp /tmp/decir.wav.XXXXXXXXXXXXX` ERROR=$? case $ERROR in 0) ;; *) echo "Error $ERROR in mktemp" exit ;; esac I didn't find the error values of mktemp - in old times I did translations of values to error strings. Clients hate seeing error codes. - -- Cheers, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAk2AFy0ACgkQtTMYHG2NR9UiFQCfVx6Mb/i2U8cifyaB7OkVTM+9 weUAn0/tLIWgJ+PrDxyFJ3gbtkuJaFLE =GUb1 -----END PGP SIGNATURE-----
El 13/03/11 18:44, Carlos E. R. escribió:
On Saturday, 2011-03-12 at 19:27 -0300, Cristian Rodríguez wrote:
El 12/03/11 18:56, Carlos E. R. escribió:
All right, that's much better , if you add some proper error checking, there is a cookie waiting for you ;-P
:-)
I added a verification for file existence,
See recent aaa-base security update for an example on what happends when you forget about the measures we are talking in this thread. :) https://hermes.opensuse.org/messages/7611270 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday, 2011-03-14 at 17:48 -0300, Cristian Rodríguez wrote:
See recent aaa-base security update for an example on what happends when you forget about the measures we are talking in this thread. :)
Mmm... cute. It is not only me who makes such mistakes O:-)
- -- Cheers, Carlos E. R. (from 11.2 x86_64 "Emerald" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAk2AErcACgkQtTMYHG2NR9UEugCfRhnDF4Ub2fUZybE8FUiy4eJH GakAn1nXsqOfSXRcarZPefndkyLvm63r =1FZK -----END PGP SIGNATURE-----
participants (5)
-
Carlos E. R.
-
Carlos E. R.
-
Cristian Rodríguez
-
Malcolm
-
Patrick Shanahan