aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_cycle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ngx_cycle.c')
-rw-r--r--src/core/ngx_cycle.c21
1 files changed, 21 insertions, 0 deletions
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;