bugfix: when syslog was enabled in the "error_log" directive for nginx 1.7.1+, use of init_worker_by_lua or ngx.timer.at() would lead to segmentation faults. thanks shun.zhang for the report in #426.

This commit is contained in:
Yichun Zhang (agentzh) 2014-10-06 23:26:16 -07:00
Родитель 8a4e8a72d4
Коммит 6706ec2148
4 изменённых файлов: 85 добавлений и 1 удалений

Просмотреть файл

@ -224,11 +224,21 @@ ngx_http_lua_init_worker(ngx_cycle_t *cycle)
r->loc_conf = http_ctx.loc_conf;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
#if defined(nginx_version) && nginx_version >= 1003014
ngx_http_set_connection_log(r->connection, clcf->error_log);
#else
c->log->file = clcf->error_log->file;
if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
c->log->log_level = clcf->error_log->log_level;
}
#endif
if (top_clcf->resolver) {
clcf->resolver = top_clcf->resolver;
}

Просмотреть файл

@ -295,11 +295,21 @@ ngx_http_lua_timer_handler(ngx_event_t *ev)
r->loc_conf = tctx.loc_conf;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
#if defined(nginx_version) && nginx_version >= 1003014
ngx_http_set_connection_log(r->connection, clcf->error_log);
#else
c->log->file = clcf->error_log->file;
if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
c->log->log_level = clcf->error_log->log_level;
}
#endif
dd("lmcf: %p", lmcf);
ctx = ngx_http_lua_create_ctx(r);

Просмотреть файл

@ -13,7 +13,7 @@ our $StapScript = $t::StapThread::StapScript;
repeat_each(2);
plan tests => repeat_each() * (blocks() * 8 + 76);
plan tests => repeat_each() * (blocks() * 8 + 72);
#no_diff();
no_long_string();
@ -2162,3 +2162,33 @@ qr/\[lua\] content_by_lua:\d+: elapsed: .*?, context: ngx\.timer/,
"lua release ngx.ctx at ref ",
]
=== TEST 32: syslog error log
--- http_config
#error_log syslog:server=127.0.0.1:12345 error;
--- config
location /t {
content_by_lua '
local function f()
ngx.log(ngx.ERR, "Bad bad bad")
end
ngx.timer.at(0, f)
ngx.sleep(0.001)
ngx.say("ok")
';
}
--- log_level: error
--- error_log_file: syslog:server=127.0.0.1:12345
--- udp_listen: 12345
--- udp_query eval: qr/Bad bad bad/
--- udp_reply: hello
--- wait: 0.1
--- request
GET /t
--- response_body
ok
--- error_log
Bad bad bad
--- skip_nginx: 4: < 1.7.1

Просмотреть файл

@ -706,3 +706,37 @@ ok
[alert]
[emerg]
=== TEST 18: syslog error log
--- http_config
#error_log syslog:server=127.0.0.1:12345 error;
init_worker_by_lua '
done = false
os.execute("sleep 0.1")
ngx.log(ngx.ERR, "Bad bad bad")
done = true
';
--- config
location /t {
content_by_lua '
while not done do
ngx.sleep(0.001)
end
ngx.say("ok")
';
}
--- log_level: error
--- error_log_file: syslog:server=127.0.0.1:12345
--- udp_listen: 12345
--- udp_query eval: qr/Bad bad bad/
--- udp_reply: hello
--- wait: 0.1
--- request
GET /t
--- response_body
ok
--- error_log
Bad bad bad
--- skip_nginx: 4: < 1.7.1