Core: working_directory validation

Previously, an invalid working_directory was only detected on worker
process startup: if chdir() failed, worker processes exited and were
not respawned, while "nginx -t" reported success.

Now the directory is checked during configuration parsing.  Note that
this doesn't cover insufficient permissions for worker processes.
This commit is contained in:
Sergey Kandaurov committed 2026-10-21 11:48:28 +04:00
1 parent 0e20f1fb0f
commit 80f0b3b840
1 file changed
+16
+16
View File
@@ -1232,9 +1232,25 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
if (ccf->working_directory.len) {
ngx_file_info_t fi;
if (ngx_conf_full_name(cycle, &ccf->working_directory, 0) != NGX_OK) {
return NGX_CONF_ERROR;
}
if (ngx_file_info(ccf->working_directory.data, &fi) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
ngx_file_info_n " \"%s\" failed",
ccf->working_directory.data);
return NGX_CONF_ERROR;
}
if (!ngx_is_dir(&fi)) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"\"%s\" is not a directory",
ccf->working_directory.data);
return NGX_CONF_ERROR;
}
}