I just write a special FILE_PRELOAD utility to solve my problem.
$: FILE_PRELOAD -C "execve+open+stat:/usr/bin/prog_b:/usr/bin/prog_b.old" ./prog_a
it generates c++ code, then compiles it and then LD_PRELOAD the result lib.so file before run ./prog_a.
Using it you can hook the next calls:
- open,fopen,fopen64
- opendir,mkdir,rmdir
- execve
- unlink,unlinkat
- stat,lstat,lstat64,_lxstat,_lxstat64,stat64
- _xstat,_xstat64,__fxstatat
- freopen,freopen64
Please, run docs/tut.sh firstly (it's a tutorial for FP utility).