comparison src/core/nginx.c @ 2758:77264e0157ad

-p and --prefix=
author Igor Sysoev <igor@sysoev.ru>
date Mon, 27 Apr 2009 11:32:33 +0000
parents a65976a205a5
children caa4f7dcf1e3
comparison
equal deleted inserted replaced
2757:9cc973b46af1 2758:77264e0157ad
9 #include <nginx.h> 9 #include <nginx.h>
10 10
11 11
12 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle); 12 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
13 static ngx_int_t ngx_get_options(int argc, char *const *argv); 13 static ngx_int_t ngx_get_options(int argc, char *const *argv);
14 static void ngx_process_options(ngx_cycle_t *cycle); 14 static ngx_int_t ngx_process_options(ngx_cycle_t *cycle);
15 static ngx_int_t ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv); 15 static ngx_int_t ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv);
16 static void *ngx_core_module_create_conf(ngx_cycle_t *cycle); 16 static void *ngx_core_module_create_conf(ngx_cycle_t *cycle);
17 static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf); 17 static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf);
18 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 18 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
19 static char *ngx_set_env(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 19 static char *ngx_set_env(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
184 ngx_uint_t ngx_max_module; 184 ngx_uint_t ngx_max_module;
185 185
186 static ngx_uint_t ngx_show_help; 186 static ngx_uint_t ngx_show_help;
187 static ngx_uint_t ngx_show_version; 187 static ngx_uint_t ngx_show_version;
188 static ngx_uint_t ngx_show_configure; 188 static ngx_uint_t ngx_show_configure;
189 static u_char *ngx_prefix;
189 static u_char *ngx_conf_file; 190 static u_char *ngx_conf_file;
190 static u_char *ngx_conf_params; 191 static u_char *ngx_conf_params;
191 static char *ngx_signal; 192 static char *ngx_signal;
192 193
193 194
219 " -V : show version and configure options then exit" 220 " -V : show version and configure options then exit"
220 CRLF 221 CRLF
221 " -t : test configuration and exit" CRLF 222 " -t : test configuration and exit" CRLF
222 " -s signal : send signal to a master process: " 223 " -s signal : send signal to a master process: "
223 "stop, quit, reopen, reload" CRLF 224 "stop, quit, reopen, reload" CRLF
225 #ifdef NGX_PREFIX
226 " -p prefix : set prefix path (default: "
227 NGX_PREFIX ")" CRLF
228 #else
229 " -p prefix : set prefix path (default: NONE)" CRLF
230 #endif
224 " -c filename : set configuration file (default: " 231 " -c filename : set configuration file (default: "
225 NGX_CONF_PATH ")" CRLF 232 NGX_CONF_PATH ")" CRLF
226 " -g directives : set global directives out of configuration " 233 " -g directives : set global directives out of configuration "
227 "file" CRLF 234 "file" CRLF
228 ); 235 );
252 ngx_regex_init(); 259 ngx_regex_init();
253 #endif 260 #endif
254 261
255 ngx_pid = ngx_getpid(); 262 ngx_pid = ngx_getpid();
256 263
257 log = ngx_log_init(); 264 log = ngx_log_init(ngx_prefix);
258 if (log == NULL) { 265 if (log == NULL) {
259 return 1; 266 return 1;
260 } 267 }
261 268
262 /* STUB */ 269 /* STUB */
280 287
281 if (ngx_save_argv(&init_cycle, argc, argv) != NGX_OK) { 288 if (ngx_save_argv(&init_cycle, argc, argv) != NGX_OK) {
282 return 1; 289 return 1;
283 } 290 }
284 291
285 ngx_process_options(&init_cycle); 292 if (ngx_process_options(&init_cycle) != NGX_OK) {
293 return 1;
294 }
286 295
287 if (ngx_os_init(log) != NGX_OK) { 296 if (ngx_os_init(log) != NGX_OK) {
288 return 1; 297 return 1;
289 } 298 }
290 299
660 669
661 case 't': 670 case 't':
662 ngx_test_config = 1; 671 ngx_test_config = 1;
663 break; 672 break;
664 673
674 case 'p':
675 if (*p) {
676 ngx_prefix = p;
677 goto next;
678 }
679
680 if (argv[++i]) {
681 ngx_prefix = (u_char *) argv[i];
682 goto next;
683 }
684
685 ngx_log_stderr(0, "option \"-p\" requires directory name");
686 return NGX_ERROR;
687
665 case 'c': 688 case 'c':
666 if (*p) { 689 if (*p) {
667 ngx_conf_file = p; 690 ngx_conf_file = p;
668 goto next; 691 goto next;
669 } 692 }
769 792
770 return NGX_OK; 793 return NGX_OK;
771 } 794 }
772 795
773 796
774 static void 797 static ngx_int_t
775 ngx_process_options(ngx_cycle_t *cycle) 798 ngx_process_options(ngx_cycle_t *cycle)
776 { 799 {
800 u_char *p;
801 size_t len;
802
803 if (ngx_prefix) {
804 len = ngx_strlen(ngx_prefix);
805 p = ngx_prefix;
806
807 if (!ngx_path_separator(*p)) {
808 p = ngx_pnalloc(cycle->pool, len + 1);
809 if (p == NULL) {
810 return NGX_ERROR;
811 }
812
813 ngx_memcpy(p, ngx_prefix, len);
814 p[len++] = '/';
815 }
816
817 cycle->conf_prefix.len = len;
818 cycle->conf_prefix.data = p;
819 cycle->prefix.len = len;
820 cycle->prefix.data = p;
821
822 } else {
823
824 #ifndef NGX_PREFIX
825
826 p = ngx_pnalloc(cycle->pool, NGX_MAX_PATH);
827 if (p == NULL) {
828 return NGX_ERROR;
829 }
830
831 if (ngx_getcwd(p, NGX_MAX_PATH) == 0) {
832 ngx_log_stderr(ngx_errno, "[emerg]: " ngx_getcwd_n " failed");
833 return NGX_ERROR;
834 }
835
836 len = ngx_strlen(p);
837
838 p[len++] = '/';
839
840 cycle->conf_prefix.len = len;
841 cycle->conf_prefix.data = p;
842 cycle->prefix.len = len;
843 cycle->prefix.data = p;
844
845 #else
846
847 #ifdef NGX_CONF_PREFIX
848 cycle->conf_prefix.len = sizeof(NGX_CONF_PREFIX) - 1;
849 cycle->conf_prefix.data = (u_char *) NGX_CONF_PREFIX;
850 #else
851 cycle->conf_prefix.len = sizeof(NGX_PREFIX) - 1;
852 cycle->conf_prefix.data = (u_char *) NGX_PREFIX;
853 #endif
854 cycle->prefix.len = sizeof(NGX_PREFIX) - 1;
855 cycle->prefix.data = (u_char *) NGX_PREFIX;
856
857 #endif
858 }
859
777 if (ngx_conf_file) { 860 if (ngx_conf_file) {
778 cycle->conf_file.len = ngx_strlen(ngx_conf_file); 861 cycle->conf_file.len = ngx_strlen(ngx_conf_file);
779 cycle->conf_file.data = ngx_conf_file; 862 cycle->conf_file.data = ngx_conf_file;
780 863
781 } else { 864 } else {
782 cycle->conf_file.len = sizeof(NGX_CONF_PATH) - 1; 865 cycle->conf_file.len = sizeof(NGX_CONF_PATH) - 1;
783 cycle->conf_file.data = (u_char *) NGX_CONF_PATH; 866 cycle->conf_file.data = (u_char *) NGX_CONF_PATH;
784 } 867 }
785 868
869 if (ngx_conf_full_name(cycle, &cycle->conf_file, 0) != NGX_OK) {
870 return NGX_ERROR;
871 }
872
873 for (p = cycle->conf_file.data + cycle->conf_file.len - 1;
874 p > cycle->conf_file.data;
875 p--)
876 {
877 if (ngx_path_separator(*p)) {
878 cycle->conf_prefix.len = p - ngx_cycle->conf_file.data + 1;
879 cycle->conf_prefix.data = ngx_cycle->conf_file.data;
880 break;
881 }
882 }
883
786 if (ngx_conf_params) { 884 if (ngx_conf_params) {
787 cycle->conf_param.len = ngx_strlen(ngx_conf_params); 885 cycle->conf_param.len = ngx_strlen(ngx_conf_params);
788 cycle->conf_param.data = ngx_conf_params; 886 cycle->conf_param.data = ngx_conf_params;
789 } 887 }
790 888
791 if (ngx_test_config) { 889 if (ngx_test_config) {
792 cycle->log->log_level = NGX_LOG_INFO; 890 cycle->log->log_level = NGX_LOG_INFO;
793 } 891 }
892
893 return NGX_OK;
794 } 894 }
795 895
796 896
797 static void * 897 static void *
798 ngx_core_module_create_conf(ngx_cycle_t *cycle) 898 ngx_core_module_create_conf(ngx_cycle_t *cycle)