static int ngx_open_listening_sockets(ngx_cycle_t *cycle, ngx_log_t *log);
static void ngx_clean_old_cycles(ngx_event_t *ev);
+
#if (NGX_DEBUG) && (__FreeBSD__)
extern char *malloc_options;
#endif
+
+typedef struct {
+ int daemon;
+} ngx_core_conf_t;
+
+
+static ngx_str_t core_name = ngx_string("core");
+
+static ngx_command_t ngx_core_commands[] = {
+
+ {ngx_string("daemon"),
+ NGX_MAIN_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_core_flag_slot,
+ 0,
+ offsetof(ngx_core_conf_t, daemon),
+ NULL},
+
+ ngx_null_command
+};
+
+
+ngx_module_t ngx_core_module = {
+ NGX_MODULE,
+ &core_name, /* module context */
+ ngx_core_commands, /* module directives */
+ NGX_CORE_MODULE, /* module type */
+ NULL, /* init module */
+ NULL /* init child */
+};
+
+
int ngx_max_module;
ngx_os_io_t ngx_io;
int main(int argc, char *const *argv)
{
- int i;
- ngx_log_t *log;
- ngx_cycle_t *cycle;
+ int i;
+ ngx_log_t *log;
+ ngx_cycle_t *cycle;
+ ngx_core_conf_t *ccf;
#if (NGX_DEBUG) && (__FreeBSD__)
malloc_options = "J";
#if !(WIN32)
- if (0) {
- if (ngx_daemon(cycle->log) == NGX_ERROR) {
+ ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx,
+ ngx_core_module);
+
+ if (ccf->daemon != 0) {
+ if (ngx_daemon(ngx_cycle->log) == NGX_ERROR) {
return 1;
}
}
- if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed");
+ if (dup2(ngx_cycle->log->file->fd, STDERR_FILENO) == -1) {
+ ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno,
+ "dup2(STDERR) failed");
return 1;
}
ngx_conf_t conf;
ngx_pool_t *pool;
ngx_cycle_t *cycle, **old;
+ ngx_core_conf_t *ccf;
ngx_open_file_t *file;
ngx_listening_t *ls, *nls;
cycle->old_cycle = old_cycle;
+
n = old_cycle ? old_cycle->open_files.nelts : 20;
cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t));
if (cycle->open_files.elts == NULL) {
cycle->open_files.nalloc = n;
cycle->open_files.pool = pool;
+
cycle->log = ngx_log_create_errlog(cycle, NULL);
if (cycle->log == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
+
n = old_cycle ? old_cycle->listening.nelts : 10;
cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
if (cycle->listening.elts == NULL) {
cycle->listening.nalloc = n;
cycle->listening.pool = pool;
+
cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *));
if (cycle->conf_ctx == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
+
+ ccf = ngx_pcalloc(pool, sizeof(ngx_core_conf_t));
+ if (ccf == NULL) {
+ ngx_destroy_pool(pool);
+ return NULL;
+ }
+ ccf->daemon = -1;
+ ((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf;
+
+
ngx_memzero(&conf, sizeof(ngx_conf_t));
/* STUB: init array ? */
conf.args = ngx_create_array(pool, 10, sizeof(ngx_str_t));
return NULL;
}
+
failed = 0;
file = cycle->open_files.elts;
int rc, boundary, len, i;
char *p;
off_t start, end;
+ ngx_table_elt_t *accept_ranges;
ngx_http_range_t *range;
ngx_http_range_filter_ctx_t *ctx;
|| r->headers_out.status != NGX_HTTP_OK
|| r->headers_out.content_length == -1
/* STUB: we currently support ranges for file hunks only */
- || r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY
- || r->headers_in.range == NULL
+ || r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY)
+ {
+ return next_header_filter(r);
+ }
+
+ if (r->headers_in.range == NULL
|| r->headers_in.range->value.len < 7
|| ngx_strncasecmp(r->headers_in.range->value.data, "bytes=", 6) != 0)
{
+ ngx_test_null(accept_ranges,
+ ngx_push_table(r->headers_out.headers),
+ NGX_ERROR);
+
+ accept_ranges->key.len = sizeof("Accept-Ranges") - 1;
+ accept_ranges->key.data = "Accept-Ranges";
+ accept_ranges->value.len = sizeof("bytes") - 1;
+ accept_ranges->value.data = "bytes";
+
return next_header_filter(r);
}