diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2004-05-18 15:29:08 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2004-05-18 15:29:08 +0000 |
| commit | ab517d58277429bba16d0641e00aebea061db1ce (patch) | |
| tree | fca49eca624c51e0ae7c829f0ce64233496c610e /src/core | |
| parent | 3043bfcf105e47969720d5bce8c3a89afe8e666d (diff) | |
| download | nginx-ab517d58277429bba16d0641e00aebea061db1ce.tar.gz nginx-ab517d58277429bba16d0641e00aebea061db1ce.tar.bz2 | |
nginx-0.0.3-2004-05-18-19:29:08 import
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/ngx_conf_file.c | 50 | ||||
| -rw-r--r-- | src/core/ngx_conf_file.h | 2 | ||||
| -rw-r--r-- | src/core/ngx_cycle.c | 38 | ||||
| -rw-r--r-- | src/core/ngx_cycle.h | 1 |
4 files changed, 90 insertions, 1 deletions
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c index fc4c95079..bb05b72db 100644 --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -3,7 +3,34 @@ #include <ngx_core.h> -/* Ten fixed arguments */ +static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); + + +static ngx_command_t ngx_conf_commands[] = { + + { ngx_string("include"), + NGX_ANY_CONF|NGX_CONF_TAKE1, + ngx_conf_include, + 0, + 0, + NULL }, + + ngx_null_command +}; + + +ngx_module_t ngx_conf_module = { + NGX_MODULE, + NULL, /* module context */ + ngx_conf_commands, /* module directives */ + NGX_CONF_MODULE, /* module type */ + NULL, /* init module */ + NULL /* init child */ +}; + + + +/* The ten fixed arguments */ static int argument_number[] = { NGX_CONF_NOARGS, @@ -513,6 +540,27 @@ ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data); } +static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_str_t *value, file; + + value = cf->args->elts; + + file.len = cf->cycle->root.len + value[1].len; + if (!(file.data = ngx_palloc(cf->pool, file.len + 1))) { + return NGX_CONF_ERROR; + } + + ngx_cpystrn(ngx_cpymem(file.data, cf->cycle->root.data, + cf->cycle->root.len), + value[1].data, value[1].len + 1); + + ngx_log_error(NGX_LOG_INFO, cf->log, 0, "include %s", file.data); + + return ngx_conf_parse(cf, &file); +} + + ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) { ngx_uint_t i; diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h index 01080cc15..ff01e8871 100644 --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -37,7 +37,9 @@ #define NGX_CONF_2MORE 0x00001000 #define NGX_DIRECT_CONF 0x00010000 + #define NGX_MAIN_CONF 0x01000000 +#define NGX_ANY_CONF 0x0F000000 diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index 24e30f7b1..989973a98 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -24,6 +24,7 @@ static ngx_connection_t dumb; ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) { void *rv; + u_char *root; ngx_uint_t i, n, failed; ngx_log_t *log; ngx_conf_t conf; @@ -33,6 +34,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) ngx_open_file_t *file; ngx_listening_t *ls, *nls; ngx_core_module_t *module; + char cwd[NGX_MAX_PATH + 1]; log = old_cycle->log; @@ -51,6 +53,42 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) cycle->conf_file = old_cycle->conf_file; + for (i = cycle->conf_file.len; i > 0; i--) { + if (cycle->conf_file.data[i] == '/') { + break; + } + } + + if (i == 0 && cycle->conf_file.data[i] != '/') { + if (ngx_getcwd(cwd, NGX_MAX_PATH) == 0) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + ngx_getcwd_n " failed"); + ngx_destroy_pool(pool); + return NULL; + } + + for ( /* void */; i < NGX_MAX_PATH && cwd[i]; i++) /* void */; + cwd[i] = '/'; + cwd[i + 1] = '\0'; + + root = (u_char *) cwd; + + } else { + root = cycle->conf_file.data; + } + + cycle->root.len = ++i; + cycle->root.data = ngx_palloc(pool, ++i); + if (cycle->root.data == NULL) { + ngx_destroy_pool(pool); + return NULL; + } + + ngx_cpystrn(cycle->root.data, root, i); + + ngx_log_error(NGX_LOG_INFO, log, 0, "root: %s", cycle->root.data); + + n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10; if (!(cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *)))) { ngx_destroy_pool(pool); diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h index 6588a7a15..e1b536869 100644 --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -25,6 +25,7 @@ struct ngx_cycle_s { ngx_cycle_t *old_cycle; ngx_str_t conf_file; + ngx_str_t root; }; |
