include/global.h - don't define timeval and timespec structures for !glibc

On request from John Spencer <maillist-alsa@barfooze.de> .

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
conf.c: use portable way to initialize recursive mutex

PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is not in POSIX, as _NP
(non-portable) suggests.

exposing such a symbol in musl libc would lock in the ABI for all
times and makes it impossible to do future changes to the under-
lying struct without hideous symbol versioning hacks.

use the portable way instead: pthread_once was designed for such
cases.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Tested-by: John Spencer <maillist-alsa@barfooze.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
pcm_file: fix SEGFAULT if file option is missing while infile is not.

Commit 5c5f1358123af69155267463a0b6254ad9cbecc4 requires both file and
infile options to be missing to report a failure.
In fact, only file option is mandatory and should be checked there.
Otherwise, NULL file triggers segfault in
snd_pcm_file_replace_fname() called from
snd_pcm_file_open_output_file().
infile option is optional, so don't report fatal error if it's missing.

Signed-off-by: Andrey Mazo <mazo@telum.ru>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm_file: fixed memory leak.

Valgrind report for this leak was:

Command: aplay -Dfile:'/tmp/qqq',raw qqq.wav

14 bytes in 1 blocks are definitely lost in loss record 1 of 2
   at 0x402BF5C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
   by 0x40D7557: snd_pcm_file_hw_params (in /usr/lib/libasound.so.2.0.0)
   by 0x40BA093: _snd_pcm_hw_params_internal (in /usr/lib/libasound.so.2.0.0)
   by 0x40AB831: snd_pcm_hw_params (in /usr/lib/libasound.so.2.0.0)
   by 0x804C523: ??? (in /usr/bin/aplay)
   by 0x804E5B7: ??? (in /usr/bin/aplay)
   by 0x804FC8C: ??? (in /usr/bin/aplay)
   by 0x80520FB: ??? (in /usr/bin/aplay)
   by 0x4184942: (below main) (libc-start.c:226)

Signed-off-by: Andrey Mazo <mazo@telum.ru>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm_file: don't touch infile on playback and output file on capture.

Commit 1d80c5b901baf7e1b7998dfa518532fbd64e4283 message describes
behaviour in case of specified infile option as
'No file writes will take place in this case'.
But this is clearly not the case as output file gets truncated while
running `arecord -Dtestin >/dev/null`, where "testin" is defined as
pcm.testin {
	type file
	slave.pcm null
	file "/tmp/qqqq.out"
	infile "/tmp/qqqq.in"
	format "raw"
}

Besides that, the existing behaviour is rather counterintuitive,
requiring both output and input files to exist and making access to them
regardless of playback or capture intention.
Also, it's very confusing to get output file truncated while trying to
just capture from the device.

Current changeset introduces the following behaviour:
 - output file ("file" option) is only (p)open()'ed for writing
   only on playback to the device
 - any data is written to the output file descriptor
   (provided with "file" option) only on playback to the device
 - input file ("infile" option) is only open()'ed for reading only on
   capture from the device
 - any data is read from the input file descriptor
   (provided with the "infile" option) only on capture from the device

Signed-off-by: Andrey Mazo <mazo@telum.ru>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm_file: document new argument to snd_pcm_file_open().

Document function argument, added in commit
4081be0b87ab9fa53a8906e66bc240f18a7a9a54.

Signed-off-by: Andrey Mazo <mazo@telum.ru>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
dmix: Don't use assert() and abort()

We seem to still have some races at closing a dmix stream, but
aborting is the worst option.  Let's make not melt down.

Reference: https://bugzilla.novell.com/show_bug.cgi?id=852446
Signed-off-by: Takashi Iwai <tiwai@suse.de>