comparison src/core/nginx.c @ 7744:f18db38a9826

Core: "-e" command line option. When installing or running from a non-root user it is sometimes required to override default, compiled in error log path. There was no way to do this without rebuilding the binary (ticket #147). This patch introduced "-e" command line option which allows one to override compiled in error log path.
author Igor Ippolitov <iippolitov@nginx.com>
date Thu, 19 Nov 2020 16:59:00 +0000
parents 9c038f5e0464
children 7df607cb2d11
comparison
equal deleted inserted replaced
7743:4b1299b1856a 7744:f18db38a9826
181 181
182 static ngx_uint_t ngx_show_help; 182 static ngx_uint_t ngx_show_help;
183 static ngx_uint_t ngx_show_version; 183 static ngx_uint_t ngx_show_version;
184 static ngx_uint_t ngx_show_configure; 184 static ngx_uint_t ngx_show_configure;
185 static u_char *ngx_prefix; 185 static u_char *ngx_prefix;
186 static u_char *ngx_error_log;
186 static u_char *ngx_conf_file; 187 static u_char *ngx_conf_file;
187 static u_char *ngx_conf_params; 188 static u_char *ngx_conf_params;
188 static char *ngx_signal; 189 static char *ngx_signal;
189 190
190 191
228 #endif 229 #endif
229 230
230 ngx_pid = ngx_getpid(); 231 ngx_pid = ngx_getpid();
231 ngx_parent = ngx_getppid(); 232 ngx_parent = ngx_getppid();
232 233
233 log = ngx_log_init(ngx_prefix); 234 log = ngx_log_init(ngx_prefix, ngx_error_log);
234 if (log == NULL) { 235 if (log == NULL) {
235 return 1; 236 return 1;
236 } 237 }
237 238
238 /* STUB */ 239 /* STUB */
391 { 392 {
392 ngx_write_stderr("nginx version: " NGINX_VER_BUILD NGX_LINEFEED); 393 ngx_write_stderr("nginx version: " NGINX_VER_BUILD NGX_LINEFEED);
393 394
394 if (ngx_show_help) { 395 if (ngx_show_help) {
395 ngx_write_stderr( 396 ngx_write_stderr(
396 "Usage: nginx [-?hvVtTq] [-s signal] [-c filename] " 397 "Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]" NGX_LINEFEED
397 "[-p prefix] [-g directives]" NGX_LINEFEED 398 " [-e filename] [-c filename] [-g directives]"
398 NGX_LINEFEED 399 NGX_LINEFEED NGX_LINEFEED
399 "Options:" NGX_LINEFEED 400 "Options:" NGX_LINEFEED
400 " -?,-h : this help" NGX_LINEFEED 401 " -?,-h : this help" NGX_LINEFEED
401 " -v : show version and exit" NGX_LINEFEED 402 " -v : show version and exit" NGX_LINEFEED
402 " -V : show version and configure options then exit" 403 " -V : show version and configure options then exit"
403 NGX_LINEFEED 404 NGX_LINEFEED
412 " -p prefix : set prefix path (default: " NGX_PREFIX ")" 413 " -p prefix : set prefix path (default: " NGX_PREFIX ")"
413 NGX_LINEFEED 414 NGX_LINEFEED
414 #else 415 #else
415 " -p prefix : set prefix path (default: NONE)" NGX_LINEFEED 416 " -p prefix : set prefix path (default: NONE)" NGX_LINEFEED
416 #endif 417 #endif
418 " -e filename : set error log file (default: "
419 #ifdef NGX_ERROR_LOG_STDERR
420 "stderr)" NGX_LINEFEED
421 #else
422 NGX_ERROR_LOG_PATH ")" NGX_LINEFEED
423 #endif
417 " -c filename : set configuration file (default: " NGX_CONF_PATH 424 " -c filename : set configuration file (default: " NGX_CONF_PATH
418 ")" NGX_LINEFEED 425 ")" NGX_LINEFEED
419 " -g directives : set global directives out of configuration " 426 " -g directives : set global directives out of configuration "
420 "file" NGX_LINEFEED NGX_LINEFEED 427 "file" NGX_LINEFEED NGX_LINEFEED
421 ); 428 );
798 } 805 }
799 806
800 ngx_log_stderr(0, "option \"-p\" requires directory name"); 807 ngx_log_stderr(0, "option \"-p\" requires directory name");
801 return NGX_ERROR; 808 return NGX_ERROR;
802 809
810 case 'e':
811 if (*p) {
812 ngx_error_log = p;
813
814 } else if (argv[++i]) {
815 ngx_error_log = (u_char *) argv[i];
816
817 } else {
818 ngx_log_stderr(0, "option \"-e\" requires file name");
819 return NGX_ERROR;
820 }
821
822 if (ngx_strcmp(ngx_error_log, "stderr") == 0) {
823 ngx_error_log = (u_char *) "";
824 }
825
826 goto next;
827
803 case 'c': 828 case 'c':
804 if (*p) { 829 if (*p) {
805 ngx_conf_file = p; 830 ngx_conf_file = p;
806 goto next; 831 goto next;
807 } 832 }
988 if (ngx_path_separator(*p)) { 1013 if (ngx_path_separator(*p)) {
989 cycle->conf_prefix.len = p - cycle->conf_file.data + 1; 1014 cycle->conf_prefix.len = p - cycle->conf_file.data + 1;
990 cycle->conf_prefix.data = cycle->conf_file.data; 1015 cycle->conf_prefix.data = cycle->conf_file.data;
991 break; 1016 break;
992 } 1017 }
1018 }
1019
1020 if (ngx_error_log) {
1021 cycle->error_log.len = ngx_strlen(ngx_error_log);
1022 cycle->error_log.data = ngx_error_log;
1023
1024 } else {
1025 ngx_str_set(&cycle->error_log, NGX_ERROR_LOG_PATH);
993 } 1026 }
994 1027
995 if (ngx_conf_params) { 1028 if (ngx_conf_params) {
996 cycle->conf_param.len = ngx_strlen(ngx_conf_params); 1029 cycle->conf_param.len = ngx_strlen(ngx_conf_params);
997 cycle->conf_param.data = ngx_conf_params; 1030 cycle->conf_param.data = ngx_conf_params;