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 hang forever

Closes #3615
  • Loading branch information
OKriw committed Aug 7, 2018
1 parent e39b4c1 commit 868f50d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/say.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ write_to_file(struct log *log, int total);
static void
write_to_syslog(struct log *log, int total);

static void
set_nonblock(int fd)
{
int flags;
if ( (flags = fcntl(fd, F_GETFL, 0)) < 0 ||
fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
say_syserror("fcntl, fd=%i", fd);
}
}

/**
* Rotate logs on SIGHUP
*/
Expand All @@ -262,13 +272,9 @@ 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);
}
}
if (log->nonblock)
set_nonblock(log->fd);

/* We are in ev signal handler
* so we don't have to be worry about async signal safety
*/
Expand Down Expand Up @@ -940,6 +946,8 @@ write_to_syslog(struct log *log, int total)
close(log->fd);
log->fd = log_syslog_connect(log);
if (log->fd >= 0) {
if (log->nonblock)
set_nonblock(log->fd);
/*
* In a case or error the log message is
* lost. We can not wait for connection -
Expand Down

0 comments on commit 868f50d

Please sign in to comment.