From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id F08A726E59 for ; Tue, 7 Aug 2018 16:58:17 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hk_4avf3h5cv for ; Tue, 7 Aug 2018 16:58:17 -0400 (EDT) Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id A319E26D8C for ; Tue, 7 Aug 2018 16:58:17 -0400 (EDT) Received: by mail-lf1-f67.google.com with SMTP id b22-v6so37092lfa.3 for ; Tue, 07 Aug 2018 13:58:17 -0700 (PDT) From: Olga Arkhangelskaia Subject: [tarantool-patches] [PATCH] Fix O_NONBLOCK flag loss Date: Tue, 7 Aug 2018 23:57:42 +0300 Message-Id: <20180807205742.52303-1-krishtal.olja@gmail.com> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Olga Arkhangelskaia During syslog reconnect we lose nonblock flag. This leads to misbehavior while logging. Tarantool hangs forever Closes #3615 --- https://github.com/tarantool/tarantool/issues/3615 https://github.com/tarantool/tarantool/tree/OKriw/gh-3615-loss-nonblock-1.10 src/say.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/say.c b/src/say.c index 063e0295c..4bd47b1f2 100644 --- a/src/say.c +++ b/src/say.c @@ -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 */ @@ -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 */ @@ -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 - -- 2.14.3 (Apple Git-98)