Mercurial > hg > nginx
comparison src/core/nginx.c @ 255:e6938ca7331a
nginx-0.0.2-2004-02-09-23:47:18 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 09 Feb 2004 20:47:18 +0000 |
parents | b6793bc5034b |
children | 8e39cab6abd5 |
comparison
equal
deleted
inserted
replaced
254:98c77ca0f354 | 255:e6938ca7331a |
---|---|
17 | 17 |
18 | 18 |
19 typedef struct { | 19 typedef struct { |
20 ngx_file_t pid; | 20 ngx_file_t pid; |
21 char *name; | 21 char *name; |
22 int argc; | |
22 char *const *argv; | 23 char *const *argv; |
23 } ngx_master_ctx_t; | 24 } ngx_master_ctx_t; |
24 | 25 |
25 | 26 |
26 static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); | 27 static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); |
27 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); | 28 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); |
28 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); | 29 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); |
29 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp); | 30 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle, char **envp); |
30 static ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv); | 31 static ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv); |
32 static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle); | |
31 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle); | 33 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle); |
32 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 34 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
33 | 35 |
34 | 36 |
35 static ngx_str_t core_name = ngx_string("core"); | 37 static ngx_str_t core_name = ngx_string("core"); |
53 { ngx_string("master_process"), | 55 { ngx_string("master_process"), |
54 NGX_MAIN_CONF|NGX_CONF_TAKE1, | 56 NGX_MAIN_CONF|NGX_CONF_TAKE1, |
55 ngx_conf_set_core_flag_slot, | 57 ngx_conf_set_core_flag_slot, |
56 0, | 58 0, |
57 offsetof(ngx_core_conf_t, master), | 59 offsetof(ngx_core_conf_t, master), |
60 NULL }, | |
61 | |
62 { ngx_string("pid"), | |
63 NGX_MAIN_CONF|NGX_CONF_TAKE1, | |
64 ngx_conf_set_core_str_slot, | |
65 0, | |
66 offsetof(ngx_core_conf_t, pid), | |
58 NULL }, | 67 NULL }, |
59 | 68 |
60 { ngx_string("worker_reopen"), | 69 { ngx_string("worker_reopen"), |
61 NGX_MAIN_CONF|NGX_CONF_TAKE1, | 70 NGX_MAIN_CONF|NGX_CONF_TAKE1, |
62 ngx_conf_set_core_flag_slot, | 71 ngx_conf_set_core_flag_slot, |
123 #endif | 132 #endif |
124 | 133 |
125 log = ngx_log_init_errlog(); | 134 log = ngx_log_init_errlog(); |
126 ngx_pid = ngx_getpid(); | 135 ngx_pid = ngx_getpid(); |
127 | 136 |
128 /* init_cycle->log is required for signal handlers */ | 137 /* init_cycle->log is required for signal handlers and ngx_getopt() */ |
129 | 138 |
130 ngx_memzero(&init_cycle, sizeof(ngx_cycle_t)); | 139 ngx_memzero(&init_cycle, sizeof(ngx_cycle_t)); |
131 init_cycle.log = log; | 140 init_cycle.log = log; |
132 ngx_cycle = &init_cycle; | 141 ngx_cycle = &init_cycle; |
142 | |
143 ngx_memzero(&ctx, sizeof(ngx_master_ctx_t)); | |
144 ctx.argc = argc; | |
145 ctx.argv = argv; | |
146 | |
147 if (ngx_getopt(&ctx, &init_cycle) == NGX_ERROR) { | |
148 return 1; | |
149 } | |
133 | 150 |
134 if (ngx_os_init(log) == NGX_ERROR) { | 151 if (ngx_os_init(log) == NGX_ERROR) { |
135 return 1; | 152 return 1; |
136 } | 153 } |
137 | 154 |
210 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 227 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
211 ngx_close_file_n " \"%s\" failed", ctx.pid.name.data); | 228 ngx_close_file_n " \"%s\" failed", ctx.pid.name.data); |
212 } | 229 } |
213 | 230 |
214 #endif | 231 #endif |
215 | |
216 ctx.argv = argv; | |
217 | 232 |
218 ngx_master_process_cycle(cycle, &ctx); | 233 ngx_master_process_cycle(cycle, &ctx); |
219 | 234 |
220 return 0; | 235 return 0; |
221 } | 236 } |
743 | 758 |
744 return pid; | 759 return pid; |
745 } | 760 } |
746 | 761 |
747 | 762 |
763 static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle) | |
764 { | |
765 ngx_int_t i; | |
766 | |
767 for (i = 1; i < ctx->argc; i++) { | |
768 if (ctx->argv[i][0] != '-') { | |
769 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | |
770 "invalid option: \"%s\"", ctx->argv[i]); | |
771 return NGX_ERROR; | |
772 } | |
773 | |
774 switch (ctx->argv[i][1]) { | |
775 | |
776 case 'c': | |
777 cycle->conf_file.data = ctx->argv[++i]; | |
778 cycle->conf_file.len = ngx_strlen(cycle->conf_file.data); | |
779 break; | |
780 | |
781 default: | |
782 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | |
783 "invalid option: \"%s\"", ctx->argv[i]); | |
784 return NGX_ERROR; | |
785 } | |
786 } | |
787 | |
788 if (cycle->conf_file.len == NULL) { | |
789 cycle->conf_file.len = sizeof(NGINX_CONF) - 1; | |
790 cycle->conf_file.data = NGINX_CONF; | |
791 } | |
792 | |
793 return NGX_OK; | |
794 } | |
795 | |
796 | |
748 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle) | 797 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle) |
749 { | 798 { |
750 ngx_core_conf_t *ccf; | 799 ngx_core_conf_t *ccf; |
751 | 800 |
752 /* | 801 /* |