Skip to content

Commit

Permalink
say: fix O_NONBLOCK flag loss
Browse files Browse the repository at this point in the history
During syslog reconnect we lose nonblock flag. This leads to misbehavior
while logging. Tarantool hangs forever.

Closes #3615
  • Loading branch information
OKriw authored and locker committed Aug 13, 2018
1 parent 444355d commit 878ff7f
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/say.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ write_to_file(struct log *log, int total);
static void
write_to_syslog(struct log *log, int total);

/**
* Sets O_NONBLOCK flag in case if lognonblock is set.
*/
static void
log_set_nonblock(struct log *log)
{
if (!log->nonblock)
return;
int flags;
if ((flags = fcntl(log->fd, F_GETFL, 0)) < 0 ||
fcntl(log->fd, F_SETFL, flags | O_NONBLOCK) < 0) {
say_syserror("fcntl, fd=%i", log->fd);
}
}

/**
* Rotate logs on SIGHUP
*/
Expand All @@ -262,13 +277,8 @@ log_rotate(struct log *log)
dup2(fd, log->fd);
close(fd);

if (log->nonblock) {
int flags;
if ( (flags = fcntl(log->fd, F_GETFL, 0)) < 0 ||
fcntl(log->fd, F_SETFL, flags | O_NONBLOCK) < 0) {
say_syserror("fcntl, fd=%i", log->fd);
}
}
log_set_nonblock(log);

/* We are in ev signal handler
* so we don't have to be worry about async signal safety
*/
Expand Down Expand Up @@ -567,12 +577,7 @@ log_create(struct log *log, const char *init_str, bool nonblock)
* non-blocking: this will garble interactive
* console output.
*/
if (log->nonblock) {
int flags;
if ( (flags = fcntl(log->fd, F_GETFL, 0)) < 0 ||
fcntl(log->fd, F_SETFL, flags | O_NONBLOCK) < 0)
say_syserror("fcntl, fd=%i", log->fd);
}
log_set_nonblock(log);
} else {
log->type = SAY_LOGGER_STDERR;
log->fd = STDERR_FILENO;
Expand Down Expand Up @@ -940,6 +945,7 @@ write_to_syslog(struct log *log, int total)
close(log->fd);
log->fd = log_syslog_connect(log);
if (log->fd >= 0) {
log_set_nonblock(log);
/*
* In a case or error the log message is
* lost. We can not wait for connection -
Expand Down

0 comments on commit 878ff7f

Please sign in to comment.