diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ngx_config.h | 9 | ||||
-rw-r--r-- | src/core/ngx_cycle.c | 21 | ||||
-rw-r--r-- | src/core/ngx_cycle.h | 1 |
3 files changed, 27 insertions, 4 deletions
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h index a6a9f5d27..8b802aa9c 100644 --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -116,10 +116,11 @@ typedef intptr_t ngx_flag_t; #define INET_ADDRSTRLEN 16 #endif -#define NGX_MAXHOSTNAMELEN 64 -/* -#define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN -*/ +#ifdef MAXHOSTNAMELEN +#define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN +#else +#define NGX_MAXHOSTNAMELEN 256 +#endif #if ((__GNU__ == 2) && (__GNUC_MINOR__ < 8)) diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index edcb6b5b0..9cdbb2d95 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -57,6 +57,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle) ngx_listening_t *ls, *nls; ngx_core_conf_t *ccf, *old_ccf; ngx_core_module_t *module; + char hostname[NGX_MAXHOSTNAMELEN]; log = old_cycle->log; @@ -170,6 +171,26 @@ ngx_init_cycle(ngx_cycle_t *old_cycle) } + if (gethostname(hostname, NGX_MAXHOSTNAMELEN) == -1) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "gethostname() failed"); + ngx_destroy_pool(pool); + return NULL; + } + + /* on Linux gethostname() silently truncates name that does not fit */ + + hostname[NGX_MAXHOSTNAMELEN - 1] = '\0'; + cycle->hostname.len = ngx_strlen(hostname); + + cycle->hostname.data = ngx_palloc(pool, cycle->hostname.len); + if (cycle->hostname.data == NULL) { + ngx_destroy_pool(pool); + return NULL; + } + + ngx_memcpy(cycle->hostname.data, hostname, cycle->hostname.len); + + for (i = 0; ngx_modules[i]; i++) { if (ngx_modules[i]->type != NGX_CORE_MODULE) { continue; diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h index 820ebbe0d..845ce8771 100644 --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -62,6 +62,7 @@ struct ngx_cycle_s { ngx_str_t conf_file; ngx_str_t root; ngx_str_t lock_file; + ngx_str_t hostname; }; |