On Mon, 19 Jul 2021 05:46:03 -0700, Frederick Gotham wrote:
I have a special audio driver that needs additional clean-up when the ALSA (Advanced Linux Sound Architecture) function, 'snd_pcm_close', is called.
This additional clean-up can't take place inside the C code for the audio driver, and so it must happen inside the ALSA library 'libasound.so' whenever a process calls 'snd_pcm_close'. To make things a little more complicated, 'libasound.so' is a pre-compiled binary for which I don't have the source code (a 3rd party has already made alterations to 'alsa-lib' and they won't give me the source code).
I could create a small shared library file with just one function 'snd_pcm_close', and then when I start any program that uses ALSA, I can use LD_PRELOAD as follows:
LD_PRELOAD=my_small_library.so some_program_that_uses_sound
This would be fine if I only had one or two programs that use sound, and if this rarely changed.
I'm looking for a solution though that will work with *any* program that links with 'libasound.so'. So here's what I did:
[snip]
ISTM that you have overlooked the advantages of LD_PRELOAD and minimized
the disadvantages of your proposed solution.
For your solution to work, you need to rename the original libasound library. Each time your distribution or software supplier updates libasound, you have
to remember to preserve your stand-in libasound.so and rename the distributor supplied libasound.so to the name you chose to work with. This seems dangerous to me, as it presumes that you will remember to do this each time you update the official libasound.so.
OTOH, /proper/ use of LD_PRELOAD would permit you to install a library that will intercept and interceed in any snd_pcm_close() calls from running processes, without requiring manual intervention with each libasound module refresh.
The key would be to add the path to your intercept library into the /etc/ld.so.preload file (see ld.so(8) for details) to ensure that all processes have your intercept library loaded ahead of, and instead of, the libasound library.
Alternatively, you /could/ alter the various login-related scripts to set the LD_PRELOAD environment variable appropriately, but this seems chancier, in that you need to change /all/ the login environment setup scripts, both commandline and
GUI.
--
Lew Pitcher
"In Skills, We Trust"
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)