Skip to content
Snippets Groups Projects
Commit 1c70c532 authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

OpenBSD compatibility patch.

TODO:
* OpenBSD posix_memalign() is broken, Slab allocator is disabled.

refs #1551
parent dcbc526d
No related merge requests found
......@@ -13,6 +13,7 @@ AX_EXT
AM_MAINTAINER_MODE([enable])
# Initialize libtool
AC_PROG_LIBTOOL
LT_INIT
# Checks for programs.
......@@ -116,7 +117,7 @@ AC_SEARCH_LIBS([OpenSSL_add_all_digests], [crypto],[], [AC_MSG_ERROR([libcrypto
# Checks for header files.
AC_HEADER_RESOLV
AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h malloc.h netdb.h netinet/in.h stdint.h stdlib.h string.h strings.h sys/socket.h sys/time.h syslog.h unistd.h urcu.h ev.h])
AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h malloc.h netdb.h netinet/in_systm.h netinet/in.h stdint.h stdlib.h string.h strings.h sys/socket.h sys/time.h syslog.h unistd.h urcu.h ev.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
......@@ -136,7 +137,7 @@ AC_DEFINE([DSFMT_MEXP], [521], [DSFMT parameters.])
# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_MMAP
AC_CHECK_FUNCS([gethostbyname gettimeofday memmove memset munmap regcomp select socket sqrt strcasecmp strchr strdup strerror strncasecmp strtol strtoul poll epoll_wait kqueue setgroups])
AC_CHECK_FUNCS([gethostbyname gettimeofday memmove memset munmap regcomp pselect select socket sqrt strcasecmp strchr strdup strerror strncasecmp strtol strtoul poll epoll_wait kqueue setgroups])
AC_CONFIG_FILES([Makefile
samples/Makefile
......
......@@ -17,6 +17,84 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <config.h>
/* OpenBSD compatibility. */
#ifndef HAVE_PSELECT
/*
* 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>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#include <unistd.h>
#include <signal.h>
static int
pselect (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;
}
#endif
#include "common/evqueue.h"
......
......@@ -17,9 +17,15 @@
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include <config.h>
#include "common/evsched.h"
/*! \todo Fix properly. */
#ifndef HAVE_PSELECT
#define OPENBSD_SLAB_BROKEN
#endif
/*!
* \brief Set event timer to T (now) + dt miliseconds.
*/
......@@ -60,7 +66,9 @@ evsched_t *evsched_new()
pthread_mutex_init(&s->mx, 0);
pthread_cond_init(&s->notify, 0);
pthread_mutex_init(&s->cache.lock, 0);
#ifndef OPENBSD_SLAB_BROKEN
slab_cache_init(&s->cache.alloc, sizeof(event_t));
#endif
init_list(&s->calendar);
return s;
}
......@@ -83,8 +91,10 @@ void evsched_delete(evsched_t **s)
evsched_event_free((*s), (event_t*)n);
}
#ifndef OPENBSD_SLAB_BROKEN
/* Free allocator. */
slab_cache_destroy(&(*s)->cache.alloc);
#endif
pthread_mutex_destroy(&(*s)->cache.lock);
/* Free scheduler. */
......@@ -99,9 +109,16 @@ event_t *evsched_event_new(evsched_t *s, int type)
}
/* Allocate. */
#ifndef OPENBSD_SLAB_BROKEN
pthread_mutex_lock(&s->cache.lock);
event_t *e = slab_cache_alloc(&s->cache.alloc);
pthread_mutex_unlock(&s->cache.lock);
#else
event_t *e = malloc(sizeof(event_t));
#endif
if (e == NULL) {
return NULL;
}
/* Initialize. */
memset(e, 0, sizeof(event_t));
......@@ -115,9 +132,13 @@ void evsched_event_free(evsched_t *s, event_t *ev)
return;
}
#ifndef OPENBSD_SLAB_BROKEN
pthread_mutex_lock(&s->cache.lock);
slab_free(ev);
pthread_mutex_unlock(&s->cache.lock);
#else
free(ev);
#endif
}
event_t* evsched_next(evsched_t *s)
......
......@@ -22,7 +22,11 @@
#include <errno.h>
#include <stdio.h>
#include <netdb.h>
#include <time.h>
#include <sys/socket.h>
#ifdef HAVE_NETINET_IN_SYSTM_H
#include <netinet/in_systm.h>
#endif
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
......
......@@ -227,23 +227,13 @@ static inline int udp_master_recvfrom(dthread_t *thread, stat_t *thread_stat)
int sock = dup(h->fd);
uint8_t qbuf[SOCKET_MTU_SZ];
struct msghdr msg;
memset(&msg, 0, sizeof(struct msghdr));
struct iovec iov;
memset(&iov, 0, sizeof(struct iovec));
iov.iov_base = qbuf;
iov.iov_len = SOCKET_MTU_SZ;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_name = addr.ptr;
msg.msg_namelen = addr.len;
/* Loop until all data is read. */
ssize_t n = 0;
while (n >= 0) {
/* Receive packet. */
n = recvmsg(sock, &msg, 0);
n = recvfrom(sock, qbuf, SOCKET_MTU_SZ, 0, addr.ptr, &addr.len);
/* Cancellation point. */
if (dt_is_cancelled(thread)) {
......
......@@ -100,20 +100,8 @@ static int xfr_udp_timeout(event_t *e)
*/
static int xfr_process_udp_query(xfrworker_t *w, int fd, knot_ns_xfr_t *data)
{
/* Prepare msg header. */
struct msghdr msg;
memset(&msg, 0, sizeof(struct msghdr));
struct iovec iov;
memset(&iov, 0, sizeof(struct iovec));
iov.iov_base = data->wire;
iov.iov_len = data->wire_size;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_name = data->addr.ptr;
msg.msg_namelen = data->addr.len;
/* Receive msg. */
ssize_t n = recvmsg(data->session, &msg, 0);
ssize_t n = recvfrom(data->session, data->wire, data->wire_size, 0, data->addr.ptr, &data->addr.len);
size_t resp_len = data->wire_size;
if (n > 0) {
udp_handle(fd, data->wire, n, &resp_len, &data->addr, w->ns);
......
......@@ -71,7 +71,7 @@ typedef struct stat_stat stat_t;
#ifdef STAT_COMPILE
stat_t *stat_new();
#else
inline stat_t *stat_new()
static inline inline stat_t *stat_new()
{
return NULL;
}
......
......@@ -14,6 +14,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include "tests/common/acl_tests.h"
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment