Skip to content
Snippets Groups Projects
Commit c03c51cf authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

fdset: require pselect(), remove unsafe compat implementation

parent e5158d04
No related branches found
No related tags found
No related merge requests found
......@@ -334,7 +334,7 @@ AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
# Checks for library functions.
AC_CHECK_FUNCS([clock_gettime gettimeofday fgetln getline madvise malloc_trim poll posix_memalign pselect pthread_setaffinity_np regcomp select setgroups strlcat strlcpy initgroups])
AC_CHECK_FUNCS([clock_gettime gettimeofday fgetln getline madvise malloc_trim poll posix_memalign pthread_setaffinity_np regcomp select setgroups strlcat strlcpy initgroups])
# Check for be64toh function
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <endian.h>]], [[return be64toh(0);]])],
......
......@@ -165,89 +165,3 @@ int fdset_sweep(fdset_t* set, fdset_sweep_cb_t cb, void *data)
return KNOT_EOK;
}
/* OpenBSD compatibility. */
#if !defined(HAVE_PSELECT) || defined(PSELECT_COMPAT)
/*
* Like select(2) but set the signals to block while waiting in
* select. This version is not entirely race condition safe. Only
* operating system support can make it so.
*
* Copyright (c) 2001-2011, NLnet Labs. All rights reserved.
*
* This software is open source.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the NLNET LABS nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h>
static int
pselect_compat (int n,
fd_set *readfds,
fd_set *writefds,
fd_set *exceptfds,
const struct timespec *timeout,
const sigset_t *sigmask)
{
int result;
sigset_t saved_sigmask;
struct timeval saved_timeout;
if (sigmask && sigprocmask(SIG_SETMASK, sigmask, &saved_sigmask) == -1)
return -1;
if (timeout) {
saved_timeout.tv_sec = timeout->tv_sec;
saved_timeout.tv_usec = timeout->tv_nsec / 1000;
result = select(n, readfds, writefds, exceptfds, &saved_timeout);
} else {
result = select(n, readfds, writefds, exceptfds, NULL);
}
if (sigmask && sigprocmask(SIG_SETMASK, &saved_sigmask, NULL) == -1)
return -1;
return result;
}
int fdset_pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timespec *timeout, const sigset_t *sigmask)
{
return pselect_compat(n, readfds, writefds, exceptfds, timeout, sigmask);
}
#else
int fdset_pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timespec *timeout, const sigset_t *sigmask)
{
return pselect(n, readfds, writefds, exceptfds, timeout, sigmask);
}
#endif
......@@ -118,18 +118,4 @@ int fdset_set_watchdog(fdset_t* set, int i, int interval);
*/
int fdset_sweep(fdset_t* set, fdset_sweep_cb_t cb, void *data);
/*!
* \brief pselect(2) compatibility wrapper.
* \param n Number of file descriptors.
* \param readfds Array of fds to read.
* \param writefds Array of fds to write.
* \param exceptfds Array of fds for exceptions.
* \param timeout Upper bound of time elapsed.
* \param sigmask If != NULL, replaces current signal mask.
* \return Number of events or -1 if fails.
*/
int fdset_pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timespec *timeout, const sigset_t *sigmask);
/*! @} */
......@@ -20,7 +20,6 @@
#include "libknot/internal/log.h"
#include "libknot/internal/mem.h"
#include "libknot/internal/macros.h"
#include "knot/common/fdset.h"
#include "knot/knot.h"
#include "knot/conf/conf.h"
#include "libknot/internal/net.h"
......@@ -516,7 +515,7 @@ int remote_poll(int sock)
sock = -1; /* Make sure n == r + 1 == 0 */
}
return fdset_pselect(sock + 1, &rfds, NULL, NULL, NULL, NULL);
return pselect(sock + 1, &rfds, NULL, NULL, NULL, NULL);
}
int remote_recv(int sock, struct sockaddr_storage *addr, uint8_t *buf,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment