[alsa-devel] [PATCH] Emit an error message when dlopen fails.

Takashi Sakamoto o-takashi at sakamocchi.jp
Wed Nov 22 02:09:44 CET 2017


Hi,

On Nov 22 2017 07:12, Cedric Roux wrote:
> Signed-off-by: Cedric Roux <sed at free.fr>
> ---
>   src/dlmisc.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git src/dlmisc.c src/dlmisc.c
> index f154ebd0..9e8e401e 100644
> --- src/dlmisc.c
> +++ src/dlmisc.c
> @@ -81,10 +81,14 @@ void *snd_dlopen(const char *name, int mode)
>   		strcat(filename, "/");
>   		strcat(filename, name);
>   		handle = dlopen(filename, mode);
> +		if (!handle)
> +			SNDERR("snd_dlopen: %s: %s", filename, dlerror());
>   		free(filename);
>   	}
>   	if (!handle)
>   		handle = dlopen(name, mode);
> +	if (!handle)
> +		SNDERR("snd_dlopen: %s: %s", name, dlerror());
>   	return handle;
>   #else
>   	return NULL;

In my opinion, this patch is preferable, however it can always generate 
superfluous error messages when handling hook configuration on 
'alsa.conf'. For example:

$ LD_PRELOAD=./src/.libs/libasound.so.2.0.0 amixer
ALSA lib dlmisc.c:85:(snd_dlopen) snd_dlopen: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
cannot open shared object file: No such file or directory
ALSA lib dlmisc.c:85:(snd_dlopen) snd_dlopen: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
cannot open shared object file: No such file or directory
ALSA lib dlmisc.c:85:(snd_dlopen) snd_dlopen: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
cannot open shared object file: No such file or directory
ALSA lib dlmisc.c:85:(snd_dlopen) snd_dlopen: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
cannot open shared object file: No such file or directory
ALSA lib dlmisc.c:85:(snd_dlopen) snd_dlopen: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
cannot open shared object file: No such file or directory
ALSA lib dlmisc.c:85:(snd_dlopen) snd_dlopen: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
/usr/lib/x86_64-linux-gnu/alsa-lib//./src/.libs/libasound.so.2.0.0: 
cannot open shared object file: No such file or directory
Simple mixer control 'IEC958',0
   Capabilities: pswitch pswitch-joined
   Playback channels: Mono
   Mono: Playback [on]
...

When any hook configuration includes no lines with 'lib', 'snd_dlopen()' 
gets NULL as its first argument, then 'dlopen()' gets an inexistent path 
as its first argument, like:

(parsing alsa.conf)
snd_config_hooks_call()
   ->snd_dlopen(name = NULL)
     if (name == NULL)
       name = self
     filename = ALSA_PLUGIN_DIR + '/' + name
     dlopen(filename)
     (generate the error messages)

I don't know why alsa-lib is programmed as what it is, so have no idea 
to suggest better solution...

Additionally, your patch includes some issues of patch format:
* Not only your signature but also patch comment is required. The first
   line is interpreted as patch title, and the rest is as comment.
* Patches should be compliant to git-patch format. I encountered failure
   of 'git am' for this patch. Please use 'git format-patch' command to
   generate patches for posting.

When posting patches, please take care of the above.


Regards

Takashi Sakamoto


More information about the Alsa-devel mailing list