# Difficulties with LD\_PRELOAD and Intercepting Sendfile

**URL:** <https://www.ruby-forum.com/t/difficulties-with-ld-preload-and-intercepting-sendfile/229392>\
**Category:** NGINX\
**Created:** [January 15, 2013, 11:04pm UTC](https://www.ruby-forum.com/t/difficulties-with-ld-preload-and-intercepting-sendfile/229392 "2013-01-15T23:04:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Cassell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@Ben\_Cassell](https://www.ruby-forum.com/u/Ben_Cassell)\
**Post date:** [January 15, 2013, 11:04pm UTC](https://www.ruby-forum.com/t/difficulties-with-ld-preload-and-intercepting-sendfile/229392/1 "2013-01-15T23:04:14Z")

</div>

We have a custom library shim that we are using to intercept libc calls  
from applications. We are loading this shim beneath nginx 1.2.3 using  
the LD\_PRELOAD flag on both Linux and FreeBSD environments.

After setting env LD\_PRELOAD in the nginx.conf file, our shim is able to  
intercept a host of libc calls including read and write (as expected).  
On FreeBSD, sendfile is also intercepted from nginx as expected by our  
shim.

On Linux however, our library is never reached when calling sendfile,  
even though we have verified that sendfile is being included from  
sys/sendfile.h (both through checking the bindings of the calls  
themselves using debugging tools and through tracing the code inside  
…/nginx-1.2.3/src/os/unix/ngx\_linux\_sendfile\_chain.c).

Calling sendfile through other applications results in a successful  
redirection to our library.

I’m wondering if anyone has encountered difficulty with intercepting  
sendfile from nginx on Linux before, or if this is possibly an oversight  
on our part.

Thanks in advance for any insight,  
Ben
