iv_signal: Fix some unregistration corner cases.

This commit fixes two corner cases related to iv_signal
unregistration:

* When unregistering an active exclusive iv_signal, we would
  only ever wake up one more reader, even if that reader is a
  nonexclusive one and there are more readers on the list.

* When unregistering an active exclusive iv_signal while there
  are other iv_signals registered for this signal number as well,
  we would wake up the next reader but fail to mark it active,
  so that if that next reader would also be unregistered before
  its handler would have had a chance to run, we would lose the
  signal altogether.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_thread: Remove local definitions of __NR_gettid.

Rely on sys/syscall.h instead.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Remove the last traces of ivykis.spec.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
contrib/kojines: Only build if <linux/netfilter_ipv4.h> is present.

Since it relies on the netfilter-provided SO_ORIGINAL_DST sockopt.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Build contrib/ by default.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
contrib/iv_getaddrinfo: Define _GNU_SOURCE in Makefile.am.

Instead of at the top of test.c.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_work: Shutdown race condition fix.

When shutting down a worker thread in response to the thread pool
having been put, execute the ->thread_stop() callback before the
private pool data is free()d.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_getaddrinfo: Make pending requests cancelable.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Build all included test and contrib applications against libivykis.so.

Instead of against the static versions of the libraries.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
pthread API functions return positive values on error.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_tls: Some iv_tls_user_ptr() semantics changes.

* In non-ivykis threads, make iv_tls_user_ptr() return NULL
  instead of causing a NULL pointer dereference.

* In ivykis threads, make iv_tls_user_ptr() return NULL before
  the thread's per-thread local storage area has been allocated
  (which happens during iv_init()) or after the area has been
  deallocated (which happens during iv_deinit()), but return
  pointers into the thread local storage area in between.

  This means that iv_tls_user_ptr() can return non-NULL values
  before the iv_tls_user's ->init_thread() function has been
  called or after its ->destroy_thread() function has been called,
  which iv_tls users should keep in mind if they intend to call
  iv_tls_user_ptr() from signal handler context.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Bump version number to 0.27.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_thread: Create threads joinable, and wait for them on exit.

This allows the creating thread to track the lifetimes of created
pthread_t handles, which:

- is necessary if we ever want to provide iv_thread_kill(),
  as pthread_kill() on a pthread_t for which the corresponding
  (detached) thread has already exited is undefined; and

- has the nice side effect of shutting up valgrind about memory
  leaks on exit if we terminate the process after a thread has
  signaled its creator of its demise but before it has had a
  chance to run its other (thread library level) cleanup code.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
configure.ac: Invoke AC_PROG_LIBTOOL.

To keep older autotools versions happy.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
configure.ac: Link test against pthread_atfork() instead of pthread_create().

On some platforms (e.g. CentOS 5), linking against -lrt makes
available for linking some pthreads symbols (e.g. pthread_create)
but not others (e.g. pthread_atfork).  Do the link test against
pthread_atfork() instead of pthread_create() for that reason.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_timer: Allow for iv_init() after iv_deinit().

By setting st->timer_root to NULL after freeing the timer radix
tree in iv_timer_deinit().

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Only build iv_method_select if we don't have any other poll methods.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Only include state for built-in poll methods into struct iv_state.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Trim the size of struct iv_fd_.

..by only including the fields we need for the poll methods we
build with.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_signal: Get rid of maximum signal number limitation.

By converting the set of signal interests to an AVL tree.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>