Mercurial > hg > nginx
comparison src/core/nginx.c @ 2725:d43d73277c5c
Win32 master/workers model
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 20 Apr 2009 06:08:47 +0000 |
parents | ffa8e2451457 |
children | 95a17423afdb |
comparison
equal
deleted
inserted
replaced
2724:9fd2f12fee0a | 2725:d43d73277c5c |
---|---|
178 NULL, /* exit master */ | 178 NULL, /* exit master */ |
179 NGX_MODULE_V1_PADDING | 179 NGX_MODULE_V1_PADDING |
180 }; | 180 }; |
181 | 181 |
182 | 182 |
183 ngx_uint_t ngx_max_module; | 183 ngx_uint_t ngx_max_module; |
184 | 184 |
185 static ngx_uint_t ngx_show_version; | 185 static ngx_uint_t ngx_show_version; |
186 static ngx_uint_t ngx_show_configure; | 186 static ngx_uint_t ngx_show_configure; |
187 #if (NGX_WIN32) | |
188 static char *ngx_signal; | |
189 #endif | |
190 | |
187 | 191 |
188 static char **ngx_os_environ; | 192 static char **ngx_os_environ; |
189 | 193 |
190 | 194 |
191 int ngx_cdecl | 195 int ngx_cdecl |
301 | 305 |
302 ngx_cycle = cycle; | 306 ngx_cycle = cycle; |
303 | 307 |
304 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | 308 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
305 | 309 |
306 ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE; | 310 if (ccf->master && ngx_process == NGX_PROCESS_SINGLE) { |
311 ngx_process = NGX_PROCESS_MASTER; | |
312 } | |
307 | 313 |
308 #if (NGX_WIN32) | 314 #if (NGX_WIN32) |
309 | 315 |
310 #if 0 | 316 if (ngx_signal) { |
311 | 317 return ngx_signal_process(cycle, ngx_signal); |
312 TODO: | 318 } |
313 | |
314 if (ccf->run_as_service) { | |
315 if (ngx_service(cycle->log) != NGX_OK) { | |
316 return 1; | |
317 } | |
318 | |
319 return 0; | |
320 } | |
321 #endif | |
322 | 319 |
323 #else | 320 #else |
324 | 321 |
325 if (ngx_init_signals(cycle->log) != NGX_OK) { | 322 if (ngx_init_signals(cycle->log) != NGX_OK) { |
326 return 1; | 323 return 1; |
332 } | 329 } |
333 | 330 |
334 ngx_daemonized = 1; | 331 ngx_daemonized = 1; |
335 } | 332 } |
336 | 333 |
334 #endif | |
335 | |
337 if (ngx_create_pidfile(&ccf->pid, cycle->log) != NGX_OK) { | 336 if (ngx_create_pidfile(&ccf->pid, cycle->log) != NGX_OK) { |
338 return 1; | 337 return 1; |
339 } | 338 } |
340 | 339 |
341 #endif | 340 if (ngx_process == NGX_PROCESS_SINGLE) { |
342 | 341 ngx_single_process_cycle(cycle); |
343 if (ngx_process == NGX_PROCESS_MASTER) { | 342 |
343 } else { | |
344 ngx_master_process_cycle(cycle); | 344 ngx_master_process_cycle(cycle); |
345 | |
346 } else { | |
347 ngx_single_process_cycle(cycle); | |
348 } | 345 } |
349 | 346 |
350 return 0; | 347 return 0; |
351 } | 348 } |
352 | 349 |
643 | 640 |
644 cycle->conf_param.data = (u_char *) argv[++i]; | 641 cycle->conf_param.data = (u_char *) argv[++i]; |
645 cycle->conf_param.len = ngx_strlen(cycle->conf_param.data); | 642 cycle->conf_param.len = ngx_strlen(cycle->conf_param.data); |
646 break; | 643 break; |
647 | 644 |
645 #if (NGX_WIN32) | |
646 case 's': | |
647 if (argv[++i] == NULL) { | |
648 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | |
649 "the option \"-s\" requires parameter"); | |
650 return NGX_ERROR; | |
651 } | |
652 | |
653 if (ngx_strcmp(argv[i], "stop") == 0 | |
654 || ngx_strcmp(argv[i], "quit") == 0 | |
655 || ngx_strcmp(argv[i], "reopen") == 0 | |
656 || ngx_strcmp(argv[i], "reload") == 0) | |
657 { | |
658 ngx_process = NGX_PROCESS_SIGNALLER; | |
659 ngx_signal = argv[i]; | |
660 break; | |
661 } | |
662 | |
663 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | |
664 "invalid option: \"-s %s\"", argv[i]); | |
665 return NGX_ERROR; | |
666 #endif | |
667 | |
648 default: | 668 default: |
649 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, | 669 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, |
650 "invalid option: \"%s\"", argv[i]); | 670 "invalid option: \"%s\"", argv[i]); |
651 return NGX_ERROR; | 671 return NGX_ERROR; |
652 } | 672 } |
784 ngx_threads_n = ccf->worker_threads; | 804 ngx_threads_n = ccf->worker_threads; |
785 ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024); | 805 ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024); |
786 | 806 |
787 #endif | 807 #endif |
788 | 808 |
809 | |
810 if (ccf->pid.len == 0) { | |
811 ccf->pid.len = sizeof(NGX_PID_PATH) - 1; | |
812 ccf->pid.data = (u_char *) NGX_PID_PATH; | |
813 } | |
814 | |
815 if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) { | |
816 return NGX_CONF_ERROR; | |
817 } | |
818 | |
819 ccf->oldpid.len = ccf->pid.len + sizeof(NGX_OLDPID_EXT); | |
820 | |
821 ccf->oldpid.data = ngx_pnalloc(cycle->pool, ccf->oldpid.len); | |
822 if (ccf->oldpid.data == NULL) { | |
823 return NGX_CONF_ERROR; | |
824 } | |
825 | |
826 ngx_memcpy(ngx_cpymem(ccf->oldpid.data, ccf->pid.data, ccf->pid.len), | |
827 NGX_OLDPID_EXT, sizeof(NGX_OLDPID_EXT)); | |
828 | |
829 | |
789 #if !(NGX_WIN32) | 830 #if !(NGX_WIN32) |
790 | 831 |
791 if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) { | 832 if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) { |
792 struct group *grp; | 833 struct group *grp; |
793 struct passwd *pwd; | 834 struct passwd *pwd; |
812 } | 853 } |
813 | 854 |
814 ccf->group = grp->gr_gid; | 855 ccf->group = grp->gr_gid; |
815 } | 856 } |
816 | 857 |
817 if (ccf->pid.len == 0) { | |
818 ccf->pid.len = sizeof(NGX_PID_PATH) - 1; | |
819 ccf->pid.data = (u_char *) NGX_PID_PATH; | |
820 } | |
821 | |
822 if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) { | |
823 return NGX_CONF_ERROR; | |
824 } | |
825 | |
826 ccf->oldpid.len = ccf->pid.len + sizeof(NGX_OLDPID_EXT); | |
827 | |
828 ccf->oldpid.data = ngx_pnalloc(cycle->pool, ccf->oldpid.len); | |
829 if (ccf->oldpid.data == NULL) { | |
830 return NGX_CONF_ERROR; | |
831 } | |
832 | |
833 ngx_memcpy(ngx_cpymem(ccf->oldpid.data, ccf->pid.data, ccf->pid.len), | |
834 NGX_OLDPID_EXT, sizeof(NGX_OLDPID_EXT)); | |
835 | |
836 | 858 |
837 if (ccf->lock_file.len == 0) { | 859 if (ccf->lock_file.len == 0) { |
838 ccf->lock_file.len = sizeof(NGX_LOCK_PATH) - 1; | 860 ccf->lock_file.len = sizeof(NGX_LOCK_PATH) - 1; |
839 ccf->lock_file.data = (u_char *) NGX_LOCK_PATH; | 861 ccf->lock_file.data = (u_char *) NGX_LOCK_PATH; |
840 } | 862 } |