[syslog-ng] [PATCH 3/3] lib/: Clear ivykis handlers before setting them

Gergely Nagy algernon at balabit.hu
Mon May 7 23:42:33 CEST 2012


The iv_fd_set_handler_in()/iv_fd_set_handler_out() functions are
picky, and will abort() if we want to set a handler for an FD that
already has handlers registered. To avoid that, whenever we want to
set a handler, clear the old one first.

This is perhaps not the best approach, as the above two functions were
similarly picky before migrating to upstream's ivykis, yet, they did
not abort() away. So there's probably some other underlying problem
lurking somewhere still, but for the time being, this will do.

At least, syslog-ng compiles AND works properly this way.

Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
 lib/control.c   |   12 ++++--------
 lib/logreader.c |   11 ++++-------
 lib/logwriter.c |    8 ++++++--
 3 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/lib/control.c b/lib/control.c
index 52ec095..715beb4 100644
--- a/lib/control.c
+++ b/lib/control.c
@@ -278,16 +278,12 @@ control_connection_stop_watches(ControlConnection *self)
 static void
 control_connection_update_watches(ControlConnection *self)
 {
+  iv_fd_set_handler_in(&self->control_io, NULL);
+  iv_fd_set_handler_out(&self->control_io, NULL);
   if (self->output_buffer->len > self->pos)
-    {
-      iv_fd_set_handler_out(&self->control_io, control_connection_io_output);
-      iv_fd_set_handler_in(&self->control_io, NULL);
-    }
+    iv_fd_set_handler_out(&self->control_io, control_connection_io_output);
   else
-    {
-      iv_fd_set_handler_out(&self->control_io, NULL);
-      iv_fd_set_handler_in(&self->control_io, control_connection_io_input);
-    }
+    iv_fd_set_handler_in(&self->control_io, control_connection_io_input);
 }
 
 ControlConnection *
diff --git a/lib/logreader.c b/lib/logreader.c
index 5a35e06..889d074 100644
--- a/lib/logreader.c
+++ b/lib/logreader.c
@@ -451,21 +451,18 @@ log_reader_update_watches(LogReader *self)
        * files cannot be polled using epoll, as it causes an I/O error
        * (thus abort in ivykis).
        */
+      iv_fd_set_handler_in(&self->fd_watch, NULL);
+      iv_fd_set_handler_out(&self->fd_watch, NULL);
+      iv_fd_set_handler_err(&self->fd_watch, NULL);
+
       if (cond & G_IO_IN)
         iv_fd_set_handler_in(&self->fd_watch, log_reader_io_process_input);
-      else
-        iv_fd_set_handler_in(&self->fd_watch, NULL);
 
       if (cond & G_IO_OUT)
         iv_fd_set_handler_out(&self->fd_watch, log_reader_io_process_input);
-      else
-        iv_fd_set_handler_out(&self->fd_watch, NULL);
 
       if (cond & (G_IO_IN + G_IO_OUT))
         iv_fd_set_handler_err(&self->fd_watch, log_reader_io_process_input);
-      else
-        iv_fd_set_handler_err(&self->fd_watch, NULL);
-
     }
   else
     {
diff --git a/lib/logwriter.c b/lib/logwriter.c
index 6d0c28f..5d2daa9 100644
--- a/lib/logwriter.c
+++ b/lib/logwriter.c
@@ -251,6 +251,9 @@ log_writer_update_fd_callbacks(LogWriter *self, GIOCondition cond)
   main_loop_assert_main_thread();
   if (self->pollable_state > 0)
     {
+      /* By default, we're not interested in the input, and before
+         setting a handler, we have to clear the old one first too. */
+      iv_fd_set_handler_in(&self->fd_watch, NULL);
       if (self->flags & LW_DETECT_EOF && (cond & G_IO_IN) == 0 && (cond & G_IO_OUT))
         {
           /* if output is enabled, and we're in DETECT_EOF mode, and input is
@@ -272,11 +275,12 @@ log_writer_update_fd_callbacks(LogWriter *self, GIOCondition cond)
           /* otherwise we're not interested in input */
           iv_fd_set_handler_in(&self->fd_watch, NULL);
         }
+
+      iv_fd_set_handler_out(&self->fd_watch, NULL);
       if (cond & G_IO_OUT)
         iv_fd_set_handler_out(&self->fd_watch, log_writer_io_flush_output);
-      else
-        iv_fd_set_handler_out(&self->fd_watch, NULL);
 
+      iv_fd_set_handler_err(&self->fd_watch, NULL);
       iv_fd_set_handler_err(&self->fd_watch, log_writer_io_error);
     }
   else
-- 
1.7.10




More information about the syslog-ng mailing list