nginx-0.0.3-2004-04-12-20:38:09 import

This commit is contained in:
Igor Sysoev 2004-04-12 16:38:09 +00:00
parent b94bb5ef43
commit 4b496b748f
14 changed files with 264 additions and 320 deletions

View file

@ -76,6 +76,14 @@ case $PLATFORM in
done=YES
;;
*)
echo "$0: error: invalid --with-zlib=asm=$ZLIB_ASM option."
echo "The valid values are \"pentium\" and \"pentiumpro\" only".
echo
exit 1;
;;
esac
;;

View file

@ -7,45 +7,44 @@
static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
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 void *ngx_core_module_create_conf(ngx_cycle_t *cycle);
static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf);
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_str_t core_name = ngx_string("core");
static ngx_command_t ngx_core_commands[] = {
{ ngx_string("user"),
NGX_MAIN_CONF|NGX_CONF_TAKE12,
ngx_set_user,
0,
0,
NULL },
{ ngx_string("daemon"),
NGX_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_core_flag_slot,
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_flag_slot,
0,
offsetof(ngx_core_conf_t, daemon),
NULL },
{ ngx_string("master_process"),
NGX_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_core_flag_slot,
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_flag_slot,
0,
offsetof(ngx_core_conf_t, master),
NULL },
{ ngx_string("worker_processes"),
NGX_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_core_num_slot,
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
0,
offsetof(ngx_core_conf_t, worker_processes),
NULL },
{ ngx_string("user"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE12,
ngx_set_user,
0,
0,
NULL },
{ ngx_string("pid"),
NGX_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_core_str_slot,
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
0,
offsetof(ngx_core_conf_t, pid),
NULL },
@ -54,12 +53,19 @@ static ngx_command_t ngx_core_commands[] = {
};
static ngx_core_module_t ngx_core_module_ctx = {
ngx_string("core"),
ngx_core_module_create_conf,
ngx_core_module_init_conf
};
ngx_module_t ngx_core_module = {
NGX_MODULE,
&core_name, /* module context */
&ngx_core_module_ctx, /* module context */
ngx_core_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
ngx_core_module_init, /* init module */
NULL, /* init module */
NULL /* init child */
};
@ -149,69 +155,32 @@ int main(int argc, char *const *argv)
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
ngx_process = (ccf->master != 0) ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE;
ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE;
#if (WIN32)
#if 0
if (run_as_service) {
if (ngx_servie(cycle->log) == NGX_ERROR) {
if (ccf->run_as_service) {
if (ngx_service(cycle->log) == NGX_ERROR) {
return 1;
}
return 0;
}
#endif
#else
if (!ngx_inherited && ccf->daemon != 0) {
if (!ngx_inherited && ccf->daemon) {
if (ngx_daemon(cycle->log) == NGX_ERROR) {
return 1;
}
}
if (ccf->pid.len == 0) {
ccf->pid.len = sizeof(NGINX_PID) - 1;
ccf->pid.data = NGINX_PID;
ccf->newpid.len = sizeof(NGINX_NEWPID) - 1;
ccf->newpid.data = NGINX_NEWPID;
} else {
ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT);
if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) {
if (ngx_create_pidfile(cycle, NULL) == NGX_ERROR) {
return 1;
}
ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT));
}
len = ngx_snprintf((char *) pid, /* STUB */ 10, PID_T_FMT, ngx_getpid());
ngx_memzero(&ctx.pid, sizeof(ngx_file_t));
ctx.pid.name = ngx_inherited ? ccf->newpid : ccf->pid;
ctx.name = ccf->pid.data;
ctx.pid.fd = ngx_open_file(ctx.pid.name.data, NGX_FILE_RDWR,
NGX_FILE_CREATE_OR_OPEN);
if (ctx.pid.fd == NGX_INVALID_FILE) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
ngx_open_file_n " \"%s\" failed", ctx.pid.name.data);
return 1;
}
if (ngx_write_file(&ctx.pid, pid, len, 0) == NGX_ERROR) {
return 1;
}
if (ngx_close_file(ctx.pid.fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_close_file_n " \"%s\" failed", ctx.pid.name.data);
}
#endif
ngx_master_process_cycle(cycle, &ctx);
@ -336,22 +305,12 @@ 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 void *ngx_core_module_create_conf(ngx_cycle_t *cycle)
{
ngx_core_conf_t *ccf;
/*
* ngx_core_module has a special init procedure: it is called by
* ngx_init_cycle() before the configuration file parsing to create
* ngx_core_module configuration and to set its default parameters
*/
if (((void **)(cycle->conf_ctx))[ngx_core_module.index] != NULL) {
return NGX_OK;
}
if (!(ccf = ngx_pcalloc(cycle->pool, sizeof(ngx_core_conf_t)))) {
return NGX_ERROR;
return NULL;
}
/* set by pcalloc()
*
@ -364,9 +323,41 @@ static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle)
ccf->user = (ngx_uid_t) NGX_CONF_UNSET;
ccf->group = (ngx_gid_t) NGX_CONF_UNSET;
((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf;
return ccf;
}
return NGX_OK;
static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_core_conf_t *ccf = conf;
ngx_conf_init_value(ccf->daemon, 1);
ngx_conf_init_value(ccf->master, 1);
ngx_conf_init_value(ccf->worker_processes, 1);
#if !(WIN32)
/* TODO: default "nobody" user */
if (ccf->pid.len == 0) {
ccf->pid.len = sizeof(NGINX_PID) - 1;
ccf->pid.data = NGINX_PID;
ccf->newpid.len = sizeof(NGINX_NEWPID) - 1;
ccf->newpid.data = NGINX_NEWPID;
} else {
ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT);
if (!(ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len))) {
return NGX_CONF_ERROR;
}
ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT));
}
#endif
return NGX_CONF_OK;
}
@ -381,12 +372,11 @@ static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
#else
ngx_core_conf_t *ccf = conf;
struct passwd *pwd;
struct group *grp;
ngx_str_t *value;
ngx_core_conf_t *ccf;
ccf = *(void **)conf;
if (ccf->user != (uid_t) NGX_CONF_UNSET) {
return "is duplicate";

View file

@ -13,9 +13,7 @@ static int argument_number[] = {
NGX_CONF_TAKE4,
NGX_CONF_TAKE5,
NGX_CONF_TAKE6,
NGX_CONF_TAKE7,
NGX_CONF_TAKE8,
NGX_CONF_TAKE9,
NGX_CONF_TAKE7
};
static int ngx_conf_read_token(ngx_conf_t *cf);
@ -204,7 +202,10 @@ ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data);
conf = NULL;
if (cf->module_type == NGX_CORE_MODULE) {
if (cmd->type & NGX_DIRECT_CONF) {
conf = ((void **) cf->ctx)[ngx_modules[m]->index];
} else if (cmd->type & NGX_MAIN_CONF) {
conf = &(((void **) cf->ctx)[ngx_modules[m]->index]);
} else if (cf->ctx) {
@ -564,27 +565,6 @@ void ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
}
char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
{
return ngx_conf_set_flag_slot(cf, cmd, *(void **)conf);
}
char *ngx_conf_set_core_num_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
{
return ngx_conf_set_num_slot(cf, cmd, *(void **)conf);
}
char *ngx_conf_set_core_str_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
{
return ngx_conf_set_str_slot(cf, cmd, *(void **)conf);
}
char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;

View file

@ -20,8 +20,6 @@
#define NGX_CONF_TAKE5 0x00000020
#define NGX_CONF_TAKE6 0x00000040
#define NGX_CONF_TAKE7 0x00000080
#define NGX_CONF_TAKE8 0x00000100
#define NGX_CONF_TAKE9 0x00000200
#define NGX_CONF_TAKE12 (NGX_CONF_TAKE1|NGX_CONF_TAKE2)
#define NGX_CONF_TAKE13 (NGX_CONF_TAKE1|NGX_CONF_TAKE3)
@ -31,13 +29,14 @@
#define NGX_CONF_TAKE1234 (NGX_CONF_TAKE1|NGX_CONF_TAKE2|NGX_CONF_TAKE3 \
|NGX_CONF_TAKE4)
#define NGX_CONF_ARGS_NUMBER 0x0000ffff
#define NGX_CONF_BLOCK 0x00010000
#define NGX_CONF_FLAG 0x00020000
#define NGX_CONF_ANY 0x00040000
#define NGX_CONF_1MORE 0x00080000
#define NGX_CONF_2MORE 0x00100000
#define NGX_CONF_ARGS_NUMBER 0x000000ff
#define NGX_CONF_BLOCK 0x00000100
#define NGX_CONF_FLAG 0x00000200
#define NGX_CONF_ANY 0x00000400
#define NGX_CONF_1MORE 0x00000800
#define NGX_CONF_2MORE 0x00001000
#define NGX_DIRECT_CONF 0x00010000
#define NGX_MAIN_CONF 0x01000000
@ -101,6 +100,13 @@ struct ngx_module_s {
};
typedef struct {
ngx_str_t name;
void *(*create_conf)(ngx_cycle_t *cycle);
char *(*init_conf)(ngx_cycle_t *cycle, void *conf);
} ngx_core_module_t;
typedef struct {
ngx_file_t file;
ngx_hunk_t *hunk;
@ -254,13 +260,6 @@ char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_bitmask_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
char *ngx_conf_set_core_num_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
char *ngx_conf_set_core_str_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
extern ngx_int_t ngx_max_module;
extern ngx_module_t *ngx_modules[];

View file

@ -2,8 +2,6 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_event.h>
/* STUB */
#include <nginx.h>
static void ngx_clean_old_cycles(ngx_event_t *ev);
@ -23,6 +21,7 @@ static ngx_connection_t dumb;
ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
{
void *rv;
ngx_uint_t i, n, failed;
ngx_log_t *log;
ngx_conf_t conf;
@ -30,8 +29,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
ngx_cycle_t *cycle, **old;
ngx_socket_t fd;
ngx_open_file_t *file;
ngx_core_conf_t *ccf;
ngx_listening_t *ls, *nls;
ngx_core_module_t *module;
log = old_cycle->log;
@ -97,10 +96,22 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
if (ngx_core_module.init_module(cycle) == NGX_ERROR) {
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->type != NGX_CORE_MODULE) {
continue;
}
module = ngx_modules[i]->ctx;
if (module->create_conf) {
rv = module->create_conf(cycle);
if (rv == NGX_CONF_ERROR) {
ngx_destroy_pool(pool);
return NULL;
}
cycle->conf_ctx[ngx_modules[i]->index] = rv;
}
}
ngx_memzero(&conf, sizeof(ngx_conf_t));
@ -125,10 +136,35 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->type != NGX_CORE_MODULE) {
continue;
}
module = ngx_modules[i]->ctx;
if (module->init_conf) {
if (module->init_conf(cycle, cycle->conf_ctx[ngx_modules[i]->index])
== NGX_CONF_ERROR)
{
ngx_destroy_pool(pool);
return NULL;
}
}
}
failed = 0;
#if !(WIN32)
if (ngx_create_pidfile(cycle, old_cycle) == NGX_ERROR) {
failed = 1;
}
#endif
if (!failed) {
file = cycle->open_files.elts;
for (i = 0; i < cycle->open_files.nelts; i++) {
if (file[i].name.data == NULL) {
@ -165,6 +201,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
#endif
}
}
if (!failed) {
if (old_cycle->listening.nelts) {
@ -374,75 +412,77 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
static ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
#if !(WIN32)
ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
{
size_t len;
u_char pid[NGX_INT64_LEN + 1];
ngx_str_t name;
ngx_core_conf_t *ccf;
u_char *name, pid[NGX_INT64_LEN + 1];
ngx_file_t file;
ngx_core_conf_t *ccf, *old_ccf;
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (old_cycle && old_cycle->conf_ctx == NULL) {
/*
* do not create the pid file in the first ngx_init_cycle() call
* because we need to write the demonized process pid
*/
if (ctx->pid.len) {
if (ccf->pid.len == 0) {
return NGX_OK;
}
if (ctx->pid.len == ccf->pid.len
&& ngx_strcmp(ctx->pid.data, ccf->pid.data) == 0)
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (old_cycle) {
old_ccf = (ngx_core_conf_t *) ngx_get_conf(old_cycle->conf_ctx,
ngx_core_module);
if (ccf->pid.len == old_ccf->pid.len
&& ngx_strcmp(ccf->pid.data, old_ccf->pid.data) == 0)
{
return NGX_OK;
}
}
if (ccf->pid.len == 0) {
ccf->pid.len = sizeof(NGINX_PID) - 1;
ccf->pid.data = NGINX_PID;
ccf->newpid.len = sizeof(NGINX_NEWPID) - 1;
ccf->newpid.data = NGINX_NEWPID;
} else {
ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT);
if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) {
return NGX_ERROR;
}
ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT));
}
len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid);
ngx_memzero(&ctx->pid, sizeof(ngx_file_t));
ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid;
ctx->name = ccf->pid.data;
ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR,
ngx_memzero(&file, sizeof(ngx_file_t));
file.name = (ngx_inherited && getppid() > 1) ? ccf->newpid : ccf->pid;
file.log = cycle->log;
file.fd = ngx_open_file(file.name.data, NGX_FILE_RDWR,
NGX_FILE_CREATE_OR_OPEN);
if (ctx->pid.fd == NGX_INVALID_FILE) {
if (file.fd == NGX_INVALID_FILE) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
ngx_open_file_n " \"%s\" failed", ctx->pid.name.data);
ngx_open_file_n " \"%s\" failed", file.name.data);
return NGX_ERROR;
}
if (ngx_write_file(&ctx->pid, pid, len, 0) == NGX_ERROR) {
if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) {
return NGX_ERROR;
}
if (ngx_close_file(ctx->pid.fd) == NGX_FILE_ERROR) {
if (ngx_close_file(file.fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_close_file_n " \"%s\" failed", ctx->pid.name.data);
ngx_close_file_n " \"%s\" failed", file.name.data);
}
ngx_delete_pidfile(old_cycle);
return NGX_OK;
}
static void ngx_delete_pidfile(ngx_cycle_t *cycle)
void ngx_delete_pidfile(ngx_cycle_t *cycle)
{
u_char *name;
ngx_core_conf_t *ccf;
if (cycle == NULL || cycle->conf_ctx == NULL) {
return;
}
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (ngx_inherited && getppid() > 1) {
@ -458,6 +498,8 @@ static void ngx_delete_pidfile(ngx_cycle_t *cycle)
}
}
#endif
void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
{

View file

@ -40,6 +40,8 @@ typedef struct {
ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle);
ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle);
void ngx_delete_pidfile(ngx_cycle_t *cycle);
void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user);
ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv);

View file

@ -7,8 +7,6 @@ static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len);
static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_str_t errlog_name = ngx_string("errlog");
static ngx_command_t ngx_errlog_commands[] = {
{ngx_string("error_log"),
@ -22,9 +20,16 @@ static ngx_command_t ngx_errlog_commands[] = {
};
static ngx_core_module_t ngx_errlog_module_ctx = {
ngx_string("errlog"),
NULL,
NULL
};
ngx_module_t ngx_errlog_module = {
NGX_MODULE,
&errlog_name, /* module context */
&ngx_errlog_module_ctx, /* module context */
ngx_errlog_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
NULL, /* init module */

View file

@ -263,6 +263,7 @@ static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags)
if (flags & NGX_CLOSE_EVENT) {
ev->active = 0;
ev->posted = 0;
return NGX_OK;
}
@ -437,10 +438,6 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
log = c->log ? c->log : cycle->log;
#endif
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0,
"epoll: fd:%d ev:%04X d:" PTR_FMT,
c->fd, event_list[i].events, event_list[i].data);
if (c->read->instance != instance) {
/*
@ -453,6 +450,10 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
continue;
}
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0,
"epoll: fd:%d ev:%04X d:" PTR_FMT,
c->fd, event_list[i].events, event_list[i].data);
if (event_list[i].events & (EPOLLERR|EPOLLHUP)) {
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
"epoll_wait() error on fd:%d ev:%04X",

View file

@ -263,6 +263,7 @@ static int ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags)
*/
if (flags & NGX_CLOSE_EVENT) {
ev->posted = 0;
return NGX_OK;
}
@ -464,10 +465,6 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
ev = (ngx_event_t *) ((uintptr_t) ev & (uintptr_t) ~1);
ev->returned_instance = instance;
if (ev->log && (ev->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
ngx_kqueue_dump_event(ev->log, &event_list[i]);
}
if (!ev->active || ev->instance != instance) {
/*
@ -480,6 +477,10 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
continue;
}
if (ev->log && (ev->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
ngx_kqueue_dump_event(ev->log, &event_list[i]);
}
ev->available = event_list[i].data;
if (event_list[i].flags & EV_EOF) {

View file

@ -59,8 +59,6 @@ ngx_msec_t ngx_accept_mutex_delay;
static ngx_str_t events_name = ngx_string("events");
static ngx_command_t ngx_events_commands[] = {
{ ngx_string("events"),
@ -74,9 +72,16 @@ static ngx_command_t ngx_events_commands[] = {
};
static ngx_core_module_t ngx_events_module_ctx = {
ngx_string("events"),
NULL,
NULL
};
ngx_module_t ngx_events_module = {
NGX_MODULE,
&events_name, /* module context */
&ngx_events_module_ctx, /* module context */
ngx_events_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
NULL, /* init module */

View file

@ -18,9 +18,6 @@ int (*ngx_http_top_header_filter) (ngx_http_request_t *r);
int (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch);
static ngx_str_t http_name = ngx_string("http");
static ngx_command_t ngx_http_commands[] = {
{ngx_string("http"),
@ -34,9 +31,16 @@ static ngx_command_t ngx_http_commands[] = {
};
static ngx_core_module_t ngx_http_module_ctx = {
ngx_string("http"),
NULL,
NULL
};
ngx_module_t ngx_http_module = {
NGX_MODULE,
&http_name, /* module context */
&ngx_http_module_ctx, /* module context */
ngx_http_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
NULL, /* init module */

View file

@ -35,9 +35,9 @@ typedef struct {
#define NGX_HTTP_MODULE 0x50545448 /* "HTTP" */
#define NGX_HTTP_MAIN_CONF 0x2000000
#define NGX_HTTP_SRV_CONF 0x4000000
#define NGX_HTTP_LOC_CONF 0x8000000
#define NGX_HTTP_MAIN_CONF 0x02000000
#define NGX_HTTP_SRV_CONF 0x04000000
#define NGX_HTTP_LOC_CONF 0x08000000
#define NGX_HTTP_MAIN_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, main_conf)

View file

@ -12,8 +12,6 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
static int ngx_worker_thread_cycle(void *data);
#endif
static void ngx_delete_pidfile(ngx_cycle_t *cycle);
ngx_int_t ngx_process;
ngx_pid_t ngx_pid;
@ -76,10 +74,6 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
ngx_core_module);
if (ccf->worker_processes == NGX_CONF_UNSET) {
ccf->worker_processes = 1;
}
if (ngx_process == NGX_PROCESS_MASTER) {
for (i = 0; i < (ngx_uint_t) ccf->worker_processes; i++) {
ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
@ -524,88 +518,3 @@ int ngx_worker_thread_cycle(void *data)
}
#endif
static ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
{
size_t len;
u_char pid[NGX_INT64_LEN + 1];
ngx_str_t name;
ngx_core_conf_t *ccf;
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (ctx->pid.len) {
if (ccf->pid.len == 0) {
return NGX_OK;
}
if (ctx->pid.len == ccf->pid.len
&& ngx_strcmp(ctx->pid.data, ccf->pid.data) == 0)
{
return NGX_OK;
}
}
if (ccf->pid.len == 0) {
ccf->pid.len = sizeof(NGINX_PID) - 1;
ccf->pid.data = NGINX_PID;
ccf->newpid.len = sizeof(NGINX_NEWPID) - 1;
ccf->newpid.data = NGINX_NEWPID;
} else {
ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT);
if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) {
return NGX_ERROR;
}
ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT));
}
len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid);
ngx_memzero(&ctx->pid, sizeof(ngx_file_t));
ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid;
ctx->name = ccf->pid.data;
ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR,
NGX_FILE_CREATE_OR_OPEN);
if (ctx->pid.fd == NGX_INVALID_FILE) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
ngx_open_file_n " \"%s\" failed", ctx->pid.name.data);
return NGX_ERROR;
}
if (ngx_write_file(&ctx->pid, pid, len, 0) == NGX_ERROR) {
return NGX_ERROR;
}
if (ngx_close_file(ctx->pid.fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_close_file_n " \"%s\" failed", ctx->pid.name.data);
}
return NGX_OK;
}
static void ngx_delete_pidfile(ngx_cycle_t *cycle)
{
u_char *name;
ngx_core_conf_t *ccf;
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (ngx_inherited && getppid() > 1) {
name = ccf->newpid.data;
} else {
name = ccf->pid.data;
}
if (ngx_delete_file(name) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_delete_file_n " \"%s\" failed", name);
}
}

View file

@ -7,8 +7,6 @@
typedef struct {
ngx_file_t pid;
u_char *name;
int argc;
char *const *argv;
} ngx_master_ctx_t;