Blame m4/ax_have_epoll.m4

Packit 875988
# ===========================================================================
Packit 875988
#      https://www.gnu.org/software/autoconf-archive/ax_have_epoll.html
Packit 875988
# ===========================================================================
Packit 875988
#
Packit 875988
# SYNOPSIS
Packit 875988
#
Packit 875988
#   AX_HAVE_EPOLL([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
Packit 875988
#   AX_HAVE_EPOLL_PWAIT([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
Packit 875988
#
Packit 875988
# DESCRIPTION
Packit 875988
#
Packit 875988
#   This macro determines whether the system supports the epoll I/O event
Packit 875988
#   interface. A neat usage example would be:
Packit 875988
#
Packit 875988
#     AX_HAVE_EPOLL(
Packit 875988
#       [AX_CONFIG_FEATURE_ENABLE(epoll)],
Packit 875988
#       [AX_CONFIG_FEATURE_DISABLE(epoll)])
Packit 875988
#     AX_CONFIG_FEATURE(
Packit 875988
#       [epoll], [This platform supports epoll(7)],
Packit 875988
#       [HAVE_EPOLL], [This platform supports epoll(7).])
Packit 875988
#
Packit 875988
#   The epoll interface was added to the Linux kernel in version 2.5.45, and
Packit 875988
#   the macro verifies that a kernel newer than this is installed. This
Packit 875988
#   check is somewhat unreliable if <linux/version.h> doesn't match the
Packit 875988
#   running kernel, but it is necessary regardless, because glibc comes with
Packit 875988
#   stubs for the epoll_create(), epoll_wait(), etc. that allow programs to
Packit 875988
#   compile and link even if the kernel is too old; the problem would then
Packit 875988
#   be detected only at runtime.
Packit 875988
#
Packit 875988
#   Linux kernel version 2.6.19 adds the epoll_pwait() call in addition to
Packit 875988
#   epoll_wait(). The availability of that function can be tested with the
Packit 875988
#   second macro. Generally speaking, it is safe to assume that
Packit 875988
#   AX_HAVE_EPOLL would succeed if AX_HAVE_EPOLL_PWAIT has, but not the
Packit 875988
#   other way round.
Packit 875988
#
Packit 875988
# LICENSE
Packit 875988
#
Packit 875988
#   Copyright (c) 2008 Peter Simons <simons@cryp.to>
Packit 875988
#
Packit 875988
#   Copying and distribution of this file, with or without modification, are
Packit 875988
#   permitted in any medium without royalty provided the copyright notice
Packit 875988
#   and this notice are preserved. This file is offered as-is, without any
Packit 875988
#   warranty.
Packit 875988
Packit 875988
#serial 11
Packit 875988
Packit 875988
AC_DEFUN([AX_HAVE_EPOLL], [dnl
Packit 875988
  ax_have_epoll_cppflags="${CPPFLAGS}"
Packit 875988
  AC_CHECK_HEADER([linux/version.h], [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"])
Packit 875988
  AC_MSG_CHECKING([for Linux epoll(7) interface])
Packit 875988
  AC_CACHE_VAL([ax_cv_have_epoll], [dnl
Packit 875988
    AC_LINK_IFELSE([dnl
Packit 875988
      AC_LANG_PROGRAM([dnl
Packit 875988
#include <sys/epoll.h>
Packit 875988
#ifdef HAVE_LINUX_VERSION_H
Packit 875988
#  include <linux/version.h>
Packit 875988
#  if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,45)
Packit 875988
#    error linux kernel version is too old to have epoll
Packit 875988
#  endif
Packit 875988
#endif
Packit 875988
], [dnl
Packit 875988
int fd, rc;
Packit 875988
struct epoll_event ev;
Packit 875988
fd = epoll_create(128);
Packit 875988
rc = epoll_wait(fd, &ev, 1, 0);])],
Packit 875988
      [ax_cv_have_epoll=yes],
Packit 875988
      [ax_cv_have_epoll=no])])
Packit 875988
  CPPFLAGS="${ax_have_epoll_cppflags}"
Packit 875988
  AS_IF([test "${ax_cv_have_epoll}" = "yes"],
Packit 875988
    [AC_MSG_RESULT([yes])
Packit 875988
$1],[AC_MSG_RESULT([no])
Packit 875988
$2])
Packit 875988
])dnl
Packit 875988
Packit 875988
AC_DEFUN([AX_HAVE_EPOLL_PWAIT], [dnl
Packit 875988
  ax_have_epoll_cppflags="${CPPFLAGS}"
Packit 875988
  AC_CHECK_HEADER([linux/version.h],
Packit 875988
    [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"])
Packit 875988
  AC_MSG_CHECKING([for Linux epoll(7) interface with signals extension])
Packit 875988
  AC_CACHE_VAL([ax_cv_have_epoll_pwait], [dnl
Packit 875988
    AC_LINK_IFELSE([dnl
Packit 875988
      AC_LANG_PROGRAM([dnl
Packit 875988
#ifdef HAVE_LINUX_VERSION_H
Packit 875988
#  include <linux/version.h>
Packit 875988
#  if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
Packit 875988
#    error linux kernel version is too old to have epoll_pwait
Packit 875988
#  endif
Packit 875988
#endif
Packit 875988
#include <sys/epoll.h>
Packit 875988
#include <signal.h>
Packit 875988
], [dnl
Packit 875988
int fd, rc;
Packit 875988
struct epoll_event ev;
Packit 875988
fd = epoll_create(128);
Packit 875988
rc = epoll_wait(fd, &ev, 1, 0);
Packit 875988
rc = epoll_pwait(fd, &ev, 1, 0, (sigset_t const *)(0));])],
Packit 875988
      [ax_cv_have_epoll_pwait=yes],
Packit 875988
      [ax_cv_have_epoll_pwait=no])])
Packit 875988
  CPPFLAGS="${ax_have_epoll_cppflags}"
Packit 875988
  AS_IF([test "${ax_cv_have_epoll_pwait}" = "yes"],
Packit 875988
    [AC_MSG_RESULT([yes])
Packit 875988
$1],[AC_MSG_RESULT([no])
Packit 875988
$2])
Packit 875988
])dnl