nginx-quic/src/core/nginx.c

1334 lines
32 KiB
C
Raw Normal View History

/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
*/
#include <ngx_config.h>
2003-01-10 03:09:20 -03:00
#include <ngx_core.h>
2003-05-30 10:27:59 -04:00
#include <nginx.h>
2004-03-09 16:47:07 -03:00
static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
static ngx_int_t ngx_get_options(int argc, char *const *argv);
2009-04-27 07:32:33 -04:00
static ngx_int_t ngx_process_options(ngx_cycle_t *cycle);
static ngx_int_t ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv);
2004-04-12 12:38:09 -04:00
static void *ngx_core_module_create_conf(ngx_cycle_t *cycle);
static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf);
2004-01-20 17:40:08 -03:00
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
2007-01-20 16:26:48 -03:00
static char *ngx_set_env(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_set_priority(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
2004-01-08 14:08:10 -03:00
static ngx_conf_enum_t ngx_debug_points[] = {
{ ngx_string("stop"), NGX_DEBUG_POINTS_STOP },
{ ngx_string("abort"), NGX_DEBUG_POINTS_ABORT },
{ ngx_null_string, 0 }
};
2003-07-11 11:17:50 -04:00
static ngx_command_t ngx_core_commands[] = {
2003-12-09 12:08:11 -03:00
{ ngx_string("daemon"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_FLAG,
2004-04-12 12:38:09 -04:00
ngx_conf_set_flag_slot,
2003-12-09 12:08:11 -03:00
0,
offsetof(ngx_core_conf_t, daemon),
NULL },
2004-01-08 14:08:10 -03:00
{ ngx_string("master_process"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_FLAG,
2004-04-12 12:38:09 -04:00
ngx_conf_set_flag_slot,
2004-01-05 17:55:48 -03:00
0,
2004-01-08 14:08:10 -03:00
offsetof(ngx_core_conf_t, master),
2004-01-05 17:55:48 -03:00
NULL },
{ ngx_string("timer_resolution"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
0,
offsetof(ngx_core_conf_t, timer_resolution),
NULL },
{ ngx_string("pid"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
0,
offsetof(ngx_core_conf_t, pid),
NULL },
{ ngx_string("lock_file"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
0,
offsetof(ngx_core_conf_t, lock_file),
NULL },
2004-03-30 16:31:58 -04:00
{ ngx_string("worker_processes"),
2004-04-12 12:38:09 -04:00
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
2004-02-09 17:47:18 -03:00
0,
2004-03-30 16:31:58 -04:00
offsetof(ngx_core_conf_t, worker_processes),
2004-02-09 17:47:18 -03:00
NULL },
{ ngx_string("debug_points"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_enum_slot,
0,
offsetof(ngx_core_conf_t, debug_points),
&ngx_debug_points },
2004-04-12 12:38:09 -04:00
{ ngx_string("user"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE12,
ngx_set_user,
0,
0,
NULL },
{ ngx_string("worker_priority"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_set_priority,
0,
0,
NULL },
{ ngx_string("worker_cpu_affinity"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_1MORE,
ngx_set_cpu_affinity,
0,
0,
NULL },
{ ngx_string("worker_rlimit_nofile"),
2004-04-12 12:38:09 -04:00
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
2004-01-22 03:47:28 -03:00
0,
offsetof(ngx_core_conf_t, rlimit_nofile),
NULL },
{ ngx_string("worker_rlimit_core"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
2010-09-15 11:24:21 -04:00
ngx_conf_set_off_slot,
0,
offsetof(ngx_core_conf_t, rlimit_core),
NULL },
{ ngx_string("worker_rlimit_sigpending"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
0,
offsetof(ngx_core_conf_t, rlimit_sigpending),
2004-01-22 03:47:28 -03:00
NULL },
{ ngx_string("working_directory"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
0,
offsetof(ngx_core_conf_t, working_directory),
NULL },
2007-01-20 16:26:48 -03:00
{ ngx_string("env"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_set_env,
0,
0,
NULL },
#if (NGX_THREADS)
{ ngx_string("worker_threads"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
0,
offsetof(ngx_core_conf_t, worker_threads),
NULL },
{ ngx_string("thread_stack_size"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
0,
offsetof(ngx_core_conf_t, thread_stack_size),
NULL },
#endif
2003-12-09 12:08:11 -03:00
ngx_null_command
2003-07-11 11:17:50 -04:00
};
2004-04-12 12:38:09 -04:00
static ngx_core_module_t ngx_core_module_ctx = {
ngx_string("core"),
ngx_core_module_create_conf,
ngx_core_module_init_conf
};
2003-07-11 11:17:50 -04:00
ngx_module_t ngx_core_module = {
nginx-0.1.29-RELEASE import *) Feature: the ngx_http_ssi_module supports "include virtual" command. *) Feature: the ngx_http_ssi_module supports the condition command like 'if expr="$NAME"' and "else" and "endif" commands. Only one nested level is supported. *) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and DATE_GMT variables and "config timefmt" command. *) Feature: the "ssi_ignore_recycled_buffers" directive. *) Bugfix: the "echo" command did not show the default value for the empty QUERY_STRING variable. *) Change: the ngx_http_proxy_module was rewritten. *) Feature: the "proxy_redirect", "proxy_pass_request_headers", "proxy_pass_request_body", and "proxy_method" directives. *) Feature: the "proxy_set_header" directive. The "proxy_x_var" was canceled and must be replaced with the proxy_set_header directive. *) Change: the "proxy_preserve_host" is canceled and must be replaced with the "proxy_set_header Host $host" and the "proxy_redirect off" directives, the "proxy_set_header Host $host:$proxy_port" directive and the appropriate proxy_redirect directives. *) Change: the "proxy_set_x_real_ip" is canceled and must be replaced with the "proxy_set_header X-Real-IP $remote_addr" directive. *) Change: the "proxy_add_x_forwarded_for" is canceled and must be replaced with the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for" directive. *) Change: the "proxy_set_x_url" is canceled and must be replaced with the "proxy_set_header X-URL http://$host:$server_port$request_uri" directive. *) Feature: the "fastcgi_param" directive. *) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params" directive are canceled and must be replaced with the fastcgi_param directives. *) Feature: the "index" directive can use the variables. *) Feature: the "index" directive can be used at http and server levels. *) Change: the last index only in the "index" directive can be absolute. *) Feature: the "rewrite" directive can use the variables. *) Feature: the "internal" directive. *) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR, SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME, REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables. *) Change: nginx now passes the invalid lines in a client request headers or a backend response header. *) Bugfix: if the backend did not transfer response for a long time and the "send_timeout" was less than "proxy_read_timeout", then nginx returned the 408 response. *) Bugfix: the segmentation fault was occurred if the backend sent an invalid line in response header; the bug had appeared in 0.1.26. *) Bugfix: the segmentation fault may occurred in FastCGI fault tolerance configuration. *) Bugfix: the "expires" directive did not remove the previous "Expires" and "Cache-Control" headers. *) Bugfix: nginx did not take into account trailing dot in "Host" header line. *) Bugfix: the ngx_http_auth_module did not work under Linux. *) Bugfix: the rewrite directive worked incorrectly, if the arguments were in a request. *) Bugfix: nginx could not be built on MacOS X.
2005-05-12 10:58:06 -04:00
NGX_MODULE_V1,
2004-04-12 12:38:09 -04:00
&ngx_core_module_ctx, /* module context */
2003-07-11 11:17:50 -04:00
ngx_core_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
NULL, /* init master */
2004-04-12 12:38:09 -04:00
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
2003-07-11 11:17:50 -04:00
};
2009-04-20 02:08:47 -04:00
ngx_uint_t ngx_max_module;
2009-04-21 12:21:58 -04:00
static ngx_uint_t ngx_show_help;
2009-04-20 02:08:47 -04:00
static ngx_uint_t ngx_show_version;
static ngx_uint_t ngx_show_configure;
2009-04-27 07:32:33 -04:00
static u_char *ngx_prefix;
2009-04-21 11:42:15 -04:00
static u_char *ngx_conf_file;
static u_char *ngx_conf_params;
2009-04-20 02:08:47 -04:00
static char *ngx_signal;
2002-12-15 03:25:09 -03:00
2007-01-20 16:26:48 -03:00
static char **ngx_os_environ;
2003-07-01 11:00:03 -04:00
int ngx_cdecl
main(int argc, char *const *argv)
{
ngx_int_t i;
ngx_log_t *log;
ngx_cycle_t *cycle, init_cycle;
ngx_core_conf_t *ccf;
2002-12-23 03:29:22 -03:00
#if (NGX_FREEBSD)
ngx_debug_init();
#endif
if (ngx_strerror_init() != NGX_OK) {
return 1;
}
if (ngx_get_options(argc, argv) != NGX_OK) {
return 1;
}
if (ngx_show_version) {
ngx_write_stderr("nginx version: " NGINX_VER NGX_LINEFEED);
2009-04-21 12:21:58 -04:00
if (ngx_show_help) {
ngx_write_stderr(
2010-09-02 09:43:02 -04:00
"Usage: nginx [-?hvVtq] [-s signal] [-c filename] "
"[-p prefix] [-g directives]" NGX_LINEFEED
NGX_LINEFEED
"Options:" NGX_LINEFEED
" -?,-h : this help" NGX_LINEFEED
" -v : show version and exit" NGX_LINEFEED
2009-04-21 12:21:58 -04:00
" -V : show version and configure options then exit"
NGX_LINEFEED
" -t : test configuration and exit" NGX_LINEFEED
2010-09-02 09:43:02 -04:00
" -q : suppress non-error messages "
"during configuration testing" NGX_LINEFEED
2009-04-21 16:25:49 -04:00
" -s signal : send signal to a master process: "
"stop, quit, reopen, reload" NGX_LINEFEED
2009-04-27 07:32:33 -04:00
#ifdef NGX_PREFIX
" -p prefix : set prefix path (default: "
NGX_PREFIX ")" NGX_LINEFEED
2009-04-27 07:32:33 -04:00
#else
" -p prefix : set prefix path (default: NONE)" NGX_LINEFEED
2009-04-27 07:32:33 -04:00
#endif
2009-04-21 12:21:58 -04:00
" -c filename : set configuration file (default: "
NGX_CONF_PATH ")" NGX_LINEFEED
2009-04-21 12:21:58 -04:00
" -g directives : set global directives out of configuration "
"file" NGX_LINEFEED NGX_LINEFEED
2009-04-21 12:21:58 -04:00
);
}
if (ngx_show_configure) {
ngx_write_stderr(
#ifdef NGX_COMPILER
"built by " NGX_COMPILER NGX_LINEFEED
2009-10-19 09:35:01 -03:00
#endif
2009-10-26 09:00:37 -03:00
#if (NGX_SSL)
2009-10-19 09:35:01 -03:00
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
"TLS SNI support enabled" NGX_LINEFEED
2009-10-26 09:00:37 -03:00
#else
"TLS SNI support disabled" NGX_LINEFEED
2009-10-26 09:00:37 -03:00
#endif
#endif
"configure arguments:" NGX_CONFIGURE NGX_LINEFEED);
}
if (!ngx_test_config) {
return 0;
}
}
2003-07-02 01:01:53 -04:00
/* TODO */ ngx_max_sockets = -1;
2003-05-20 11:37:55 -04:00
2003-11-25 17:44:56 -03:00
ngx_time_init();
2004-01-08 14:08:10 -03:00
#if (NGX_PCRE)
2003-11-25 17:44:56 -03:00
ngx_regex_init();
2003-12-19 05:15:11 -03:00
#endif
2003-11-13 03:14:05 -03:00
2004-02-03 13:43:54 -03:00
ngx_pid = ngx_getpid();
2002-08-20 10:48:28 -04:00
2009-04-27 07:32:33 -04:00
log = ngx_log_init(ngx_prefix);
if (log == NULL) {
return 1;
}
2004-09-28 16:09:22 -04:00
/* STUB */
2004-07-15 12:35:51 -04:00
#if (NGX_OPENSSL)
ngx_ssl_init(log);
#endif
/*
* init_cycle->log is required for signal handlers and
* ngx_process_options()
*/
2003-12-19 05:15:11 -03:00
ngx_memzero(&init_cycle, sizeof(ngx_cycle_t));
init_cycle.log = log;
ngx_cycle = &init_cycle;
init_cycle.pool = ngx_create_pool(1024, log);
if (init_cycle.pool == NULL) {
2004-02-09 17:47:18 -03:00
return 1;
}
if (ngx_save_argv(&init_cycle, argc, argv) != NGX_OK) {
return 1;
}
2009-04-27 07:32:33 -04:00
if (ngx_process_options(&init_cycle) != NGX_OK) {
return 1;
}
2004-10-01 11:53:53 -04:00
if (ngx_os_init(log) != NGX_OK) {
2004-01-05 17:55:48 -03:00
return 1;
}
/*
* ngx_crc32_table_init() requires ngx_cacheline_size set in ngx_os_init()
*/
if (ngx_crc32_table_init() != NGX_OK) {
return 1;
}
if (ngx_add_inherited_sockets(&init_cycle) != NGX_OK) {
2004-01-05 17:55:48 -03:00
return 1;
}
2004-04-15 11:34:36 -04:00
ngx_max_module = 0;
for (i = 0; ngx_modules[i]; i++) {
ngx_modules[i]->index = ngx_max_module++;
}
2004-01-05 17:55:48 -03:00
cycle = ngx_init_cycle(&init_cycle);
2003-07-02 01:01:53 -04:00
if (cycle == NULL) {
2004-04-18 15:06:02 -04:00
if (ngx_test_config) {
ngx_log_stderr(0, "configuration file %s test failed",
2009-04-19 12:06:09 -04:00
init_cycle.conf_file.data);
2004-04-18 15:06:02 -04:00
}
2003-06-26 11:35:36 -04:00
return 1;
}
2004-04-15 11:34:36 -04:00
if (ngx_test_config) {
2010-09-02 09:43:02 -04:00
if (!ngx_quiet_mode) {
ngx_log_stderr(0, "configuration file %s test is successful",
cycle->conf_file.data);
}
2004-04-15 11:34:36 -04:00
return 0;
}
if (ngx_signal) {
return ngx_signal_process(cycle, ngx_signal);
}
2004-10-03 16:02:06 -04:00
ngx_os_status(cycle->log);
2003-07-07 02:11:50 -04:00
ngx_cycle = cycle;
2003-07-04 11:10:33 -04:00
2004-01-05 17:55:48 -03:00
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
2009-04-20 02:08:47 -04:00
if (ccf->master && ngx_process == NGX_PROCESS_SINGLE) {
ngx_process = NGX_PROCESS_MASTER;
}
2004-01-05 17:55:48 -03:00
2009-04-21 16:25:49 -04:00
#if !(NGX_WIN32)
2003-07-10 12:26:57 -04:00
if (ngx_init_signals(cycle->log) != NGX_OK) {
return 1;
}
2004-04-12 12:38:09 -04:00
if (!ngx_inherited && ccf->daemon) {
if (ngx_daemon(cycle->log) != NGX_OK) {
2003-07-10 12:26:57 -04:00
return 1;
}
2004-06-23 11:18:17 -04:00
ngx_daemonized = 1;
2003-07-10 12:26:57 -04:00
}
if (ngx_inherited) {
ngx_daemonized = 1;
}
2009-04-20 02:08:47 -04:00
#endif
if (ngx_create_pidfile(&ccf->pid, cycle->log) != NGX_OK) {
2003-12-14 17:10:27 -03:00
return 1;
}
if (cycle->log->file->fd != ngx_stderr) {
if (ngx_set_stderr(cycle->log->file->fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
ngx_set_stderr_n " failed");
return 1;
}
}
if (log->file->fd != ngx_stderr) {
if (ngx_close_file(log->file->fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_close_file_n " built-in log failed");
}
}
ngx_use_stderr = 0;
2009-04-20 02:08:47 -04:00
if (ngx_process == NGX_PROCESS_SINGLE) {
ngx_single_process_cycle(cycle);
2004-04-16 01:14:16 -04:00
} else {
2009-04-20 02:08:47 -04:00
ngx_master_process_cycle(cycle);
2004-04-16 01:14:16 -04:00
}
2004-01-08 05:47:17 -03:00
return 0;
}
static ngx_int_t
ngx_add_inherited_sockets(ngx_cycle_t *cycle)
2004-01-05 17:55:48 -03:00
{
u_char *p, *v, *inherited;
ngx_int_t s;
ngx_listening_t *ls;
2003-06-11 11:28:34 -04:00
2004-03-16 03:10:12 -04:00
inherited = (u_char *) getenv(NGINX_VAR);
2004-03-09 16:47:07 -03:00
if (inherited == NULL) {
return NGX_OK;
}
2002-08-26 11:18:19 -04:00
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
2004-03-09 16:47:07 -03:00
"using inherited sockets from \"%s\"", inherited);
if (ngx_array_init(&cycle->listening, cycle->pool, 10,
2006-10-06 09:02:23 -04:00
sizeof(ngx_listening_t))
!= NGX_OK)
{
return NGX_ERROR;
}
2004-03-09 16:47:07 -03:00
for (p = inherited, v = p; *p; p++) {
if (*p == ':' || *p == ';') {
s = ngx_atoi(v, p - v);
if (s == NGX_ERROR) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"invalid socket number \"%s\" in " NGINX_VAR
" environment variable, ignoring the rest"
" of the variable", v);
2004-03-09 16:47:07 -03:00
break;
2002-08-20 10:48:28 -04:00
}
2004-01-05 17:55:48 -03:00
2004-03-16 03:10:12 -04:00
v = p + 1;
2004-03-09 16:47:07 -03:00
ls = ngx_array_push(&cycle->listening);
if (ls == NULL) {
2004-03-09 16:47:07 -03:00
return NGX_ERROR;
2004-03-16 03:10:12 -04:00
}
2004-01-08 18:02:06 -03:00
ngx_memzero(ls, sizeof(ngx_listening_t));
ls->fd = (ngx_socket_t) s;
2004-03-09 16:47:07 -03:00
}
2004-01-05 17:55:48 -03:00
}
2004-03-09 16:47:07 -03:00
ngx_inherited = 1;
return ngx_set_inherited_sockets(cycle);
2004-01-05 17:55:48 -03:00
}
2003-07-07 02:11:50 -04:00
2007-01-20 16:26:48 -03:00
char **
ngx_set_environment(ngx_cycle_t *cycle, ngx_uint_t *last)
{
char **p, **env;
ngx_str_t *var;
ngx_uint_t i, n;
ngx_core_conf_t *ccf;
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
2007-01-25 18:48:28 -03:00
if (last == NULL && ccf->environment) {
return ccf->environment;
2007-01-20 16:26:48 -03:00
}
var = ccf->env.elts;
for (i = 0; i < ccf->env.nelts; i++) {
if (ngx_strcmp(var[i].data, "TZ") == 0
|| ngx_strncmp(var[i].data, "TZ=", 3) == 0)
{
goto tz_found;
}
}
var = ngx_array_push(&ccf->env);
if (var == NULL) {
return NULL;
}
2007-01-20 16:26:48 -03:00
var->len = 2;
var->data = (u_char *) "TZ";
var = ccf->env.elts;
tz_found:
2007-01-25 18:48:28 -03:00
n = 0;
2007-01-20 16:26:48 -03:00
for (i = 0; i < ccf->env.nelts; i++) {
if (var[i].data[var[i].len] == '=') {
n++;
continue;
}
for (p = ngx_os_environ; *p; p++) {
if (ngx_strncmp(*p, var[i].data, var[i].len) == 0
&& (*p)[var[i].len] == '=')
{
n++;
break;
}
}
}
if (last) {
2007-01-25 18:48:28 -03:00
env = ngx_alloc((*last + n + 1) * sizeof(char *), cycle->log);
2007-01-20 16:26:48 -03:00
*last = n;
} else {
env = ngx_palloc(cycle->pool, (n + 1) * sizeof(char *));
}
if (env == NULL) {
return NULL;
}
n = 0;
for (i = 0; i < ccf->env.nelts; i++) {
if (var[i].data[var[i].len] == '=') {
env[n++] = (char *) var[i].data;
continue;
}
for (p = ngx_os_environ; *p; p++) {
if (ngx_strncmp(*p, var[i].data, var[i].len) == 0
&& (*p)[var[i].len] == '=')
{
env[n++] = *p;
break;
}
}
}
env[n] = NULL;
if (last == NULL) {
ccf->environment = env;
environ = env;
}
return env;
}
ngx_pid_t
ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
2003-07-07 02:11:50 -04:00
{
2007-01-20 16:26:48 -03:00
char **env, *var;
u_char *p;
ngx_uint_t i, n;
ngx_pid_t pid;
ngx_exec_ctx_t ctx;
ngx_core_conf_t *ccf;
ngx_listening_t *ls;
2003-07-07 02:11:50 -04:00
2009-04-23 14:22:28 -04:00
ngx_memzero(&ctx, sizeof(ngx_exec_ctx_t));
2004-01-05 17:55:48 -03:00
ctx.path = argv[0];
ctx.name = "new binary process";
ctx.argv = argv;
2003-07-07 02:11:50 -04:00
2007-01-20 16:26:48 -03:00
n = 2;
env = ngx_set_environment(cycle, &n);
if (env == NULL) {
return NGX_INVALID_PID;
}
2004-03-09 16:47:07 -03:00
var = ngx_alloc(sizeof(NGINX_VAR)
+ cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
2004-01-05 17:55:48 -03:00
cycle->log);
2003-07-07 02:11:50 -04:00
p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR));
2003-07-07 02:11:50 -04:00
2004-01-05 17:55:48 -03:00
ls = cycle->listening.elts;
for (i = 0; i < cycle->listening.nelts; i++) {
p = ngx_sprintf(p, "%ud;", ls[i].fd);
2004-01-05 17:55:48 -03:00
}
2003-07-07 02:11:50 -04:00
*p = '\0';
2007-01-20 16:26:48 -03:00
env[n++] = var;
#if (NGX_SETPROCTITLE_USES_ENV)
/* allocate the spare 300 bytes for the new binary process title */
2007-01-20 16:26:48 -03:00
env[n++] = "SPARE=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
2007-01-20 16:26:48 -03:00
#endif
2007-01-20 16:26:48 -03:00
env[n] = NULL;
2007-01-20 16:26:48 -03:00
#if (NGX_DEBUG)
{
char **e;
for (e = env; *e; e++) {
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "env: %s", *e);
}
}
#endif
2007-01-20 16:26:48 -03:00
ctx.envp = (char *const *) env;
2003-07-07 02:11:50 -04:00
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
2007-01-20 16:26:48 -03:00
if (ngx_rename_file(ccf->pid.data, ccf->oldpid.data) != NGX_OK) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_rename_file_n " %s to %s failed "
"before executing new binary process \"%s\"",
ccf->pid.data, ccf->oldpid.data, argv[0]);
2007-01-20 16:26:48 -03:00
ngx_free(env);
ngx_free(var);
return NGX_INVALID_PID;
}
2004-03-04 13:34:23 -03:00
pid = ngx_execute(cycle, &ctx);
2003-07-07 02:11:50 -04:00
if (pid == NGX_INVALID_PID) {
2007-01-20 16:26:48 -03:00
if (ngx_rename_file(ccf->oldpid.data, ccf->pid.data) != NGX_OK) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
2007-01-20 16:26:48 -03:00
ngx_rename_file_n " %s back to %s failed after "
"the try to execute the new binary process \"%s\"",
ccf->oldpid.data, ccf->pid.data, argv[0]);
}
}
2007-01-20 16:26:48 -03:00
ngx_free(env);
2004-01-05 17:55:48 -03:00
ngx_free(var);
2004-01-13 18:33:59 -03:00
return pid;
2004-01-05 17:55:48 -03:00
}
2003-07-07 02:11:50 -04:00
static ngx_int_t
ngx_get_options(int argc, char *const *argv)
2004-02-09 17:47:18 -03:00
{
2009-04-21 11:42:15 -04:00
u_char *p;
ngx_int_t i;
2004-02-09 17:47:18 -03:00
for (i = 1; i < argc; i++) {
2009-04-21 11:42:15 -04:00
p = (u_char *) argv[i];
if (*p++ != '-') {
ngx_log_stderr(0, "invalid option: \"%s\"", argv[i]);
2004-02-09 17:47:18 -03:00
return NGX_ERROR;
}
2009-04-21 11:42:15 -04:00
while (*p) {
2004-02-09 17:47:18 -03:00
2009-04-21 11:42:15 -04:00
switch (*p++) {
2009-04-21 12:21:58 -04:00
case '?':
case 'h':
ngx_show_version = 1;
ngx_show_help = 1;
break;
2009-04-21 11:42:15 -04:00
case 'v':
ngx_show_version = 1;
break;
2006-12-23 16:54:21 -03:00
2009-04-21 11:42:15 -04:00
case 'V':
ngx_show_version = 1;
ngx_show_configure = 1;
break;
2004-04-15 11:34:36 -04:00
2009-04-21 11:42:15 -04:00
case 't':
ngx_test_config = 1;
break;
2004-04-14 16:34:05 -04:00
2010-09-02 09:43:02 -04:00
case 'q':
ngx_quiet_mode = 1;
break;
2009-04-27 07:32:33 -04:00
case 'p':
if (*p) {
ngx_prefix = p;
goto next;
}
if (argv[++i]) {
ngx_prefix = (u_char *) argv[i];
goto next;
}
ngx_log_stderr(0, "option \"-p\" requires directory name");
return NGX_ERROR;
2009-04-21 11:42:15 -04:00
case 'c':
if (*p) {
ngx_conf_file = p;
goto next;
}
2004-02-09 17:47:18 -03:00
2009-04-21 11:42:15 -04:00
if (argv[++i]) {
ngx_conf_file = (u_char *) argv[i];
goto next;
}
2008-06-30 08:35:16 -04:00
ngx_log_stderr(0, "option \"-c\" requires file name");
2009-04-21 11:42:15 -04:00
return NGX_ERROR;
case 'g':
if (*p) {
ngx_conf_params = p;
goto next;
}
if (argv[++i]) {
ngx_conf_params = (u_char *) argv[i];
goto next;
}
ngx_log_stderr(0, "option \"-g\" requires parameter");
2009-04-21 11:42:15 -04:00
return NGX_ERROR;
2008-06-30 08:35:16 -04:00
2009-04-21 11:42:15 -04:00
case 's':
if (*p) {
ngx_signal = (char *) p;
} else if (argv[++i]) {
ngx_signal = argv[i];
} else {
ngx_log_stderr(0, "option \"-s\" requires parameter");
2009-04-21 11:42:15 -04:00
return NGX_ERROR;
}
if (ngx_strcmp(ngx_signal, "stop") == 0
|| ngx_strcmp(ngx_signal, "quit") == 0
|| ngx_strcmp(ngx_signal, "reopen") == 0
|| ngx_strcmp(ngx_signal, "reload") == 0)
{
ngx_process = NGX_PROCESS_SIGNALLER;
goto next;
}
ngx_log_stderr(0, "invalid option: \"-s %s\"", ngx_signal);
2009-04-20 02:08:47 -04:00
return NGX_ERROR;
2009-04-21 11:42:15 -04:00
default:
ngx_log_stderr(0, "invalid option: \"%c\"", *(p - 1));
2009-04-21 11:42:15 -04:00
return NGX_ERROR;
2009-04-20 02:08:47 -04:00
}
2009-04-21 11:42:15 -04:00
}
2009-04-20 02:08:47 -04:00
2009-04-21 11:42:15 -04:00
next:
2009-04-20 02:08:47 -04:00
2009-04-21 11:42:15 -04:00
continue;
2004-02-09 17:47:18 -03:00
}
return NGX_OK;
}
static ngx_int_t
ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv)
{
#if (NGX_FREEBSD)
ngx_os_argv = (char **) argv;
ngx_argc = argc;
ngx_argv = (char **) argv;
#else
size_t len;
ngx_int_t i;
ngx_os_argv = (char **) argv;
ngx_argc = argc;
ngx_argv = ngx_alloc((argc + 1) * sizeof(char *), cycle->log);
if (ngx_argv == NULL) {
return NGX_ERROR;
}
for (i = 0; i < argc; i++) {
len = ngx_strlen(argv[i]) + 1;
ngx_argv[i] = ngx_alloc(len, cycle->log);
if (ngx_argv[i] == NULL) {
return NGX_ERROR;
}
(void) ngx_cpystrn((u_char *) ngx_argv[i], (u_char *) argv[i], len);
}
ngx_argv[i] = NULL;
#endif
2007-01-20 16:26:48 -03:00
ngx_os_environ = environ;
return NGX_OK;
}
2009-04-27 07:32:33 -04:00
static ngx_int_t
ngx_process_options(ngx_cycle_t *cycle)
{
2009-04-27 07:32:33 -04:00
u_char *p;
size_t len;
if (ngx_prefix) {
len = ngx_strlen(ngx_prefix);
p = ngx_prefix;
if (!ngx_path_separator(*p)) {
p = ngx_pnalloc(cycle->pool, len + 1);
if (p == NULL) {
return NGX_ERROR;
}
ngx_memcpy(p, ngx_prefix, len);
p[len++] = '/';
}
cycle->conf_prefix.len = len;
cycle->conf_prefix.data = p;
cycle->prefix.len = len;
cycle->prefix.data = p;
} else {
#ifndef NGX_PREFIX
p = ngx_pnalloc(cycle->pool, NGX_MAX_PATH);
if (p == NULL) {
return NGX_ERROR;
}
if (ngx_getcwd(p, NGX_MAX_PATH) == 0) {
ngx_log_stderr(ngx_errno, "[emerg]: " ngx_getcwd_n " failed");
return NGX_ERROR;
}
len = ngx_strlen(p);
p[len++] = '/';
cycle->conf_prefix.len = len;
cycle->conf_prefix.data = p;
cycle->prefix.len = len;
cycle->prefix.data = p;
#else
#ifdef NGX_CONF_PREFIX
2010-05-14 05:56:37 -04:00
ngx_str_set(&cycle->conf_prefix, NGX_CONF_PREFIX);
2009-04-27 07:32:33 -04:00
#else
2010-05-14 05:56:37 -04:00
ngx_str_set(&cycle->conf_prefix, NGX_PREFIX);
2009-04-27 07:32:33 -04:00
#endif
2010-05-14 05:56:37 -04:00
ngx_str_set(&cycle->prefix, NGX_PREFIX);
2009-04-27 07:32:33 -04:00
#endif
}
if (ngx_conf_file) {
cycle->conf_file.len = ngx_strlen(ngx_conf_file);
2009-04-21 11:42:15 -04:00
cycle->conf_file.data = ngx_conf_file;
} else {
2010-05-14 05:56:37 -04:00
ngx_str_set(&cycle->conf_file, NGX_CONF_PATH);
}
2009-04-27 07:32:33 -04:00
if (ngx_conf_full_name(cycle, &cycle->conf_file, 0) != NGX_OK) {
return NGX_ERROR;
}
for (p = cycle->conf_file.data + cycle->conf_file.len - 1;
p > cycle->conf_file.data;
p--)
{
if (ngx_path_separator(*p)) {
cycle->conf_prefix.len = p - ngx_cycle->conf_file.data + 1;
cycle->conf_prefix.data = ngx_cycle->conf_file.data;
break;
}
}
if (ngx_conf_params) {
cycle->conf_param.len = ngx_strlen(ngx_conf_params);
2009-04-21 11:42:15 -04:00
cycle->conf_param.data = ngx_conf_params;
}
if (ngx_test_config) {
cycle->log->log_level = NGX_LOG_INFO;
}
2009-04-27 07:32:33 -04:00
return NGX_OK;
}
static void *
ngx_core_module_create_conf(ngx_cycle_t *cycle)
2004-01-05 17:55:48 -03:00
{
ngx_core_conf_t *ccf;
2003-07-07 02:11:50 -04:00
ccf = ngx_pcalloc(cycle->pool, sizeof(ngx_core_conf_t));
if (ccf == NULL) {
2004-04-12 12:38:09 -04:00
return NULL;
2003-07-07 02:11:50 -04:00
}
/*
2010-03-26 18:17:26 -03:00
* set by ngx_pcalloc()
2004-01-05 17:55:48 -03:00
*
* ccf->pid = NULL;
* ccf->oldpid = NULL;
* ccf->priority = 0;
* ccf->cpu_affinity_n = 0;
* ccf->cpu_affinity = NULL;
2004-01-05 17:55:48 -03:00
*/
2004-01-20 17:40:08 -03:00
ccf->daemon = NGX_CONF_UNSET;
ccf->master = NGX_CONF_UNSET;
ccf->timer_resolution = NGX_CONF_UNSET_MSEC;
2004-03-30 16:31:58 -04:00
ccf->worker_processes = NGX_CONF_UNSET;
ccf->debug_points = NGX_CONF_UNSET;
ccf->rlimit_nofile = NGX_CONF_UNSET;
2010-09-15 11:24:21 -04:00
ccf->rlimit_core = NGX_CONF_UNSET;
ccf->rlimit_sigpending = NGX_CONF_UNSET;
ccf->user = (ngx_uid_t) NGX_CONF_UNSET_UINT;
ccf->group = (ngx_gid_t) NGX_CONF_UNSET_UINT;
2004-07-05 02:55:54 -04:00
#if (NGX_THREADS)
ccf->worker_threads = NGX_CONF_UNSET;
ccf->thread_stack_size = NGX_CONF_UNSET_SIZE;
2004-07-05 02:55:54 -04:00
#endif
2004-01-05 17:55:48 -03:00
2007-01-20 16:26:48 -03:00
if (ngx_array_init(&ccf->env, cycle->pool, 1, sizeof(ngx_str_t))
!= NGX_OK)
{
return NULL;
}
2004-04-12 12:38:09 -04:00
return ccf;
}
2004-01-05 17:55:48 -03:00
2004-04-12 12:38:09 -04:00
static char *
ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
2004-04-12 12:38:09 -04:00
{
ngx_core_conf_t *ccf = conf;
ngx_conf_init_value(ccf->daemon, 1);
ngx_conf_init_value(ccf->master, 1);
ngx_conf_init_msec_value(ccf->timer_resolution, 0);
2004-04-12 12:38:09 -04:00
ngx_conf_init_value(ccf->worker_processes, 1);
ngx_conf_init_value(ccf->debug_points, 0);
2004-04-12 12:38:09 -04:00
#if (NGX_HAVE_SCHED_SETAFFINITY)
if (ccf->cpu_affinity_n
&& ccf->cpu_affinity_n != 1
&& ccf->cpu_affinity_n != (ngx_uint_t) ccf->worker_processes)
{
ngx_log_error(NGX_LOG_WARN, cycle->log, 0,
"number of the \"worker_processes\" is not equal to "
"the number of the \"worker_cpu_affinity\" mask, "
"using last mask for remaining worker processes");
}
#endif
2004-07-05 02:55:54 -04:00
#if (NGX_THREADS)
2004-07-05 02:55:54 -04:00
ngx_conf_init_value(ccf->worker_threads, 0);
ngx_threads_n = ccf->worker_threads;
ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024);
2004-07-05 02:55:54 -04:00
#endif
2009-04-20 02:08:47 -04:00
if (ccf->pid.len == 0) {
2010-05-14 05:56:37 -04:00
ngx_str_set(&ccf->pid, NGX_PID_PATH);
2009-04-20 02:08:47 -04:00
}
if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) {
return NGX_CONF_ERROR;
}
ccf->oldpid.len = ccf->pid.len + sizeof(NGX_OLDPID_EXT);
ccf->oldpid.data = ngx_pnalloc(cycle->pool, ccf->oldpid.len);
if (ccf->oldpid.data == NULL) {
return NGX_CONF_ERROR;
}
ngx_memcpy(ngx_cpymem(ccf->oldpid.data, ccf->pid.data, ccf->pid.len),
NGX_OLDPID_EXT, sizeof(NGX_OLDPID_EXT));
#if !(NGX_WIN32)
2004-04-12 12:38:09 -04:00
if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) {
struct group *grp;
struct passwd *pwd;
2004-09-27 12:03:21 -04:00
2007-07-11 06:46:21 -04:00
ngx_set_errno(0);
pwd = getpwnam(NGX_USER);
2004-09-27 12:03:21 -04:00
if (pwd == NULL) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"getpwnam(\"" NGX_USER "\") failed");
2004-09-27 12:03:21 -04:00
return NGX_CONF_ERROR;
}
ccf->username = NGX_USER;
2004-09-27 12:03:21 -04:00
ccf->user = pwd->pw_uid;
2007-07-11 06:46:21 -04:00
ngx_set_errno(0);
grp = getgrnam(NGX_GROUP);
2004-09-27 12:03:21 -04:00
if (grp == NULL) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"getgrnam(\"" NGX_GROUP "\") failed");
2004-09-27 12:03:21 -04:00
return NGX_CONF_ERROR;
}
ccf->group = grp->gr_gid;
}
2004-04-12 12:38:09 -04:00
2006-11-20 05:51:45 -03:00
if (ccf->lock_file.len == 0) {
2010-05-14 05:56:37 -04:00
ngx_str_set(&ccf->lock_file, NGX_LOCK_PATH);
}
if (ngx_conf_full_name(cycle, &ccf->lock_file, 0) != NGX_OK) {
return NGX_CONF_ERROR;
}
{
ngx_str_t lock_file;
2006-11-20 05:51:45 -03:00
lock_file = cycle->old_cycle->lock_file;
if (lock_file.len) {
lock_file.len--;
if (ccf->lock_file.len != lock_file.len
|| ngx_strncmp(ccf->lock_file.data, lock_file.data, lock_file.len)
!= 0)
{
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"\"lock_file\" could not be changed, ignored");
}
cycle->lock_file.len = lock_file.len + 1;
lock_file.len += sizeof(".accept");
cycle->lock_file.data = ngx_pstrdup(cycle->pool, &lock_file);
if (cycle->lock_file.data == NULL) {
return NGX_CONF_ERROR;
}
} else {
cycle->lock_file.len = ccf->lock_file.len + 1;
cycle->lock_file.data = ngx_pnalloc(cycle->pool,
2006-11-20 05:51:45 -03:00
ccf->lock_file.len + sizeof(".accept"));
if (cycle->lock_file.data == NULL) {
return NGX_CONF_ERROR;
}
ngx_memcpy(ngx_cpymem(cycle->lock_file.data, ccf->lock_file.data,
ccf->lock_file.len),
".accept", sizeof(".accept"));
}
}
2006-11-20 05:51:45 -03:00
2004-04-12 12:38:09 -04:00
#endif
return NGX_CONF_OK;
2003-07-07 02:11:50 -04:00
}
2004-01-20 17:40:08 -03:00
static char *
ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2004-01-20 17:40:08 -03:00
{
#if (NGX_WIN32)
2004-03-04 04:04:55 -03:00
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"\"user\" is not supported, ignored");
return NGX_CONF_OK;
#else
2004-04-12 12:38:09 -04:00
ngx_core_conf_t *ccf = conf;
char *group;
2004-01-20 17:40:08 -03:00
struct passwd *pwd;
struct group *grp;
ngx_str_t *value;
if (ccf->user != (uid_t) NGX_CONF_UNSET_UINT) {
2004-01-20 17:40:08 -03:00
return "is duplicate";
}
if (geteuid() != 0) {
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"the \"user\" directive makes sense only "
"if the master process runs "
"with super-user privileges, ignored");
return NGX_CONF_OK;
}
2004-01-20 17:40:08 -03:00
value = (ngx_str_t *) cf->args->elts;
ccf->username = (char *) value[1].data;
2007-07-11 06:46:21 -04:00
ngx_set_errno(0);
2004-03-16 03:10:12 -04:00
pwd = getpwnam((const char *) value[1].data);
2004-01-20 17:40:08 -03:00
if (pwd == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
"getpwnam(\"%s\") failed", value[1].data);
2004-01-20 17:40:08 -03:00
return NGX_CONF_ERROR;
}
ccf->user = pwd->pw_uid;
group = (char *) ((cf->args->nelts == 2) ? value[1].data : value[2].data);
2004-01-20 17:40:08 -03:00
2007-07-11 06:46:21 -04:00
ngx_set_errno(0);
grp = getgrnam(group);
2004-01-20 17:40:08 -03:00
if (grp == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
"getgrnam(\"%s\") failed", group);
2004-01-20 17:40:08 -03:00
return NGX_CONF_ERROR;
}
ccf->group = grp->gr_gid;
return NGX_CONF_OK;
2004-03-04 04:04:55 -03:00
#endif
2004-01-20 17:40:08 -03:00
}
2007-01-20 16:26:48 -03:00
static char *
ngx_set_env(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_core_conf_t *ccf = conf;
ngx_str_t *value, *var;
ngx_uint_t i;
var = ngx_array_push(&ccf->env);
if (var == NULL) {
return NGX_CONF_ERROR;
}
value = cf->args->elts;
*var = value[1];
for (i = 0; i < value[1].len; i++) {
if (value[1].data[i] == '=') {
var->len = i;
return NGX_CONF_OK;
}
}
return NGX_CONF_OK;
}
static char *
ngx_set_priority(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_core_conf_t *ccf = conf;
ngx_str_t *value;
ngx_uint_t n, minus;
if (ccf->priority != 0) {
return "is duplicate";
}
value = cf->args->elts;
if (value[1].data[0] == '-') {
n = 1;
minus = 1;
} else if (value[1].data[0] == '+') {
n = 1;
minus = 0;
} else {
n = 0;
minus = 0;
}
ccf->priority = ngx_atoi(&value[1].data[n], value[1].len - n);
if (ccf->priority == NGX_ERROR) {
return "invalid number";
}
if (minus) {
ccf->priority = -ccf->priority;
}
return NGX_CONF_OK;
}
static char *
ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
#if (NGX_HAVE_SCHED_SETAFFINITY)
ngx_core_conf_t *ccf = conf;
u_char ch;
u_long *mask;
ngx_str_t *value;
ngx_uint_t i, n;
if (ccf->cpu_affinity) {
return "is duplicate";
}
mask = ngx_palloc(cf->pool, (cf->args->nelts - 1) * sizeof(long));
if (mask == NULL) {
return NGX_CONF_ERROR;
}
ccf->cpu_affinity_n = cf->args->nelts - 1;
ccf->cpu_affinity = mask;
value = cf->args->elts;
for (n = 1; n < cf->args->nelts; n++) {
if (value[n].len > 32) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"worker_cpu_affinity\" supports up to 32 CPU only");
return NGX_CONF_ERROR;
}
mask[n - 1] = 0;
for (i = 0; i < value[n].len; i++) {
ch = value[n].data[i];
if (ch == ' ') {
continue;
}
mask[n - 1] <<= 1;
if (ch == '0') {
continue;
}
if (ch == '1') {
mask[n - 1] |= 1;
continue;
}
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid character \"%c\" in \"worker_cpu_affinity\"",
ch);
2008-05-22 08:09:41 -04:00
return NGX_CONF_ERROR;
}
}
#else
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"\"worker_cpu_affinity\" is not supported "
"on this platform, ignored");
#endif
return NGX_CONF_OK;
}
u_long
ngx_get_cpu_affinity(ngx_uint_t n)
{
ngx_core_conf_t *ccf;
ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx,
ngx_core_module);
if (ccf->cpu_affinity == NULL) {
return 0;
}
if (ccf->cpu_affinity_n > n) {
return ccf->cpu_affinity[n];
}
return ccf->cpu_affinity[ccf->cpu_affinity_n - 1];
}