Mercurial > hg > nginx
comparison src/core/nginx.c @ 91:637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 19 May 2003 16:39:14 +0000 |
parents | 37530da31268 |
children | 19cc647ecd91 |
comparison
equal
deleted
inserted
replaced
90:37530da31268 | 91:637625a2acdb |
---|---|
2 #include <nginx.h> | 2 #include <nginx.h> |
3 | 3 |
4 #include <ngx_config.h> | 4 #include <ngx_config.h> |
5 | 5 |
6 #include <ngx_core.h> | 6 #include <ngx_core.h> |
7 #include <ngx_connection.h> | |
7 #include <ngx_os_init.h> | 8 #include <ngx_os_init.h> |
8 #include <ngx_string.h> | 9 #include <ngx_string.h> |
9 #include <ngx_errno.h> | 10 #include <ngx_errno.h> |
10 #include <ngx_time.h> | 11 #include <ngx_time.h> |
11 #include <ngx_log.h> | 12 #include <ngx_log.h> |
12 #include <ngx_alloc.h> | 13 #include <ngx_alloc.h> |
13 #include <ngx_array.h> | 14 #include <ngx_array.h> |
14 #include <ngx_socket.h> | 15 #include <ngx_socket.h> |
15 #include <ngx_server.h> | 16 #include <ngx_server.h> |
16 #include <ngx_connection.h> | |
17 #include <ngx_listen.h> | 17 #include <ngx_listen.h> |
18 #include <ngx_conf_file.h> | 18 #include <ngx_conf_file.h> |
19 | 19 |
20 /* STUB */ | 20 /* STUB */ |
21 #include <ngx_http.h> | 21 #include <ngx_http.h> |
31 u_int ngx_sendfile_flags; | 31 u_int ngx_sendfile_flags; |
32 | 32 |
33 ngx_server_t ngx_server; | 33 ngx_server_t ngx_server; |
34 /* */ | 34 /* */ |
35 | 35 |
36 ngx_log_t ngx_log; | 36 ngx_log_t ngx_log; |
37 ngx_pool_t *ngx_pool; | 37 ngx_pool_t *ngx_pool; |
38 void ****ngx_conf_ctx; | |
39 | |
40 | |
41 ngx_os_io_t ngx_io; | |
38 | 42 |
39 | 43 |
40 int ngx_max_module; | 44 int ngx_max_module; |
41 void *ctx_conf; | 45 void *ctx_conf; |
42 | 46 |
53 | 57 |
54 /* STUB */ | 58 /* STUB */ |
55 ngx_log.log_level = NGX_LOG_DEBUG; | 59 ngx_log.log_level = NGX_LOG_DEBUG; |
56 | 60 |
57 if (ngx_os_init(&ngx_log) == NGX_ERROR) { | 61 if (ngx_os_init(&ngx_log) == NGX_ERROR) { |
58 exit(1); | 62 return 1; |
59 } | 63 } |
60 | 64 |
61 ngx_pool = ngx_create_pool(16 * 1024, &ngx_log); | 65 ngx_pool = ngx_create_pool(16 * 1024, &ngx_log); |
62 /* */ | 66 /* */ |
63 | |
64 #if (WIN32) | |
65 | |
66 if (ngx_init_sockets(&ngx_log) == NGX_ERROR) { | |
67 exit(1); | |
68 } | |
69 | |
70 #else | |
71 | |
72 ngx_set_signals(&ngx_log); | |
73 | |
74 #endif | |
75 | |
76 ngx_init_array(ngx_listening_sockets, ngx_pool, 10, sizeof(ngx_listen_t), | |
77 1); | |
78 | 67 |
79 ngx_max_module = 0; | 68 ngx_max_module = 0; |
80 for (i = 0; ngx_modules[i]; i++) { | 69 for (i = 0; ngx_modules[i]; i++) { |
81 ngx_modules[i]->index = ngx_max_module++; | 70 ngx_modules[i]->index = ngx_max_module++; |
82 } | 71 } |
83 | 72 |
84 ngx_memzero(&conf, sizeof(ngx_conf_t)); | 73 /* life cycle */ |
85 | 74 |
86 ngx_test_null(conf.args, ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)), | 75 { |
87 1); | 76 ngx_init_array(ngx_listening_sockets, |
88 | 77 ngx_pool, 10, sizeof(ngx_listen_t), |
89 ngx_test_null(conf.ctx, | 78 1); |
90 ngx_pcalloc(ngx_pool, ngx_max_module * sizeof(void *)), | 79 |
91 1); | 80 ngx_memzero(&conf, sizeof(ngx_conf_t)); |
92 | 81 |
93 conf.pool = ngx_pool; | 82 ngx_test_null(conf.args, |
94 conf.log = &ngx_log; | 83 ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)), |
95 conf.module_type = NGX_CORE_MODULE_TYPE; | 84 1); |
96 conf.cmd_type = NGX_MAIN_CONF; | 85 |
97 | 86 ngx_test_null(ngx_conf_ctx, |
98 conf_file.len = sizeof("nginx.conf") - 1; | 87 ngx_pcalloc(ngx_pool, ngx_max_module * sizeof(void *)), |
99 conf_file.data = "nginx.conf"; | 88 1); |
100 | 89 |
101 if (ngx_conf_parse(&conf, &conf_file) != NGX_CONF_OK) { | 90 conf.ctx = ngx_conf_ctx; |
102 return 1; | 91 conf.pool = ngx_pool; |
103 } | 92 conf.log = &ngx_log; |
104 | 93 conf.module_type = NGX_CORE_MODULE_TYPE; |
105 ngx_init_temp_number(); | 94 conf.cmd_type = NGX_MAIN_CONF; |
106 | 95 |
107 for (i = 0; ngx_modules[i]; i++) { | 96 conf_file.len = sizeof("nginx.conf") - 1; |
108 if (ngx_modules[i]->init_module) { | 97 conf_file.data = "nginx.conf"; |
109 if (ngx_modules[i]->init_module(ngx_pool) == NGX_ERROR) { | 98 |
110 return 1; | 99 if (ngx_conf_parse(&conf, &conf_file) != NGX_CONF_OK) { |
111 } | 100 return 1; |
112 } | 101 } |
113 } | 102 |
114 | 103 ngx_init_temp_number(); |
115 ngx_open_listening_sockets(&ngx_log); | 104 |
116 | 105 ngx_io = ngx_os_io; |
117 /* TODO: daemon */ | 106 |
118 | 107 for (i = 0; ngx_modules[i]; i++) { |
119 /* TODO: fork */ | 108 if (ngx_modules[i]->init_module) { |
120 | 109 if (ngx_modules[i]->init_module(ngx_pool) == NGX_ERROR) { |
121 ngx_pre_thread(&ngx_listening_sockets, ngx_pool, &ngx_log); | 110 return 1; |
122 | 111 } |
123 /* TODO: threads */ | 112 } |
124 | 113 } |
125 /* STUB */ | 114 |
126 ngx_worker(&ngx_log); | 115 ngx_open_listening_sockets(&ngx_log); |
116 | |
117 /* TODO: daemon, once only */ | |
118 | |
119 /* TODO: fork */ | |
120 | |
121 ngx_pre_thread(&ngx_listening_sockets, ngx_pool, &ngx_log); | |
122 | |
123 /* TODO: threads */ | |
124 | |
125 /* STUB */ | |
126 ngx_worker(&ngx_log); | |
127 } | |
127 | 128 |
128 return 0; | 129 return 0; |
129 } | 130 } |
130 | 131 |
131 #if !(WIN32) | |
132 static void ngx_set_signals(ngx_log_t *log) | |
133 { | |
134 struct sigaction sa; | |
135 | |
136 ngx_memzero(&sa, sizeof(struct sigaction)); | |
137 sa.sa_handler = SIG_IGN; | |
138 sigemptyset(&sa.sa_mask); | |
139 if (sigaction(SIGPIPE, &sa, NULL) == -1) { | |
140 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | |
141 "sigaction(SIGPIPE, SIG_IGN) failed"); | |
142 exit(1); | |
143 } | |
144 } | |
145 #endif | |
146 | 132 |
147 static void ngx_open_listening_sockets(ngx_log_t *log) | 133 static void ngx_open_listening_sockets(ngx_log_t *log) |
148 { | 134 { |
149 int times, failed, reuseaddr, i; | 135 int times, failed, reuseaddr, i; |
150 ngx_err_t err; | 136 ngx_err_t err; |