diff options
author | dimitri staessens <dimitri.staessens@ugent.be> | 2017-08-18 15:56:55 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@ugent.be> | 2017-08-21 10:25:19 +0200 |
commit | 8f58e5a3ec0e4a15fc8ae0911cc864f5dbf86c6e (patch) | |
tree | 0535742162921dc0d19c16f5b02d2f1c8f4fc493 /src/lib | |
parent | eefae235dd7af96eef3dc4f82f706170c379d260 (diff) | |
download | ouroboros-8f58e5a3ec0e4a15fc8ae0911cc864f5dbf86c6e.tar.gz ouroboros-8f58e5a3ec0e4a15fc8ae0911cc864f5dbf86c6e.zip |
build: Revise the build system
This revises the build system to have configuration per system
component. System settings can now be set using cmake.
The standard compliance defines were removed from configuration header
and are set in the sources where needed. Also some small code
refactors, such as moving the data for shims out of the ipcp structure
to the respective shims were performed.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/CMakeLists.txt | 104 | ||||
-rw-r--r-- | src/lib/cacep.c | 3 | ||||
-rw-r--r-- | src/lib/cdap.c | 3 | ||||
-rw-r--r-- | src/lib/cdap_req.c | 5 | ||||
-rw-r--r-- | src/lib/cdap_req.h | 1 | ||||
-rw-r--r-- | src/lib/config.h.in | 57 | ||||
-rw-r--r-- | src/lib/dev.c | 15 | ||||
-rw-r--r-- | src/lib/frct_pci.c | 1 | ||||
-rw-r--r-- | src/lib/hash.c | 3 | ||||
-rw-r--r-- | src/lib/irm.c | 3 | ||||
-rw-r--r-- | src/lib/lockfile.c | 15 | ||||
-rw-r--r-- | src/lib/md5.c | 2 | ||||
-rw-r--r-- | src/lib/nsm.c | 55 | ||||
-rw-r--r-- | src/lib/random.c | 3 | ||||
-rw-r--r-- | src/lib/rib.c | 5 | ||||
-rw-r--r-- | src/lib/shm_flow_set.c | 43 | ||||
-rw-r--r-- | src/lib/shm_rbuff.c | 7 | ||||
-rw-r--r-- | src/lib/shm_rbuff_ll.c | 3 | ||||
-rw-r--r-- | src/lib/shm_rbuff_pthr.c | 3 | ||||
-rw-r--r-- | src/lib/shm_rdrbuff.c | 5 | ||||
-rw-r--r-- | src/lib/sockets.c | 1 | ||||
-rw-r--r-- | src/lib/tests/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/lib/tests/rib_test.c | 3 | ||||
-rw-r--r-- | src/lib/time_utils.c | 3 | ||||
-rw-r--r-- | src/lib/timerwheel.c | 5 | ||||
-rw-r--r-- | src/lib/tpm.c | 5 |
26 files changed, 246 insertions, 115 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 728d975a..4522613b 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -15,7 +15,7 @@ protobuf_generate_c(CACEP_PROTO_SRCS CACEP_PROTO_HDRS cacep.proto) if (NOT APPLE) find_library(LIBRT_LIBRARIES rt) if (NOT LIBRT_LIBRARIES) - message(FATAL_ERROR "Could not find librt.") + message(FATAL_ERROR "Could not find librt") endif () else () set(LIBRT_LIBRARIES "") @@ -23,7 +23,7 @@ endif () find_library(LIBPTHREAD_LIBRARIES pthread) if (NOT LIBPTHREAD_LIBRARIES) - message(FATAL_ERROR "Could not find libpthread.") + message(FATAL_ERROR "Could not find libpthread") endif () include(CheckSymbolExists) @@ -31,30 +31,60 @@ list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L) list(APPEND CMAKE_REQUIRED_DEFINITIONS -D__XSI_VISIBLE=500) list(APPEND CMAKE_REQUIRED_LIBRARIES pthread) check_symbol_exists(pthread_mutexattr_setrobust pthread.h HAVE_ROBUST_MUTEX) -set(HAVE_ROBUST_MUTEX CACHE STRING "Have robust mutexes") + +if (HAVE_ROBUST_MUTEX) + set(DISABLE_ROBUST_MUTEXES FALSE CACHE BOOL "Disable robust mutex support") + if (NOT DISABLE_ROBUST_MUTEXES) + message(STATUS "Robust mutex support enabled") + set(HAVE_ROBUST_MUTEX TRUE) + else () + message(STATUS "Robust mutex support disabled by user") + set(HAVE_ROBUST_MUTEX FALSE) + endif () +endif () find_library(LIBGCRYPT_LIBRARIES gcrypt) if (LIBGCRYPT_LIBRARIES) - find_path(LIBGCRYPT_INCLUDE_DIR gcrypt.h HINTS /usr/include /usr/local/include) - if (NOT LIBGCRYPT_INCLUDE_DIR STREQUAL "GRYPT_INCLUDE_DIR-NOTFOUND") + find_path(LIBGCRYPT_INCLUDE_DIR gcrypt.h + HINTS /usr/include /usr/local/include) + if (LIBGCRYPT_INCLUDE_DIR) file(STRINGS ${LIBGCRYPT_INCLUDE_DIR}/gcrypt.h GCSTR REGEX "^#define GCRYPT_VERSION ") string(REGEX REPLACE "^#define GCRYPT_VERSION \"(.*)\".*$" "\\1" GCVER "${GCSTR}") - message(STATUS "Found libgcrypt: ${LIBGCRYPT_LIBRARIES} (found version \"${GCVER}\")") + message(STATUS "Found libgcrypt: ${LIBGCRYPT_LIBRARIES}" + "(found version \"${GCVER}\")") if (NOT GCVER VERSION_LESS "1.7.0") - set(HAVE_LIBGCRYPT "1" CACHE STRING "Have libgcrypt") + set (DISABLE_LIBGCRYPT FALSE CACHE BOOL "Disable libgcrypt support") + if (NOT DISABLE_LIBGCRYPT) + message(STATUS "libgcrypt support enabled") + set(HAVE_LIBGCRYPT TRUE) + else () + message(STATUS "libgcrpyt support disabled by user") + endif() + else () + message(STATUS "Install version > \"1.7.0\" to enable libgcrypt support") endif() endif () -else () +endif () + +if (NOT HAVE_LIBGCRYPT) set(LIBGCRYPT_LIBRARIES "") set(LIBGCRYPT_INCLUDE_DIR "") endif () find_package(OpenSSL) if (OPENSSL_FOUND) - set(HAVE_OPENSSL "1" CACHE STRING "Have OpenSSL") -else () + set (DISABLE_OPENSSL FALSE CACHE BOOL "Disable OpenSSL support") + if (NOT DISABLE_OPENSSL) + message(STATUS "OpenSSL support enabled") + set(HAVE_OPENSSL TRUE) + else() + message(STATUS "OpenSSL support disabled by user") + endif() +endif () + +if (NOT HAVE_OPENSSL) set (OPENSSL_INCLUDE_DIR "") endif () @@ -62,9 +92,9 @@ if (APPLE OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") set(SYS_RND_HDR "") else () find_path(SYS_RND_HDR sys/random.h PATH /usr/include/ /usr/local/include/) - if (NOT SYS_RND_HDR STREQUAL "SYS_RND_HDR-NOTFOUND") + if (SYS_RND_HDR) message(STATUS "Found sys/random.h in ${SYS_RND_HDR}") - set(HAVE_SYS_RANDOM "1" CACHE STRING "Have random header") + set(HAVE_SYS_RANDOM TRUE) else () set(SYS_RND_HDR "") endif () @@ -73,10 +103,52 @@ endif() if (NOT ((CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") OR APPLE OR HAVE_SYS_RANDOM OR HAVE_OPENSSL OR HAVE_LIBGCRYPT)) message(FATAL_ERROR "No secure random generator found, " - "please install libgcrypt (> 1.7.0) or OpenSSL" - ) + "please install libgcrypt (> 1.7.0) or OpenSSL") endif () +mark_as_advanced(LIBRT_LIBRARIES LIBPTHREAD_LIBRARIES + LIBGCRYPT_LIBRARIES OPENSSL_LIBRARIES SYS_RND_INCLUDE_DIR + LIBGCRYPT_INCLUDE_DIR SYS_RND_HDR) + +math(EXPR SHM_BUFFER_EXPR "1 << 20") +set(SHM_BUFFER_SIZE ${SHM_BUFFER_EXPR} CACHE STRING + "Number of blocks in SDU buffer, must be a power of 2") +set(SYS_MAX_FLOWS 4096 CACHE STRING + "Maximum number of total flows for this system") +set(AP_MAX_FLOWS 1024 CACHE STRING + "Maximum number of flows in an application") +set(AP_RES_FDS 64 CACHE STRING + "Number of reserved flow descriptors per application") +set(AP_MAX_FQUEUES 32 CACHE STRING + "Maximum number of flow sets per application") +set(DU_BUFF_HEADSPACE 128 CACHE STRING + "Bytes of headspace to reserve for future headers") +set(DU_BUFF_TAILSPACE 0 CACHE STRING + "Bytes of tailspace to reserve for future tails") +if (NOT APPLE) + set(PTHREAD_COND_CLOCK "CLOCK_MONOTONIC" CACHE STRING + "Clock to use for condition variable timing") +else () + set (PTHREAD_COND_CLOCK "CLOCK_REALTIME" CACHE INTERNAL + "Clock to use for condition variable timing") +endif () +set(SOCKET_TIMEOUT 1000 CACHE STRING + "Default timeout for responses from IPCPs (ms)") +set(CDAP_REPLY_TIMEOUT 6000 CACHE STRING + "Timeout for CDAP to wait for reply") +set(SHM_PREFIX "ouroboros" CACHE STRING + "String to prepend to POSIX shared memory filenames") +set(SHM_RBUFF_PREFIX "/${SHM_PREFIX}.rbuff." CACHE INTERNAL + "Prefix for rbuff POSIX shared memory filenames") +set(SHM_LOCKFILE_NAME "/${SHM_PREFIX}.lockfile" CACHE INTERNAL + "Filename for the POSIX shared memory lockfile") +set(SHM_FLOW_SET_PREFIX "/${SHM_PREFIX}.set." CACHE INTERNAL + "Prefix for the POSIX shared memory flow set") +set(SHM_RDRB_NAME "/${SHM_PREFIX}.rdrb" CACHE INTERNAL + "Name for the main POSIX shared memory buffer") +set(SHM_RDRB_BLOCK_SIZE "sysconf(_SC_PAGESIZE)" CACHE STRING + "SDU buffer block size, multiple of pagesize for performance") + set(SOURCE_FILES # Add source files here bitmap.c @@ -94,7 +166,6 @@ set(SOURCE_FILES lockfile.c logs.c md5.c - nsm.c qos.c qoscube.c random.c @@ -110,6 +181,9 @@ set(SOURCE_FILES utils.c ) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY) + add_library(ouroboros SHARED ${SOURCE_FILES} ${IRM_PROTO_SRCS} ${IPCP_PROTO_SRCS} ${DIF_CONFIG_PROTO_SRCS} ${CDAP_PROTO_SRCS} ${CACEP_PROTO_SRCS} ${RO_PROTO_SRCS}) diff --git a/src/lib/cacep.c b/src/lib/cacep.c index 55d11b0f..722adca1 100644 --- a/src/lib/cacep.c +++ b/src/lib/cacep.c @@ -20,7 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 199309L + #include <ouroboros/cacep.h> #include <ouroboros/dev.h> #include <ouroboros/errno.h> diff --git a/src/lib/cdap.c b/src/lib/cdap.c index bf8d5816..679771f5 100644 --- a/src/lib/cdap.c +++ b/src/lib/cdap.c @@ -20,7 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200809L + #include <ouroboros/cdap.h> #include <ouroboros/bitmap.h> #include <ouroboros/dev.h> diff --git a/src/lib/cdap_req.c b/src/lib/cdap_req.c index 7aded62f..a9b85525 100644 --- a/src/lib/cdap_req.c +++ b/src/lib/cdap_req.c @@ -20,7 +20,10 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200809L + +#include "config.h" + #include <ouroboros/time_utils.h> #include <ouroboros/errno.h> diff --git a/src/lib/cdap_req.h b/src/lib/cdap_req.h index 89f4145a..4c9cd15b 100644 --- a/src/lib/cdap_req.h +++ b/src/lib/cdap_req.h @@ -23,7 +23,6 @@ #ifndef OUROBOROS_CDAP_REQ_H #define OUROBOROS_CDAP_REQ_H -#include <ouroboros/config.h> #include <ouroboros/cdap.h> #include <ouroboros/list.h> #include <ouroboros/utils.h> diff --git a/src/lib/config.h.in b/src/lib/config.h.in new file mode 100644 index 00000000..c4b189d7 --- /dev/null +++ b/src/lib/config.h.in @@ -0,0 +1,57 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Ouroboros library configuration + * + * Dimitri Staessens <dimitri.staessens@ugent.be> + * Sander Vrijders <sander.vrijders@ugent.be> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#cmakedefine HAVE_SYS_RANDOM +#cmakedefine HAVE_LIBGCRYPT +#cmakedefine HAVE_OPENSSL + +#define SYS_MAX_FLOWS @SYS_MAX_FLOWS@ + +#cmakedefine SHM_RBUFF_LOCKLESS + +#define SHM_RBUFF_PREFIX "@SHM_RBUFF_PREFIX@" +#define SHM_LOCKFILE_NAME "@SHM_LOCKFILE_NAME@" +#define SHM_FLOW_SET_PREFIX "@SHM_FLOW_SET_PREFIX@" +#define SHM_RDRB_NAME "@SHM_RDRB_NAME@" +#define SHM_RDRB_BLOCK_SIZE @SHM_RDRB_BLOCK_SIZE@ +#define SHM_BUFFER_SIZE @SHM_BUFFER_SIZE@ + +#if defined(__linux__) || (defined(__MACH__) && !defined(__APPLE__)) +/* Avoid a bug in robust mutex implementation of glibc 2.25 */ + #include <features.h> + #if !defined(__GLIBC__) || !(__GLIBC__ == 2 && __GLIBC_MINOR__ == 25) + #cmakedefine HAVE_ROBUST_MUTEX + #else + #cmakedefine HAVE_ROBUST_MUTEX + #endif +#endif + +#define PTHREAD_COND_CLOCK @PTHREAD_COND_CLOCK@ + +#define AP_MAX_FLOWS @AP_MAX_FLOWS@ +#define AP_RES_FDS @AP_RES_FDS@ +#define AP_MAX_FQUEUES @AP_MAX_FQUEUES@ + +#define DU_BUFF_HEADSPACE @DU_BUFF_HEADSPACE@ +#define DU_BUFF_TAILSPACE @DU_BUFF_TAILSPACE@ + +#define CDAP_REPLY_TIMEOUT @CDAP_REPLY_TIMEOUT@ diff --git a/src/lib/dev.c b/src/lib/dev.c index e81bf105..1018f556 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -20,7 +20,10 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200809L + +#include "config.h" + #include <ouroboros/errno.h> #include <ouroboros/dev.h> #include <ouroboros/ipcp-dev.h> @@ -596,7 +599,7 @@ int ouroboros_init(const char * ap_name) frcti_fini(i); } - ai.ports = malloc(sizeof(*ai.ports) * IRMD_MAX_FLOWS); + ai.ports = malloc(sizeof(*ai.ports) * SYS_MAX_FLOWS); if (ai.ports == NULL) goto fail_ports; @@ -611,7 +614,7 @@ int ouroboros_init(const char * ap_name) } } - for (i = 0; i < IRMD_MAX_FLOWS; ++i) { + for (i = 0; i < SYS_MAX_FLOWS; ++i) { ai.ports[i].state = PORT_INIT; if (pthread_mutex_init(&ai.ports[i].state_lock, NULL)) { int j; @@ -640,10 +643,10 @@ int ouroboros_init(const char * ap_name) fail_timerwheel: pthread_rwlock_destroy(&ai.lock); fail_lock: - for (i = 0; i < IRMD_MAX_FLOWS; ++i) + for (i = 0; i < SYS_MAX_FLOWS; ++i) pthread_cond_destroy(&ai.ports[i].state_cond); fail_state_cond: - for (i = 0; i < IRMD_MAX_FLOWS; ++i) + for (i = 0; i < SYS_MAX_FLOWS; ++i) pthread_mutex_destroy(&ai.ports[i].state_lock); fail_announce: free(ai.ap_name); @@ -688,7 +691,7 @@ void ouroboros_fini() } } - for (i = 0; i < IRMD_MAX_FLOWS; ++i) { + for (i = 0; i < SYS_MAX_FLOWS; ++i) { pthread_mutex_destroy(&ai.ports[i].state_lock); pthread_cond_destroy(&ai.ports[i].state_cond); } diff --git a/src/lib/frct_pci.c b/src/lib/frct_pci.c index 92cf8cd9..392e11c6 100644 --- a/src/lib/frct_pci.c +++ b/src/lib/frct_pci.c @@ -20,7 +20,6 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> #include <ouroboros/frct_pci.h> #include <ouroboros/hash.h> #include <ouroboros/errno.h> diff --git a/src/lib/hash.c b/src/lib/hash.c index e062a0ad..09e5be8c 100644 --- a/src/lib/hash.c +++ b/src/lib/hash.c @@ -23,7 +23,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#include "config.h" + #include <ouroboros/hash.h> #ifndef HAVE_LIBGCRYPT diff --git a/src/lib/irm.c b/src/lib/irm.c index a6075d33..4232cec1 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -20,7 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200809L + #include <ouroboros/errno.h> #include <ouroboros/hash.h> #include <ouroboros/irm.h> diff --git a/src/lib/lockfile.c b/src/lib/lockfile.c index e2e4d289..4a3dcb91 100644 --- a/src/lib/lockfile.c +++ b/src/lib/lockfile.c @@ -20,7 +20,10 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200112L + +#include "config.h" + #include <ouroboros/lockfile.h> #include <stdlib.h> @@ -47,7 +50,7 @@ struct lockfile * lockfile_create() { mask = umask(0); - fd = shm_open(LOCKFILE_NAME, O_CREAT | O_EXCL | O_RDWR, 0666); + fd = shm_open(SHM_LOCKFILE_NAME, O_CREAT | O_EXCL | O_RDWR, 0666); if (fd == -1) { free(lf); return NULL; @@ -69,7 +72,7 @@ struct lockfile * lockfile_create() { close (fd); if (lf->api == MAP_FAILED) { - shm_unlink(LOCKFILE_NAME); + shm_unlink(SHM_LOCKFILE_NAME); free(lf); return NULL; } @@ -85,7 +88,7 @@ struct lockfile * lockfile_open() { if (lf == NULL) return NULL; - fd = shm_open(LOCKFILE_NAME, O_RDWR, 0666); + fd = shm_open(SHM_LOCKFILE_NAME, O_RDWR, 0666); if (fd < 0) { free(lf); return NULL; @@ -100,7 +103,7 @@ struct lockfile * lockfile_open() { close(fd); if (lf->api == MAP_FAILED) { - shm_unlink(LOCKFILE_NAME); + shm_unlink(SHM_LOCKFILE_NAME); free(lf); return NULL; } @@ -126,7 +129,7 @@ void lockfile_destroy(struct lockfile * lf) munmap(lf->api, LF_SIZE); - shm_unlink(LOCKFILE_NAME); + shm_unlink(SHM_LOCKFILE_NAME); free(lf); } diff --git a/src/lib/md5.c b/src/lib/md5.c index a4d92de3..3394f406 100644 --- a/src/lib/md5.c +++ b/src/lib/md5.c @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 - 2017 * - * SHA3 algorithm + * MD5 algorithm * * Dimitri Staessens <dimitri.staessens@ugent.be> * Sander Vrijders <sander.vrijders@ugent.be> diff --git a/src/lib/nsm.c b/src/lib/nsm.c deleted file mode 100644 index 2dd5729b..00000000 --- a/src/lib/nsm.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * The API to instruct the global Namespace Manager - * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., http://www.fsf.org/about/contact/. - */ - -#include <ouroboros/nsm.h> - -int nsm_reg(char * name, - char ** dafs, - size_t dafs_size) -{ - (void) name; - (void) dafs; - (void) dafs_size; - - return -1; -} - -int nsm_unreg(char * name, - char ** dafs, - size_t dafs_size) -{ - (void) name; - (void) dafs; - (void) dafs_size; - - - return -1; -} - -ssize_t nsm_resolve(char * name, - char ** dafs) -{ - (void) name; - (void) dafs; - - return -1; -} diff --git a/src/lib/random.c b/src/lib/random.c index 66aefaa3..27719b26 100644 --- a/src/lib/random.c +++ b/src/lib/random.c @@ -20,7 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#include "config.h" + #include <ouroboros/random.h> #if defined(__APPLE__) /* Barf */ diff --git a/src/lib/rib.c b/src/lib/rib.c index e8cf97d4..104dc0cc 100644 --- a/src/lib/rib.c +++ b/src/lib/rib.c @@ -20,7 +20,10 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200809L + +#include "config.h" + #include <ouroboros/errno.h> #include <ouroboros/list.h> #include <ouroboros/rib.h> diff --git a/src/lib/shm_flow_set.c b/src/lib/shm_flow_set.c index 2f1d4e33..f4a70689 100644 --- a/src/lib/shm_flow_set.c +++ b/src/lib/shm_flow_set.c @@ -20,7 +20,10 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200809L + +#include "config.h" + #include <ouroboros/lockfile.h> #include <ouroboros/time_utils.h> #include <ouroboros/shm_flow_set.h> @@ -38,11 +41,22 @@ #include <string.h> #include <assert.h> +/* + * pthread_cond_timedwait has a WONTFIX bug as of glibc 2.25 where it + * doesn't test pthread cancellation when passed an expired timeout + * with the clock set to CLOCK_MONOTONIC. + */ +#if ((defined(__linux__) || (defined(__MACH__) && !defined(__APPLE__))) \ + && (defined(__GLIBC__) && ((__GLIBC__ * 1000 + __GLIBC_MINOR__) >= 2025)) \ + && (PTHREAD_COND_CLOCK == CLOCK_MONOTONIC)) +#define HAVE_CANCEL_BUG +#endif + #define FN_MAX_CHARS 255 #define FQUEUESIZE ((SHM_BUFFER_SIZE) * sizeof(int)) -#define SHM_FLOW_SET_FILE_SIZE (IRMD_MAX_FLOWS * sizeof(ssize_t) \ +#define SHM_FLOW_SET_FILE_SIZE (SYS_MAX_FLOWS * sizeof(ssize_t) \ + AP_MAX_FQUEUES * sizeof(size_t) \ + AP_MAX_FQUEUES * sizeof(pthread_cond_t) \ + AP_MAX_FQUEUES * FQUEUESIZE \ @@ -109,7 +123,7 @@ struct shm_flow_set * shm_flow_set_create() } set->mtable = shm_base; - set->heads = (size_t *) (set->mtable + IRMD_MAX_FLOWS); + set->heads = (size_t *) (set->mtable + SYS_MAX_FLOWS); set->conds = (pthread_cond_t *)(set->heads + AP_MAX_FQUEUES); set->fqueues = (int *) (set->conds + AP_MAX_FQUEUES); set->lock = (pthread_mutex_t *) @@ -132,7 +146,7 @@ struct shm_flow_set * shm_flow_set_create() pthread_cond_init(&set->conds[i], &cattr); } - for (i = 0; i < IRMD_MAX_FLOWS; ++i) + for (i = 0; i < SYS_MAX_FLOWS; ++i) set->mtable[i] = -1; set->api = getpid(); @@ -175,7 +189,7 @@ struct shm_flow_set * shm_flow_set_open(pid_t api) } set->mtable = shm_base; - set->heads = (size_t *) (set->mtable + IRMD_MAX_FLOWS); + set->heads = (size_t *) (set->mtable + SYS_MAX_FLOWS); set->conds = (pthread_cond_t *)(set->heads + AP_MAX_FQUEUES); set->fqueues = (int *) (set->conds + AP_MAX_FQUEUES); set->lock = (pthread_mutex_t *) @@ -233,7 +247,7 @@ void shm_flow_set_zero(struct shm_flow_set * set, pthread_mutex_lock(set->lock); - for (i = 0; i < IRMD_MAX_FLOWS; ++i) + for (i = 0; i < SYS_MAX_FLOWS; ++i) if (set->mtable[i] == (ssize_t) idx) set->mtable[i] = -1; @@ -248,7 +262,7 @@ int shm_flow_set_add(struct shm_flow_set * set, int port_id) { assert(set); - assert(!(port_id < 0) && port_id < IRMD_MAX_FLOWS); + assert(!(port_id < 0) && port_id < SYS_MAX_FLOWS); assert(idx < AP_MAX_FQUEUES); pthread_mutex_lock(set->lock); @@ -270,7 +284,7 @@ void shm_flow_set_del(struct shm_flow_set * set, int port_id) { assert(set); - assert(!(port_id < 0) && port_id < IRMD_MAX_FLOWS); + assert(!(port_id < 0) && port_id < SYS_MAX_FLOWS); assert(idx < AP_MAX_FQUEUES); pthread_mutex_lock(set->lock); @@ -288,7 +302,7 @@ int shm_flow_set_has(struct shm_flow_set * set, int ret = 0; assert(set); - assert(!(port_id < 0) && port_id < IRMD_MAX_FLOWS); + assert(!(port_id < 0) && port_id < SYS_MAX_FLOWS); assert(idx < AP_MAX_FQUEUES); pthread_mutex_lock(set->lock); @@ -305,7 +319,7 @@ void shm_flow_set_notify(struct shm_flow_set * set, int port_id) { assert(set); - assert(!(port_id < 0) && port_id < IRMD_MAX_FLOWS); + assert(!(port_id < 0) && port_id < SYS_MAX_FLOWS); pthread_mutex_lock(set->lock); @@ -345,13 +359,18 @@ ssize_t shm_flow_set_wait(const struct shm_flow_set * set, (void *) set->lock); while (set->heads[idx] == 0 && ret != -ETIMEDOUT) { - if (abstime != NULL) + if (abstime != NULL) { ret = -pthread_cond_timedwait(set->conds + idx, set->lock, abstime); - else +#ifdef HAVE_CANCEL_BUG + if (ret == -ETIMEDOUT) + pthread_testcancel(); +#endif + } else { ret = -pthread_cond_wait(set->conds + idx, set->lock); + } #ifdef HAVE_ROBUST_MUTEX if (ret == -EOWNERDEAD) pthread_mutex_consistent(set->lock); diff --git a/src/lib/shm_rbuff.c b/src/lib/shm_rbuff.c index 7f8af9f5..93108332 100644 --- a/src/lib/shm_rbuff.c +++ b/src/lib/shm_rbuff.c @@ -19,9 +19,12 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> -#if ((SHM_RBUFF_LOCKLESS > 0) && \ +#define _POSIX_C_SOURCE 200809L + +#include "config.h" + +#if (defined(SHM_RBUFF_LOCKLESS) && \ (defined(__GNUC__) || defined (__clang__))) #include "shm_rbuff_ll.c" #else diff --git a/src/lib/shm_rbuff_ll.c b/src/lib/shm_rbuff_ll.c index b420b785..ec0199c0 100644 --- a/src/lib/shm_rbuff_ll.c +++ b/src/lib/shm_rbuff_ll.c @@ -20,7 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#include "config.h" + #include <ouroboros/shm_rbuff.h> #include <ouroboros/lockfile.h> #include <ouroboros/time_utils.h> diff --git a/src/lib/shm_rbuff_pthr.c b/src/lib/shm_rbuff_pthr.c index 7dc5f5d9..9567762f 100644 --- a/src/lib/shm_rbuff_pthr.c +++ b/src/lib/shm_rbuff_pthr.c @@ -20,7 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200809L + #include <ouroboros/shm_rbuff.h> #include <ouroboros/lockfile.h> #include <ouroboros/time_utils.h> diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c index 0919b1e0..447f8b35 100644 --- a/src/lib/shm_rdrbuff.c +++ b/src/lib/shm_rdrbuff.c @@ -20,7 +20,10 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200809L + +#include "config.h" + #include <ouroboros/errno.h> #include <ouroboros/shm_rdrbuff.h> #include <ouroboros/shm_du_buff.h> diff --git a/src/lib/sockets.c b/src/lib/sockets.c index 7f0c4dd4..263d2356 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -20,7 +20,6 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> #include <ouroboros/errno.h> #include <ouroboros/sockets.h> #include <ouroboros/utils.h> diff --git a/src/lib/tests/CMakeLists.txt b/src/lib/tests/CMakeLists.txt index fd3c1c6a..0223262a 100644 --- a/src/lib/tests/CMakeLists.txt +++ b/src/lib/tests/CMakeLists.txt @@ -1,6 +1,12 @@ get_filename_component(PARENT_PATH ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) get_filename_component(PARENT_DIR ${PARENT_PATH} NAME) +if (NOT (APPLE OR GNU)) + set(TIMERWHEEL_TEST "timerwheel_test.c") +else () + set(TIMERWHEEL_TEST "") +endif () + create_test_sourcelist(${PARENT_DIR}_tests test_suite.c # Add new tests here bitmap_test.c @@ -11,7 +17,7 @@ create_test_sourcelist(${PARENT_DIR}_tests test_suite.c rib_test.c sha3_test.c time_utils_test.c - timerwheel_test.c + ${TIMERWHEEL_TEST} ) add_executable(${PARENT_DIR}_test EXCLUDE_FROM_ALL ${${PARENT_DIR}_tests}) diff --git a/src/lib/tests/rib_test.c b/src/lib/tests/rib_test.c index e1fa427d..6a2446b9 100644 --- a/src/lib/tests/rib_test.c +++ b/src/lib/tests/rib_test.c @@ -20,7 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 199309L + #include <ouroboros/time_utils.h> #include <ouroboros/rib.h> #include <ouroboros/rqueue.h> diff --git a/src/lib/time_utils.c b/src/lib/time_utils.c index 2dec4524..22937d4b 100644 --- a/src/lib/time_utils.c +++ b/src/lib/time_utils.c @@ -20,7 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 199309L + #include <ouroboros/time_utils.h> #include <stddef.h> diff --git a/src/lib/timerwheel.c b/src/lib/timerwheel.c index 7e2779d0..76f0ab32 100644 --- a/src/lib/timerwheel.c +++ b/src/lib/timerwheel.c @@ -20,7 +20,10 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200112L + +#include "config.h" + #include <ouroboros/time_utils.h> #include <ouroboros/errno.h> #include <ouroboros/list.h> diff --git a/src/lib/tpm.c b/src/lib/tpm.c index 739996c4..dd71d276 100644 --- a/src/lib/tpm.c +++ b/src/lib/tpm.c @@ -20,7 +20,10 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/config.h> +#define _POSIX_C_SOURCE 200112L + +#include "config.h" + #include <ouroboros/errno.h> #include <ouroboros/list.h> #include <ouroboros/time_utils.h> |