I am using LD_PRELOAD, and I am seeing a difference between bash and dash when using the system() command.
Let's consider this simple C program:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
system("echo $LD_PRELOAD > /tmp/blah.txt");
return 0;
}
I would start my test program like this:
LD_PRELOAD=preload.so ./test
Both in bash and dash, I got:
~$ cat /tmp/blah.txt
preload.so
So far so good except that the LD_PRELOAD is not applied to the command given to system when dash is the shell. I mean
- if /bin/sh points to /bin/bash, LD_PRELOAD is applied to the command given to system()
- if /bin/sh points to /bin/dash, LD_PRELOAD is NOT applied to the command given to system().
My preload.so library override open(). It is executed with the test program when bash is used (/bin/sh=/bin/bash), but not when dash is used (/bin/sh=/bin/dash).
I am guessing that bash and dash might treat the environment variables passed to execve differently, but I can not find a way with dash to have LD_PRELOAD applied to the command given to system... Unfortunately I have to use dash, and using bash is not an option.