Skip to content

Commit

Permalink
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 committed Aug 12, 2018
1 parent 444355d commit 5700d30
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/say.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,23 @@ 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
set_nonblock(struct log *log)
{
if (!log->nonblock)
return;
else {
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 +279,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);
}
}
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 +579,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);
}
set_nonblock(log);
} else {
log->type = SAY_LOGGER_STDERR;
log->fd = STDERR_FILENO;
Expand Down Expand Up @@ -940,6 +947,7 @@ write_to_syslog(struct log *log, int total)
close(log->fd);
log->fd = log_syslog_connect(log);
if (log->fd >= 0) {
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 5700d30

Please sign in to comment.