Mercurial > hg > nginx
comparison src/event/ngx_event.c @ 4599:f947296f6b2b
Fixed master exit if there is no events section (ticket #150).
Instead of checking if there is events{} section present in configuration
in init_module handler we now do the same in init_conf handler. This
allows master process to detect incorrect configuration early and
reject it.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 18 Apr 2012 14:47:10 +0000 |
parents | 834049edae24 |
children | 9ee20e074a2e |
comparison
equal
deleted
inserted
replaced
4598:01a21ee8f8bb | 4599:f947296f6b2b |
---|---|
19 extern ngx_module_t ngx_epoll_module; | 19 extern ngx_module_t ngx_epoll_module; |
20 extern ngx_module_t ngx_rtsig_module; | 20 extern ngx_module_t ngx_rtsig_module; |
21 extern ngx_module_t ngx_select_module; | 21 extern ngx_module_t ngx_select_module; |
22 | 22 |
23 | 23 |
24 static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf); | |
24 static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle); | 25 static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle); |
25 static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle); | 26 static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle); |
26 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 27 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
27 | 28 |
28 static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, | 29 static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, |
29 void *conf); | 30 void *conf); |
30 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 31 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
31 static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, | 32 static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, |
32 void *conf); | 33 void *conf); |
33 | 34 |
34 static void *ngx_event_create_conf(ngx_cycle_t *cycle); | 35 static void *ngx_event_core_create_conf(ngx_cycle_t *cycle); |
35 static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf); | 36 static char *ngx_event_core_init_conf(ngx_cycle_t *cycle, void *conf); |
36 | 37 |
37 | 38 |
38 static ngx_uint_t ngx_timer_resolution; | 39 static ngx_uint_t ngx_timer_resolution; |
39 sig_atomic_t ngx_event_timer_alarm; | 40 sig_atomic_t ngx_event_timer_alarm; |
40 | 41 |
91 | 92 |
92 | 93 |
93 static ngx_core_module_t ngx_events_module_ctx = { | 94 static ngx_core_module_t ngx_events_module_ctx = { |
94 ngx_string("events"), | 95 ngx_string("events"), |
95 NULL, | 96 NULL, |
96 NULL | 97 ngx_event_init_conf |
97 }; | 98 }; |
98 | 99 |
99 | 100 |
100 ngx_module_t ngx_events_module = { | 101 ngx_module_t ngx_events_module = { |
101 NGX_MODULE_V1, | 102 NGX_MODULE_V1, |
171 }; | 172 }; |
172 | 173 |
173 | 174 |
174 ngx_event_module_t ngx_event_core_module_ctx = { | 175 ngx_event_module_t ngx_event_core_module_ctx = { |
175 &event_core_name, | 176 &event_core_name, |
176 ngx_event_create_conf, /* create configuration */ | 177 ngx_event_core_create_conf, /* create configuration */ |
177 ngx_event_init_conf, /* init configuration */ | 178 ngx_event_core_init_conf, /* init configuration */ |
178 | 179 |
179 { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } | 180 { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } |
180 }; | 181 }; |
181 | 182 |
182 | 183 |
421 | 422 |
422 return NGX_OK; | 423 return NGX_OK; |
423 } | 424 } |
424 | 425 |
425 | 426 |
427 static char * | |
428 ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) | |
429 { | |
430 if (ngx_get_conf(cycle->conf_ctx, ngx_events_module) == NULL) { | |
431 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | |
432 "no \"events\" section in configuration"); | |
433 return NGX_CONF_ERROR; | |
434 } | |
435 | |
436 return NGX_CONF_OK; | |
437 } | |
438 | |
439 | |
426 static ngx_int_t | 440 static ngx_int_t |
427 ngx_event_module_init(ngx_cycle_t *cycle) | 441 ngx_event_module_init(ngx_cycle_t *cycle) |
428 { | 442 { |
429 void ***cf; | 443 void ***cf; |
430 u_char *shared; | 444 u_char *shared; |
433 ngx_time_t *tp; | 447 ngx_time_t *tp; |
434 ngx_core_conf_t *ccf; | 448 ngx_core_conf_t *ccf; |
435 ngx_event_conf_t *ecf; | 449 ngx_event_conf_t *ecf; |
436 | 450 |
437 cf = ngx_get_conf(cycle->conf_ctx, ngx_events_module); | 451 cf = ngx_get_conf(cycle->conf_ctx, ngx_events_module); |
438 | |
439 if (cf == NULL) { | |
440 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | |
441 "no \"events\" section in configuration"); | |
442 return NGX_ERROR; | |
443 } | |
444 | |
445 ecf = (*cf)[ngx_event_core_module.ctx_index]; | 452 ecf = (*cf)[ngx_event_core_module.ctx_index]; |
446 | 453 |
447 if (!ngx_test_config && ngx_process <= NGX_PROCESS_MASTER) { | 454 if (!ngx_test_config && ngx_process <= NGX_PROCESS_MASTER) { |
448 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, | 455 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, |
449 "using the \"%s\" event method", ecf->name); | 456 "using the \"%s\" event method", ecf->name); |
1114 return NGX_CONF_OK; | 1121 return NGX_CONF_OK; |
1115 } | 1122 } |
1116 | 1123 |
1117 | 1124 |
1118 static void * | 1125 static void * |
1119 ngx_event_create_conf(ngx_cycle_t *cycle) | 1126 ngx_event_core_create_conf(ngx_cycle_t *cycle) |
1120 { | 1127 { |
1121 ngx_event_conf_t *ecf; | 1128 ngx_event_conf_t *ecf; |
1122 | 1129 |
1123 ecf = ngx_palloc(cycle->pool, sizeof(ngx_event_conf_t)); | 1130 ecf = ngx_palloc(cycle->pool, sizeof(ngx_event_conf_t)); |
1124 if (ecf == NULL) { | 1131 if (ecf == NULL) { |
1145 return ecf; | 1152 return ecf; |
1146 } | 1153 } |
1147 | 1154 |
1148 | 1155 |
1149 static char * | 1156 static char * |
1150 ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) | 1157 ngx_event_core_init_conf(ngx_cycle_t *cycle, void *conf) |
1151 { | 1158 { |
1152 ngx_event_conf_t *ecf = conf; | 1159 ngx_event_conf_t *ecf = conf; |
1153 | 1160 |
1154 #if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL) | 1161 #if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL) |
1155 int fd; | 1162 int fd; |