* [tarantool-patches] [PATCH v2] Fix O_NONBLOCK flag loss
@ 2018-08-13 6:37 Olga Arkhangelskaia
2018-08-13 10:13 ` Vladimir Davydov
0 siblings, 1 reply; 2+ messages in thread
From: Olga Arkhangelskaia @ 2018-08-13 6:37 UTC (permalink / raw)
To: tarantool-patches; +Cc: Olga Arkhangelskaia
During syslog reconnect we lose nonblock flag. This leads to misbehavior
while logging. Tarantool hangs forever. Test for this fix will be available
in 1.10.
Closes #3615
---
https://github.com/tarantool/tarantool/issues/3615
https://github.com/tarantool/tarantool/tree/OKriw/gh-3615-loss-nonblock-1.9
v1:
https://www.freelists.org/post/tarantool-patches/PATCH-Fix-O-NONBLOCK-flag-loss
Changes in v2:
-rebased on 1.9
-changed set_nonblock arg
-set flag in one more place
src/say.c | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/src/say.c b/src/say.c
index 063e0295c..9c1066efc 100644
--- a/src/say.c
+++ b/src/say.c
@@ -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
*/
@@ -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
*/
@@ -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;
@@ -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 -
--
2.14.3 (Apple Git-98)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [tarantool-patches] [PATCH v2] Fix O_NONBLOCK flag loss
2018-08-13 6:37 [tarantool-patches] [PATCH v2] Fix O_NONBLOCK flag loss Olga Arkhangelskaia
@ 2018-08-13 10:13 ` Vladimir Davydov
0 siblings, 0 replies; 2+ messages in thread
From: Vladimir Davydov @ 2018-08-13 10:13 UTC (permalink / raw)
To: Olga Arkhangelskaia; +Cc: tarantool-patches
Please prefix the subject line with a subsystem name ("say: " in your
case).
On Mon, Aug 13, 2018 at 09:37:58AM +0300, Olga Arkhangelskaia wrote:
> During syslog reconnect we lose nonblock flag. This leads to misbehavior
> while logging. Tarantool hangs forever.
> Test for this fix will be available in 1.10.
Please explain why (in the commit message).
>
> Closes #3615
> ---
> https://github.com/tarantool/tarantool/issues/3615
> https://github.com/tarantool/tarantool/tree/OKriw/gh-3615-loss-nonblock-1.9
>
> v1:
> https://www.freelists.org/post/tarantool-patches/PATCH-Fix-O-NONBLOCK-flag-loss
>
> Changes in v2:
> -rebased on 1.9
> -changed set_nonblock arg
> -set flag in one more place
>
> src/say.c | 34 +++++++++++++++++++++-------------
> 1 file changed, 21 insertions(+), 13 deletions(-)
>
> diff --git a/src/say.c b/src/say.c
> index 063e0295c..9c1066efc 100644
> --- a/src/say.c
> +++ b/src/say.c
> @@ -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)
Please prefix this function with 'log_' (log_set_nonblock), because this
function is a method of 'log' object.
> +{
> + if (!log->nonblock)
> + return;
> + else {
'else' is pointless.
> + int flags;
> + if ((flags = fcntl(log->fd, F_GETFL, 0)) < 0 ||
> + fcntl(log->fd, F_SETFL, flags | O_NONBLOCK) < 0) {
Malformed indentation. Please align the next line to 'if (', as we do
everywhere else.
> + say_syserror("fcntl, fd=%i", log->fd);
> + }
> + }
> +}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-08-13 10:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-13 6:37 [tarantool-patches] [PATCH v2] Fix O_NONBLOCK flag loss Olga Arkhangelskaia
2018-08-13 10:13 ` Vladimir Davydov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox