set worker_priority, worker_rlimit_nofile, worker_rlimit_core, and
worker_rlimit_sigpending without super-user privileges testing
Igor Sysoev
14 years ago
791 | 791 | |
792 | 792 | ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
793 | 793 | |
794 | if (priority && ccf->priority != 0) { | |
795 | if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) { | |
796 | ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
797 | "setpriority(%d) failed", ccf->priority); | |
798 | } | |
799 | } | |
800 | ||
801 | if (ccf->rlimit_nofile != NGX_CONF_UNSET) { | |
802 | rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile; | |
803 | rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile; | |
804 | ||
805 | if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) { | |
806 | ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
807 | "setrlimit(RLIMIT_NOFILE, %i) failed", | |
808 | ccf->rlimit_nofile); | |
809 | } | |
810 | } | |
811 | ||
812 | if (ccf->rlimit_core != NGX_CONF_UNSET_SIZE) { | |
813 | rlmt.rlim_cur = (rlim_t) ccf->rlimit_core; | |
814 | rlmt.rlim_max = (rlim_t) ccf->rlimit_core; | |
815 | ||
816 | if (setrlimit(RLIMIT_CORE, &rlmt) == -1) { | |
817 | ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
818 | "setrlimit(RLIMIT_CORE, %i) failed", | |
819 | ccf->rlimit_core); | |
820 | } | |
821 | } | |
822 | ||
823 | #ifdef RLIMIT_SIGPENDING | |
824 | if (ccf->rlimit_sigpending != NGX_CONF_UNSET) { | |
825 | rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending; | |
826 | rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending; | |
827 | ||
828 | if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) { | |
829 | ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
830 | "setrlimit(RLIMIT_SIGPENDING, %i) failed", | |
831 | ccf->rlimit_sigpending); | |
832 | } | |
833 | } | |
834 | #endif | |
835 | ||
794 | 836 | if (geteuid() == 0) { |
795 | if (priority && ccf->priority != 0) { | |
796 | if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) { | |
797 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
798 | "setpriority(%d) failed", ccf->priority); | |
799 | } | |
800 | } | |
801 | ||
802 | if (ccf->rlimit_nofile != NGX_CONF_UNSET) { | |
803 | rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile; | |
804 | rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile; | |
805 | ||
806 | if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) { | |
807 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
808 | "setrlimit(RLIMIT_NOFILE, %i) failed", | |
809 | ccf->rlimit_nofile); | |
810 | } | |
811 | } | |
812 | ||
813 | if (ccf->rlimit_core != NGX_CONF_UNSET_SIZE) { | |
814 | rlmt.rlim_cur = (rlim_t) ccf->rlimit_core; | |
815 | rlmt.rlim_max = (rlim_t) ccf->rlimit_core; | |
816 | ||
817 | if (setrlimit(RLIMIT_CORE, &rlmt) == -1) { | |
818 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
819 | "setrlimit(RLIMIT_CORE, %i) failed", | |
820 | ccf->rlimit_core); | |
821 | } | |
822 | } | |
823 | ||
824 | #ifdef RLIMIT_SIGPENDING | |
825 | if (ccf->rlimit_sigpending != NGX_CONF_UNSET) { | |
826 | rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending; | |
827 | rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending; | |
828 | ||
829 | if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) { | |
830 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
831 | "setrlimit(RLIMIT_SIGPENDING, %i) failed", | |
832 | ccf->rlimit_sigpending); | |
833 | } | |
834 | } | |
835 | #endif | |
836 | ||
837 | 837 | if (setgid(ccf->group) == -1) { |
838 | 838 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
839 | 839 | "setgid(%d) failed", ccf->group); |