{module dev}include <sys/time.h> on 32bit linux cause segmentation fault?

Igor Sysoev igor at sysoev.ru
Thu May 26 09:18:11 MSD 2011


On Thu, May 26, 2011 at 11:36:42AM +0800, Conan wrote:
> hi, I'm wring a nginx module which is hooked at
> NGX_HTTP_ACCESS_PHASE. Segmentation fault happened when calling
> ngx_log_error(NGX_LOG_ERR, r->connection->log, "xxx")  in my module's
> handler(which will handle every request). I found r->connection->log = 0x0
>  when debug with gdb.
> 
> On 64bit centos/ubuntu/macos module works well.  Segmentation fault seem
> only occurs on 32bit linux(ubuntu).
> 
> When I comment out #include <sys/time.h>, segmentation fault disappeared.
> Attachment is my module's skeleton.

> #include <sys/time.h> 
> #include <ngx_config.h>
> #include <ngx_core.h>
> #include <ngx_http.h>

You should not include any files before ngx_config.h.
src/os/unix/ngx_linux_config.h does it for you:

#define _FILE_OFFSET_BITS  64

#include <sys/types.h>
#include <sys/time.h>

I believe, <sys/time.h> includes another file (may be <sys/types.h>
which depends on _FILE_OFFSET_BITS and your module is built with
32-bit off_t on 32-bit platform while nginx is build with 64-bit off_t.


-- 
Igor Sysoev



More information about the nginx-devel mailing list