diff options
author | Igor Sysoev <igor@sysoev.ru> | 2008-06-30 16:35:16 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2008-06-30 16:35:16 +0400 |
commit | b4fbdcf5d4bdaad5b762c2852c88123ed54a4bbb (patch) | |
tree | 66b1f911ac5d19ca710c753bbd15bf5a0dc505a4 | |
parent | b882154636c92aede2b682e4ae10c324d8d5cf35 (diff) |
-g switch
-rw-r--r-- | src/core/nginx.c | 14 | ||||
-rw-r--r-- | src/core/ngx_conf_file.c | 71 | ||||
-rw-r--r-- | src/core/ngx_conf_file.h | 1 | ||||
-rw-r--r-- | src/core/ngx_cycle.c | 15 | ||||
-rw-r--r-- | src/core/ngx_cycle.h | 1 |
5 files changed, 95 insertions, 7 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index 450edf374..fb4ac2616 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -637,8 +637,7 @@ ngx_getopt(ngx_cycle_t *cycle, int argc, char *const *argv) case 'c': if (argv[i + 1] == NULL) { ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, - "the option: \"%s\" requires file name", - argv[i]); + "the option \"-c\" requires file name"); return NGX_ERROR; } @@ -646,6 +645,17 @@ ngx_getopt(ngx_cycle_t *cycle, int argc, char *const *argv) cycle->conf_file.len = ngx_strlen(cycle->conf_file.data); break; + case 'g': + if (argv[i + 1] == NULL) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, + "the option \"-g\" requires parameter"); + return NGX_ERROR; + } + + cycle->conf_param.data = (u_char *) argv[++i]; + cycle->conf_param.len = ngx_strlen(cycle->conf_param.data); + break; + default: ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "invalid option: \"%s\"", argv[i]); diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c index dbeb39d0c..7da9997ca 100644 --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -58,14 +58,52 @@ static int argument_number[] = { char * +ngx_conf_param(ngx_conf_t *cf) +{ + ngx_str_t *param; + ngx_buf_t b; + ngx_conf_file_t conf_file; + + param = &cf->cycle->conf_param; + + if (param->len == 0) { + return NGX_CONF_OK; + } + + ngx_memzero(&conf_file, sizeof(ngx_conf_file_t)); + + ngx_memzero(&b, sizeof(ngx_buf_t)); + + b.start = param->data; + b.pos = param->data; + b.last = param->data + param->len; + b.end = b.last; + b.temporary = 1; + + conf_file.file.fd = NGX_INVALID_FILE; + conf_file.file.name.data = (u_char *) "command line"; + conf_file.line = 1; + + cf->conf_file = &conf_file; + cf->conf_file->buffer = &b; + + return ngx_conf_parse(cf, NULL); +} + + +char * ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) { char *rv; ngx_fd_t fd; ngx_int_t rc; ngx_buf_t *b; - ngx_uint_t block; ngx_conf_file_t *prev; + enum { + parse_file = 0, + parse_block, + parse_param + } type; #if (NGX_SUPPRESS_WARN) fd = NGX_INVALID_FILE; @@ -120,10 +158,14 @@ ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) cf->conf_file->file.log = cf->log; cf->conf_file->line = 1; - block = 0; + type = parse_file; + + } else if (cf->conf_file->file.fd != NGX_INVALID_FILE) { + + type = parse_block; } else { - block = 1; + type = parse_param; } @@ -146,7 +188,7 @@ ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) if (rc == NGX_CONF_BLOCK_DONE) { - if (!block) { + if (type != parse_block) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "unexpected \"}\""); goto failed; } @@ -156,7 +198,7 @@ ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) if (rc == NGX_CONF_FILE_DONE) { - if (block) { + if (type == parse_block) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "unexpected end of file, expecting \"}\""); goto failed; @@ -165,6 +207,16 @@ ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) goto done; } + if (rc == NGX_CONF_BLOCK_START) { + + if (type == parse_param) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "block directives are not supported " + "in -g option"); + goto failed; + } + } + /* rc == NGX_OK || rc == NGX_CONF_BLOCK_START */ if (cf->handler) { @@ -402,10 +454,19 @@ ngx_conf_read_token(ngx_conf_t *cf) for ( ;; ) { if (b->pos >= b->last) { + if (cf->conf_file->file.offset >= ngx_file_size(&cf->conf_file->file.info)) { if (cf->args->nelts > 0) { + + if (cf->conf_file->file.fd == NGX_INVALID_FILE) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "unexpected end of parameter, " + "expecting \";\""); + return NGX_ERROR; + } + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "unexpected end of file, " "expecting \";\" or \"}\""); diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h index c3e3e9a91..5957341ff 100644 --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -317,6 +317,7 @@ char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data); #define addressof(addr) ((int) &addr) +char *ngx_conf_param(ngx_conf_t *cf); char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename); diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index a82e8506b..725f54b49 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -90,6 +90,16 @@ ngx_init_cycle(ngx_cycle_t *old_cycle) old_cycle->conf_file.len + 1); + cycle->conf_param.len = old_cycle->conf_param.len; + cycle->conf_param.data = ngx_pnalloc(pool, old_cycle->conf_param.len); + if (cycle->conf_param.data == NULL) { + ngx_destroy_pool(pool); + return NULL; + } + ngx_memcpy(cycle->conf_param.data, old_cycle->conf_param.data, + old_cycle->conf_param.len); + + n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10; cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *)); @@ -238,6 +248,11 @@ ngx_init_cycle(ngx_cycle_t *old_cycle) log->log_level = NGX_LOG_DEBUG_ALL; #endif + if (ngx_conf_param(&conf) != NGX_CONF_OK) { + ngx_destroy_cycle_pools(&conf); + return NULL; + } + if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) { ngx_destroy_cycle_pools(&conf); return NULL; diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h index 845ce8771..e42f46bb6 100644 --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -60,6 +60,7 @@ struct ngx_cycle_s { ngx_cycle_t *old_cycle; ngx_str_t conf_file; + ngx_str_t conf_param; ngx_str_t root; ngx_str_t lock_file; ngx_str_t hostname; |