Skip to content

Commit

Permalink
syslog: fixed segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
chobits committed Nov 28, 2016
1 parent bf4a809 commit 06370cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
17 changes: 10 additions & 7 deletions src/core/ngx_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ ngx_log_stderr(ngx_err_t err, const char *fmt, ...)

last = errstr + NGX_MAX_ERROR_STR;

p = ngx_cpymem(errstr, "nginx: ", 7);

va_start(args, fmt);
p = ngx_vslprintf(errstr, last, fmt, args);
p = ngx_vslprintf(p, last, fmt, args);
va_end(args);

if (err) {
Expand Down Expand Up @@ -402,7 +404,7 @@ ngx_int_t
ngx_log_open_default(ngx_cycle_t *cycle)
{
ngx_log_t *log;
static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH);
static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH);

if (ngx_log_get_file_log(&cycle->new_log) != NULL) {
return NGX_OK;
Expand Down Expand Up @@ -445,7 +447,8 @@ ngx_log_redirect_stderr(ngx_cycle_t *cycle)
return NGX_OK;
}

fd = cycle->log->file->fd;
/* file log always exists when we are called */
fd = ngx_log_get_file_log(cycle->log)->file->fd;

if (fd != ngx_stderr) {
if (ngx_set_stderr(fd) == NGX_FILE_ERROR) {
Expand Down Expand Up @@ -481,13 +484,13 @@ ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
ngx_uint_t i, n, d, found;
ngx_str_t *value;

value = cf->args->elts;

if (cf->args->nelts == 2) {
log->log_level = NGX_LOG_ERR;
return NGX_CONF_OK;
}

value = cf->args->elts;

for (i = 2; i < cf->args->nelts; i++) {
found = 0;

Expand Down Expand Up @@ -552,8 +555,8 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
char *
ngx_log_set_log(ngx_conf_t *cf, ngx_log_t **head)
{
ngx_log_t *new_log;
ngx_str_t *value, name;
ngx_log_t *new_log;
ngx_str_t *value, name;
ngx_syslog_peer_t *peer;

if (*head != NULL && (*head)->log_level == 0) {
Expand Down
2 changes: 0 additions & 2 deletions src/core/ngx_times.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ ngx_time_update(void)
months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday,
tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec);



ngx_memory_barrier();

ngx_cached_tm = &cached_http_log_tm[slot];
Expand Down
9 changes: 5 additions & 4 deletions src/os/unix/ngx_process_cycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ static ngx_cache_manager_ctx_t ngx_cache_loader_ctx = {
};


static ngx_cycle_t ngx_exit_cycle;
static ngx_log_t ngx_exit_log;
static ngx_open_file_t ngx_exit_log_file;
static ngx_cycle_t ngx_exit_cycle;
static ngx_log_t ngx_exit_log;
static ngx_open_file_t ngx_exit_log_file;


void
ngx_master_process_cycle(ngx_cycle_t *cycle)
Expand Down Expand Up @@ -1071,7 +1072,7 @@ ngx_worker_process_exit(ngx_cycle_t *cycle)

ngx_exit_log = *ngx_log_get_file_log(ngx_cycle->log);

ngx_exit_log_file.fd = ngx_cycle->log->file->fd;
ngx_exit_log_file.fd = ngx_exit_log.file->fd;
ngx_exit_log.file = &ngx_exit_log_file;
ngx_exit_log.next = NULL;
ngx_exit_log.writer = NULL;
Expand Down

0 comments on commit 06370cd

Please sign in to comment.