]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix to use event_assign with libevent for thread-safety.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 8 Apr 2019 11:02:34 +0000 (11:02 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 8 Apr 2019 11:02:34 +0000 (11:02 +0000)
git-svn-id: file:///svn/unbound/trunk@5149 be551aaa-1e26-0410-a405-d3ace91eadb9

config.h.in
configure
configure.ac
doc/Changelog
util/ub_event.c

index 7c3309683daae00e568b091ece86272d08f09cfc..74c14d16175ea40584e4fd448f72e2aafd7e54dc 100644 (file)
    if you don't. */
 #undef HAVE_DECL_ARC4RANDOM_UNIFORM
 
+/* Define to 1 if you have the declaration of `evsignal_assign', and to 0 if
+   you don't. */
+#undef HAVE_DECL_EVSIGNAL_ASSIGN
+
 /* Define to 1 if you have the declaration of `inet_ntop', and to 0 if you
    don't. */
 #undef HAVE_DECL_INET_NTOP
 /* Define to 1 if you have the `ERR_load_crypto_strings' function. */
 #undef HAVE_ERR_LOAD_CRYPTO_STRINGS
 
+/* Define to 1 if you have the `event_assign' function. */
+#undef HAVE_EVENT_ASSIGN
+
 /* Define to 1 if you have the `event_base_free' function. */
 #undef HAVE_EVENT_BASE_FREE
 
index b4c91f8d55436f89568309e512f30a5b500814e0..777649c666b40fd860d31128222ea2ce810fb1f2 100755 (executable)
--- a/configure
+++ b/configure
@@ -19013,6 +19013,35 @@ _ACEOF
 fi
 done
  # only in libev. (tested on 4.00)
+       for ac_func in event_assign
+do :
+  ac_fn_c_check_func "$LINENO" "event_assign" "ac_cv_func_event_assign"
+if test "x$ac_cv_func_event_assign" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_EVENT_ASSIGN 1
+_ACEOF
+
+fi
+done
+ # in libevent, for thread-safety
+       ac_fn_c_check_decl "$LINENO" "evsignal_assign" "ac_cv_have_decl_evsignal_assign" "$ac_includes_default
+#ifdef HAVE_EVENT_H
+#  include <event.h>
+#else
+#  include \"event2/event.h\"
+#endif
+
+"
+if test "x$ac_cv_have_decl_evsignal_assign" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_EVSIGNAL_ASSIGN $ac_have_decl
+_ACEOF
+
         PC_LIBEVENT_DEPENDENCY="libevent"
 
        if test -n "$BAK_LDFLAGS_SET"; then
index ea1783b70953624af05161e3edb3e94f7ba1ca65..abbecf0bad0b8ef4634cbcd0447f44cb2a5d56b3 100644 (file)
@@ -1200,6 +1200,14 @@ large outgoing port ranges.  ])
        AC_CHECK_FUNCS([event_base_get_method]) # only in libevent 1.4.3 and later
        AC_CHECK_FUNCS([ev_loop]) # only in libev. (tested on 3.51)
        AC_CHECK_FUNCS([ev_default_loop]) # only in libev. (tested on 4.00)
+       AC_CHECK_FUNCS([event_assign]) # in libevent, for thread-safety
+       AC_CHECK_DECLS([evsignal_assign], [], [], [AC_INCLUDES_DEFAULT
+#ifdef HAVE_EVENT_H
+#  include <event.h>
+#else
+#  include "event2/event.h"
+#endif
+       ])
         PC_LIBEVENT_DEPENDENCY="libevent"
         AC_SUBST(PC_LIBEVENT_DEPENDENCY)
        if test -n "$BAK_LDFLAGS_SET"; then
index 110ab826595bb2fc080729f204b61324e30dd241..ae4b31f62479e8886f9d5ac03f9cdf872c798703 100644 (file)
@@ -1,3 +1,6 @@
+8 April 2019: Wouter
+       - Fix to use event_assign with libevent for thread-safety.
+
 5 April 2019: Wouter
        - Fix to reinit event structure for accepted TCP (and TLS) sockets.
 
index 78481a982055b57a73cee8a961a9c920d67a7c5e..e097fbc4015883745ff0a411986bf7f94777490d 100644 (file)
@@ -295,11 +295,18 @@ ub_event_new(struct ub_event_base* base, int fd, short bits,
        if (!ev)
                return NULL;
 
+#ifndef HAVE_EVENT_ASSIGN
        event_set(ev, fd, NATIVE_BITS(bits), NATIVE_BITS_CB(cb), arg);
        if (event_base_set(AS_EVENT_BASE(base), ev) != 0) {
                free(ev);
                return NULL;
        }
+#else
+       if (event_assign(ev, AS_EVENT_BASE(base), fd, bits, cb, arg) != 0) {
+               free(ev);
+               return NULL;
+       }
+#endif
        return AS_UB_EVENT(ev);
 }
 
@@ -312,11 +319,18 @@ ub_signal_new(struct ub_event_base* base, int fd,
        if (!ev)
                return NULL;
 
+#if !HAVE_DECL_EVSIGNAL_ASSIGN
        signal_set(ev, fd, NATIVE_BITS_CB(cb), arg);
        if (event_base_set(AS_EVENT_BASE(base), ev) != 0) {
                free(ev);
                return NULL;
        }
+#else
+       if (evsignal_assign(ev, AS_EVENT_BASE(base), fd, cb, arg) != 0) {
+               free(ev);
+               return NULL;
+       }
+#endif
        return AS_UB_EVENT(ev);
 }