Skip to content

Commit

Permalink
fixed the compatible problem with nginx-1.3.10
Browse files Browse the repository at this point in the history
most of the changes are in the tcp log module
  • Loading branch information
yaoweibin committed Jan 3, 2013
1 parent ae321fd commit fcf1527
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 10 deletions.
6 changes: 6 additions & 0 deletions ngx_tcp.h
Expand Up @@ -156,6 +156,12 @@ typedef struct {
time_t error_log_time;
} ngx_tcp_log_t;

typedef struct {
u_char *start;
u_char *pos;
u_char *last;
} ngx_tcp_log_buf_t;

typedef struct {
ngx_array_t *logs; /* array of ngx_tcp_log_t */

Expand Down
56 changes: 47 additions & 9 deletions ngx_tcp_core_module.c
Expand Up @@ -790,9 +790,12 @@ ngx_tcp_log_set_access_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_tcp_core_srv_conf_t *cscf = conf;
ngx_tcp_log_srv_conf_t *lscf = cscf->access_log;

ssize_t buf;
ssize_t size;
ngx_str_t *value, name;
ngx_tcp_log_t *log;
#if (nginx_version) >= 1003010
ngx_tcp_log_buf_t *buffer;
#endif

value = cf->args->elts;

Expand Down Expand Up @@ -836,28 +839,63 @@ ngx_tcp_log_set_access_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
name.len = value[2].len - 7;
name.data = value[2].data + 7;

buf = ngx_parse_size(&name);
size = ngx_parse_size(&name);

if (buf == NGX_ERROR) {
if (size == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid parameter \"%V\"", &value[2]);
return NGX_CONF_ERROR;
}

if (log->file->buffer && log->file->last - log->file->pos != buf) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"access_log \"%V\" already defined "
"with different buffer size", &value[1]);
#if (nginx_version) >= 1003010
if (log->file->data) {

buffer = log->file->data;

if (buffer->last - buffer->pos != size) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"access_log \"%V\" already defined "
"with different buffer size", &value[1]);
return NGX_CONF_ERROR;
}

return NGX_CONF_OK;
}

buffer = ngx_pcalloc(cf->pool, sizeof(ngx_tcp_log_buf_t));
if (buffer == NULL) {
return NGX_CONF_ERROR;
}

buffer->start = ngx_palloc(cf->pool, size);
if (buffer->start == NULL) {
return NGX_CONF_ERROR;
}

log->file->buffer = ngx_palloc(cf->pool, buf);
buffer->pos = buffer->start;
buffer->last = buffer->start + size;

log->file->data = buffer;
#else
if (log->file->buffer) {
if (log->file->last - log->file->pos != size) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"access_log \"%V\" already defined "
"with different buffer size", &value[1]);
return NGX_CONF_ERROR;
}

return NGX_CONF_OK;
}

log->file->buffer = ngx_palloc(cf->pool, size);
if (log->file->buffer == NULL) {
return NGX_CONF_ERROR;
}

log->file->pos = log->file->buffer;
log->file->last = log->file->buffer + buf;
log->file->last = log->file->buffer + size;
#endif
}

return NGX_CONF_OK;
Expand Down
31 changes: 30 additions & 1 deletion ngx_tcp_log.c
Expand Up @@ -20,7 +20,10 @@ ngx_tcp_log_handler(ngx_tcp_session_t *s)
ngx_connection_t *c;
ngx_tcp_log_t *log;
ngx_open_file_t *file;
ngx_tcp_log_srv_conf_t *lscf;
#if (nginx_version) >= 1003010
ngx_tcp_log_buf_t *buffer;
#endif
ngx_tcp_log_srv_conf_t *lscf;
ngx_tcp_core_srv_conf_t *cscf;

ngx_log_debug0(NGX_LOG_DEBUG_TCP, s->connection->log, 0,
Expand Down Expand Up @@ -63,6 +66,31 @@ ngx_tcp_log_handler(ngx_tcp_session_t *s)

file = log[l].file;

#if (nginx_version) >= 1003010
if (file && file->data) {

buffer = file->data;

if (len > (size_t) (buffer->last - buffer->pos)) {

ngx_tcp_log_write(s, &log[l], buffer->start,
buffer->pos - buffer->start);

buffer->pos = buffer->start;
}

if (len <= (size_t) (buffer->last - buffer->pos)) {

p = buffer->pos;

p = ngx_tcp_log_fill(s, p);

buffer->pos = p;

continue;
}
}
#else
if (file && file->buffer) {

if (len > (size_t) (file->last - file->pos)) {
Expand All @@ -84,6 +112,7 @@ ngx_tcp_log_handler(ngx_tcp_session_t *s)
continue;
}
}
#endif

line = ngx_pnalloc(s->pool, len);
if (line == NULL) {
Expand Down

0 comments on commit fcf1527

Please sign in to comment.