set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and

worker_rlimit_sigpending without super-user privileges testing
This commit is contained in:
Igor Sysoev 2007-08-15 20:53:30 +00:00
parent 966e2a5736
commit 4edb1d61e9

View File

@ -792,49 +792,49 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (geteuid() == 0) { if (priority && ccf->priority != 0) {
if (priority && ccf->priority != 0) { if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, "setpriority(%d) failed", ccf->priority);
"setpriority(%d) failed", ccf->priority);
}
} }
}
if (ccf->rlimit_nofile != NGX_CONF_UNSET) { if (ccf->rlimit_nofile != NGX_CONF_UNSET) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile; rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile;
rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile; rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile;
if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) { if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_NOFILE, %i) failed", "setrlimit(RLIMIT_NOFILE, %i) failed",
ccf->rlimit_nofile); ccf->rlimit_nofile);
}
} }
}
if (ccf->rlimit_core != NGX_CONF_UNSET_SIZE) { if (ccf->rlimit_core != NGX_CONF_UNSET_SIZE) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_core; rlmt.rlim_cur = (rlim_t) ccf->rlimit_core;
rlmt.rlim_max = (rlim_t) ccf->rlimit_core; rlmt.rlim_max = (rlim_t) ccf->rlimit_core;
if (setrlimit(RLIMIT_CORE, &rlmt) == -1) { if (setrlimit(RLIMIT_CORE, &rlmt) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_CORE, %i) failed", "setrlimit(RLIMIT_CORE, %i) failed",
ccf->rlimit_core); ccf->rlimit_core);
}
} }
}
#ifdef RLIMIT_SIGPENDING #ifdef RLIMIT_SIGPENDING
if (ccf->rlimit_sigpending != NGX_CONF_UNSET) { if (ccf->rlimit_sigpending != NGX_CONF_UNSET) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending; rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending;
rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending; rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending;
if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) { if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_SIGPENDING, %i) failed", "setrlimit(RLIMIT_SIGPENDING, %i) failed",
ccf->rlimit_sigpending); ccf->rlimit_sigpending);
}
} }
}
#endif #endif
if (geteuid() == 0) {
if (setgid(ccf->group) == -1) { if (setgid(ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setgid(%d) failed", ccf->group); "setgid(%d) failed", ccf->group);