Mercurial > hg > nginx
comparison src/core/ngx_log.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 | 4b420f9c4c5d |
children |
comparison
equal
deleted
inserted
replaced
7743:4b1299b1856a | 7744:f18db38a9826 |
---|---|
313 return buf; | 313 return buf; |
314 } | 314 } |
315 | 315 |
316 | 316 |
317 ngx_log_t * | 317 ngx_log_t * |
318 ngx_log_init(u_char *prefix) | 318 ngx_log_init(u_char *prefix, u_char *error_log) |
319 { | 319 { |
320 u_char *p, *name; | 320 u_char *p, *name; |
321 size_t nlen, plen; | 321 size_t nlen, plen; |
322 | 322 |
323 ngx_log.file = &ngx_log_file; | 323 ngx_log.file = &ngx_log_file; |
324 ngx_log.log_level = NGX_LOG_NOTICE; | 324 ngx_log.log_level = NGX_LOG_NOTICE; |
325 | 325 |
326 name = (u_char *) NGX_ERROR_LOG_PATH; | 326 if (error_log == NULL) { |
327 | 327 error_log = (u_char *) NGX_ERROR_LOG_PATH; |
328 /* | 328 } |
329 * we use ngx_strlen() here since BCC warns about | 329 |
330 * condition is always false and unreachable code | 330 name = error_log; |
331 */ | |
332 | |
333 nlen = ngx_strlen(name); | 331 nlen = ngx_strlen(name); |
334 | 332 |
335 if (nlen == 0) { | 333 if (nlen == 0) { |
336 ngx_log_file.fd = ngx_stderr; | 334 ngx_log_file.fd = ngx_stderr; |
337 return &ngx_log; | 335 return &ngx_log; |
367 | 365 |
368 if (!ngx_path_separator(*(p - 1))) { | 366 if (!ngx_path_separator(*(p - 1))) { |
369 *p++ = '/'; | 367 *p++ = '/'; |
370 } | 368 } |
371 | 369 |
372 ngx_cpystrn(p, (u_char *) NGX_ERROR_LOG_PATH, nlen + 1); | 370 ngx_cpystrn(p, error_log, nlen + 1); |
373 | 371 |
374 p = name; | 372 p = name; |
375 } | 373 } |
376 } | 374 } |
377 | 375 |
401 | 399 |
402 | 400 |
403 ngx_int_t | 401 ngx_int_t |
404 ngx_log_open_default(ngx_cycle_t *cycle) | 402 ngx_log_open_default(ngx_cycle_t *cycle) |
405 { | 403 { |
406 ngx_log_t *log; | 404 ngx_log_t *log; |
407 static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH); | |
408 | 405 |
409 if (ngx_log_get_file_log(&cycle->new_log) != NULL) { | 406 if (ngx_log_get_file_log(&cycle->new_log) != NULL) { |
410 return NGX_OK; | 407 return NGX_OK; |
411 } | 408 } |
412 | 409 |
423 log = &cycle->new_log; | 420 log = &cycle->new_log; |
424 } | 421 } |
425 | 422 |
426 log->log_level = NGX_LOG_ERR; | 423 log->log_level = NGX_LOG_ERR; |
427 | 424 |
428 log->file = ngx_conf_open_file(cycle, &error_log); | 425 log->file = ngx_conf_open_file(cycle, &cycle->error_log); |
429 if (log->file == NULL) { | 426 if (log->file == NULL) { |
430 return NGX_ERROR; | 427 return NGX_ERROR; |
431 } | 428 } |
432 | 429 |
433 if (log != &cycle->new_log) { | 430 if (log != &cycle->new_log) { |