comparison src/core/nginx.c @ 2733:edc01cc34b3e

allow condensed command lines options
author Igor Sysoev <igor@sysoev.ru>
date Tue, 21 Apr 2009 15:42:15 +0000
parents 95a17423afdb
children a9d7f8ebdbef
comparison
equal deleted inserted replaced
2732:e1b3d210587a 2733:edc01cc34b3e
183 183
184 ngx_uint_t ngx_max_module; 184 ngx_uint_t ngx_max_module;
185 185
186 static ngx_uint_t ngx_show_version; 186 static ngx_uint_t ngx_show_version;
187 static ngx_uint_t ngx_show_configure; 187 static ngx_uint_t ngx_show_configure;
188 static char *ngx_conf_file; 188 static u_char *ngx_conf_file;
189 static char *ngx_conf_params; 189 static u_char *ngx_conf_params;
190 #if (NGX_WIN32) 190 #if (NGX_WIN32)
191 static char *ngx_signal; 191 static char *ngx_signal;
192 #endif 192 #endif
193 193
194 194
596 596
597 597
598 static ngx_int_t 598 static ngx_int_t
599 ngx_get_options(int argc, char *const *argv) 599 ngx_get_options(int argc, char *const *argv)
600 { 600 {
601 ngx_int_t i; 601 u_char *p;
602 ngx_int_t i;
602 603
603 for (i = 1; i < argc; i++) { 604 for (i = 1; i < argc; i++) {
604 if (argv[i][0] != '-') { 605
606 p = (u_char *) argv[i];
607
608 if (*p++ != '-') {
605 ngx_log_stderr("invalid option: \"%s\"", argv[i]); 609 ngx_log_stderr("invalid option: \"%s\"", argv[i]);
606 return NGX_ERROR; 610 return NGX_ERROR;
607 } 611 }
608 612
609 switch (argv[i][1]) { 613 while (*p) {
610 614
611 case 'v': 615 switch (*p++) {
612 ngx_show_version = 1; 616
613 break; 617 case 'v':
614 618 ngx_show_version = 1;
615 case 'V':
616 ngx_show_version = 1;
617 ngx_show_configure = 1;
618 break;
619
620 case 't':
621 ngx_test_config = 1;
622 break;
623
624 case 'c':
625 if (argv[++i]) {
626 ngx_conf_file = argv[i];
627 break; 619 break;
628 } 620
629 621 case 'V':
630 ngx_log_stderr("the option \"-c\" requires file name"); 622 ngx_show_version = 1;
631 return NGX_ERROR; 623 ngx_show_configure = 1;
632
633 case 'g':
634 if (argv[++i]) {
635 ngx_conf_params = argv[i];
636 break; 624 break;
637 } 625
638 626 case 't':
639 ngx_log_stderr("the option \"-g\" requires parameter"); 627 ngx_test_config = 1;
640 return NGX_ERROR; 628 break;
629
630 case 'c':
631 if (*p) {
632 ngx_conf_file = p;
633 goto next;
634 }
635
636 if (argv[++i]) {
637 ngx_conf_file = (u_char *) argv[i];
638 goto next;
639 }
640
641 ngx_log_stderr("the option \"-c\" requires file name");
642 return NGX_ERROR;
643
644 case 'g':
645 if (*p) {
646 ngx_conf_params = p;
647 goto next;
648 }
649
650 if (argv[++i]) {
651 ngx_conf_params = (u_char *) argv[i];
652 goto next;
653 }
654
655 ngx_log_stderr("the option \"-g\" requires parameter");
656 return NGX_ERROR;
641 657
642 #if (NGX_WIN32) 658 #if (NGX_WIN32)
643 case 's': 659 case 's':
644 if (argv[++i] == NULL) { 660 if (*p) {
645 ngx_log_stderr("the option \"-s\" requires parameter"); 661 ngx_signal = (char *) p;
662
663 } else if (argv[++i]) {
664 ngx_signal = argv[i];
665
666 } else {
667 ngx_log_stderr("the option \"-s\" requires parameter");
668 return NGX_ERROR;
669 }
670
671 if (ngx_strcmp(ngx_signal, "stop") == 0
672 || ngx_strcmp(ngx_signal, "quit") == 0
673 || ngx_strcmp(ngx_signal, "reopen") == 0
674 || ngx_strcmp(ngx_signal, "reload") == 0)
675 {
676 ngx_process = NGX_PROCESS_SIGNALLER;
677 goto next;
678 }
679
680 ngx_log_stderr("invalid option: \"-s %s\"", ngx_signal);
681 return NGX_ERROR;
682 #endif
683
684 default:
685 ngx_log_stderr("invalid option: \"%c\"", *(p - 1));
646 return NGX_ERROR; 686 return NGX_ERROR;
647 } 687 }
648 688 }
649 if (ngx_strcmp(argv[i], "stop") == 0 689
650 || ngx_strcmp(argv[i], "quit") == 0 690 next:
651 || ngx_strcmp(argv[i], "reopen") == 0 691
652 || ngx_strcmp(argv[i], "reload") == 0) 692 continue;
653 {
654 ngx_process = NGX_PROCESS_SIGNALLER;
655 ngx_signal = argv[i];
656 break;
657 }
658
659 ngx_log_stderr("invalid option: \"-s %s\"", argv[i]);
660 return NGX_ERROR;
661 #endif
662
663 default:
664 ngx_log_stderr("invalid option: \"%s\"", argv[i]);
665 return NGX_ERROR;
666 }
667 } 693 }
668 694
669 return NGX_OK; 695 return NGX_OK;
670 } 696 }
671 697
715 static void 741 static void
716 ngx_process_options(ngx_cycle_t *cycle) 742 ngx_process_options(ngx_cycle_t *cycle)
717 { 743 {
718 if (ngx_conf_file) { 744 if (ngx_conf_file) {
719 cycle->conf_file.len = ngx_strlen(ngx_conf_file); 745 cycle->conf_file.len = ngx_strlen(ngx_conf_file);
720 cycle->conf_file.data = (u_char *) ngx_conf_file; 746 cycle->conf_file.data = ngx_conf_file;
721 747
722 } else { 748 } else {
723 cycle->conf_file.len = sizeof(NGX_CONF_PATH) - 1; 749 cycle->conf_file.len = sizeof(NGX_CONF_PATH) - 1;
724 cycle->conf_file.data = (u_char *) NGX_CONF_PATH; 750 cycle->conf_file.data = (u_char *) NGX_CONF_PATH;
725 } 751 }
726 752
727 if (ngx_conf_params) { 753 if (ngx_conf_params) {
728 cycle->conf_param.data = (u_char *) ngx_conf_params;
729 cycle->conf_param.len = ngx_strlen(ngx_conf_params); 754 cycle->conf_param.len = ngx_strlen(ngx_conf_params);
755 cycle->conf_param.data = ngx_conf_params;
730 } 756 }
731 757
732 if (ngx_test_config) { 758 if (ngx_test_config) {
733 cycle->log->log_level = NGX_LOG_INFO; 759 cycle->log->log_level = NGX_LOG_INFO;
734 } 760 }