assume that I have a tar.gz archive that contains 1 shared library. My intention, is to untar it "on-the-fly" and the .so (that is extracted), put it on LD_PRELOAD and the run my code.
So, I made a script:
#!/bin/bash
myTarLib=$1
tar -zxf $myTarLib --to-command "export LD_PRELOAD="
./run_the_func
The execution of the run_the_exec
didn't use the .so from the tar.
I have the impression that the "--to-command" option creates another shell; is it correct?
Do you have any suggestion on how I could do it? The important part, is that i don't want to have the .so on the disk.
Thanks in advance!
I found a solution to the problem... The use of
memfd_create
The
memfd_create
creates a file descriptor. Then this can be used to store any data in it. The manpage is here.In order to use it, you need to create a C-Wrapper that takes care of the untar (in my case). The code is:
Now the idea is that the C code above, will run the untar and will store the result to the fd. Once you have finished using it, you simply hit a number and the C code exits. During the exit, all the fds are released, so the untar-ed library is "gone".