nginx-0.0.2-2004-02-09-23:47:18 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index fe78ab4..34f204f 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -19,6 +19,7 @@
typedef struct {
ngx_file_t pid;
char *name;
+ int argc;
char *const *argv;
} ngx_master_ctx_t;
@@ -28,6 +29,7 @@
static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp);
static ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv);
+static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle);
static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle);
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
@@ -57,6 +59,13 @@
offsetof(ngx_core_conf_t, master),
NULL },
+ { ngx_string("pid"),
+ NGX_MAIN_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_core_str_slot,
+ 0,
+ offsetof(ngx_core_conf_t, pid),
+ NULL },
+
{ ngx_string("worker_reopen"),
NGX_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_core_flag_slot,
@@ -125,12 +134,20 @@
log = ngx_log_init_errlog();
ngx_pid = ngx_getpid();
- /* init_cycle->log is required for signal handlers */
+ /* init_cycle->log is required for signal handlers and ngx_getopt() */
ngx_memzero(&init_cycle, sizeof(ngx_cycle_t));
init_cycle.log = log;
ngx_cycle = &init_cycle;
+ ngx_memzero(&ctx, sizeof(ngx_master_ctx_t));
+ ctx.argc = argc;
+ ctx.argv = argv;
+
+ if (ngx_getopt(&ctx, &init_cycle) == NGX_ERROR) {
+ return 1;
+ }
+
if (ngx_os_init(log) == NGX_ERROR) {
return 1;
}
@@ -213,8 +230,6 @@
#endif
- ctx.argv = argv;
-
ngx_master_process_cycle(cycle, &ctx);
return 0;
@@ -745,6 +760,40 @@
}
+static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle)
+{
+ ngx_int_t i;
+
+ for (i = 1; i < ctx->argc; i++) {
+ if (ctx->argv[i][0] != '-') {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
+ "invalid option: \"%s\"", ctx->argv[i]);
+ return NGX_ERROR;
+ }
+
+ switch (ctx->argv[i][1]) {
+
+ case 'c':
+ cycle->conf_file.data = ctx->argv[++i];
+ cycle->conf_file.len = ngx_strlen(cycle->conf_file.data);
+ break;
+
+ default:
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
+ "invalid option: \"%s\"", ctx->argv[i]);
+ return NGX_ERROR;
+ }
+ }
+
+ if (cycle->conf_file.len == NULL) {
+ cycle->conf_file.len = sizeof(NGINX_CONF) - 1;
+ cycle->conf_file.data = NGINX_CONF;
+ }
+
+ return NGX_OK;
+}
+
+
static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle)
{
ngx_core_conf_t *ccf;
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index 8450998..f80271d 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -46,6 +46,7 @@
cycle->pool = pool;
cycle->old_cycle = old_cycle;
+ cycle->conf_file = old_cycle->conf_file;
n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10;
@@ -117,10 +118,8 @@
conf.module_type = NGX_CORE_MODULE;
conf.cmd_type = NGX_MAIN_CONF;
- conf_file.len = sizeof(NGINX_CONF) - 1;
- conf_file.data = NGINX_CONF;
- if (ngx_conf_parse(&conf, &conf_file) != NGX_CONF_OK) {
+ if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) {
ngx_destroy_pool(pool);
return NULL;
}
diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h
index ef311a8..d9f1a60 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -21,7 +21,7 @@
ngx_cycle_t *old_cycle;
- unsigned one_process:1;
+ ngx_str_t conf_file;
};