comparison src/core/ngx_cycle.c @ 2011:b56d4b1ebac7

$hostname variable
author Igor Sysoev <igor@sysoev.ru>
date Fri, 16 May 2008 14:39:06 +0000
parents 45db41a0591c
children 2a92804f4109 0ebecd0c3410
comparison
equal deleted inserted replaced
2010:bd6cc5370fc1 2011:b56d4b1ebac7
55 ngx_list_part_t *part, *opart; 55 ngx_list_part_t *part, *opart;
56 ngx_open_file_t *file; 56 ngx_open_file_t *file;
57 ngx_listening_t *ls, *nls; 57 ngx_listening_t *ls, *nls;
58 ngx_core_conf_t *ccf, *old_ccf; 58 ngx_core_conf_t *ccf, *old_ccf;
59 ngx_core_module_t *module; 59 ngx_core_module_t *module;
60 char hostname[NGX_MAXHOSTNAMELEN];
60 61
61 log = old_cycle->log; 62 log = old_cycle->log;
62 63
63 pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log); 64 pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log);
64 if (pool == NULL) { 65 if (pool == NULL) {
166 cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *)); 167 cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *));
167 if (cycle->conf_ctx == NULL) { 168 if (cycle->conf_ctx == NULL) {
168 ngx_destroy_pool(pool); 169 ngx_destroy_pool(pool);
169 return NULL; 170 return NULL;
170 } 171 }
172
173
174 if (gethostname(hostname, NGX_MAXHOSTNAMELEN) == -1) {
175 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "gethostname() failed");
176 ngx_destroy_pool(pool);
177 return NULL;
178 }
179
180 /* on Linux gethostname() silently truncates name that does not fit */
181
182 hostname[NGX_MAXHOSTNAMELEN - 1] = '\0';
183 cycle->hostname.len = ngx_strlen(hostname);
184
185 cycle->hostname.data = ngx_palloc(pool, cycle->hostname.len);
186 if (cycle->hostname.data == NULL) {
187 ngx_destroy_pool(pool);
188 return NULL;
189 }
190
191 ngx_memcpy(cycle->hostname.data, hostname, cycle->hostname.len);
171 192
172 193
173 for (i = 0; ngx_modules[i]; i++) { 194 for (i = 0; ngx_modules[i]; i++) {
174 if (ngx_modules[i]->type != NGX_CORE_MODULE) { 195 if (ngx_modules[i]->type != NGX_CORE_MODULE) {
175 continue; 196 continue;