summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt11
-rw-r--r--include/ouroboros/config.h.in2
-rw-r--r--include/ouroboros/endian.h3
-rw-r--r--include/ouroboros/time_utils.h23
-rw-r--r--src/ipcpd/CMakeLists.txt2
-rw-r--r--src/ipcpd/normal/dht.c4
-rw-r--r--src/irmd/main.c4
-rw-r--r--src/lib/CMakeLists.txt35
-rw-r--r--src/lib/bitmap.c1
-rw-r--r--src/lib/hashtable.c1
-rw-r--r--src/lib/random.c19
-rw-r--r--src/lib/shm_rdrbuff.c4
-rw-r--r--src/lib/tests/CMakeLists.txt1
-rw-r--r--src/lib/tests/time_utils_test.c2
-rw-r--r--src/lib/time_utils.c13
15 files changed, 61 insertions, 64 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3c7266eb..ba56dc33 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,6 +19,10 @@ set(PACKAGE_BUGREPORT "None"
set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}"
CACHE STRING "Package version")
+if (APPLE)
+ set(CMAKE_MACOSX_RPATH 1)
+endif()
+
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
@@ -72,8 +76,11 @@ configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/ouroboros.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/ouroboros.pc"
@ONLY)
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ouroboros.pc"
- DESTINATION "/usr/lib/pkgconfig")
+
+if (NOT APPLE)
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ouroboros.pc"
+ DESTINATION "/usr/lib/pkgconfig")
+endif ()
enable_testing()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
diff --git a/include/ouroboros/config.h.in b/include/ouroboros/config.h.in
index 881410eb..d1dac3e9 100644
--- a/include/ouroboros/config.h.in
+++ b/include/ouroboros/config.h.in
@@ -46,7 +46,7 @@
#define AP_MAX_FQUEUES 64
#define SHM_RDRB_BLOCK_SIZE sysconf(_SC_PAGESIZE)
#define SHM_RDRB_MULTI_BLOCK
-#define SHM_RDRB_PREFIX "/ouroboros.rdrb."
+#define SHM_RDRB_NAME "/ouroboros.rdrb"
#define LOCKFILE_NAME "/ouroboros.lockfile"
#define SHM_BUFFER_SIZE 1 << 14
#define DU_BUFF_HEADSPACE 128
diff --git a/include/ouroboros/endian.h b/include/ouroboros/endian.h
index 873aff73..f93428b7 100644
--- a/include/ouroboros/endian.h
+++ b/include/ouroboros/endian.h
@@ -24,7 +24,8 @@
#ifndef OUROBOROS_ENDIAN_H
#define OUROBOROS_ENDIAN_H
-#if defined(__linux__) || defined(__CYGWIN__) || defined(__MACH__)
+#if defined(__linux__) || defined(__CYGWIN__) || \
+ (defined(__MACH__) && !defined(__APPLE__))
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
diff --git a/include/ouroboros/time_utils.h b/include/ouroboros/time_utils.h
index 35f2dcbb..fc70b1ea 100644
--- a/include/ouroboros/time_utils.h
+++ b/include/ouroboros/time_utils.h
@@ -79,27 +79,4 @@ int tv_to_ts(const struct timeval * src,
int ts_to_tv(const struct timespec * src,
struct timeval * dst);
-#ifdef __APPLE__ /* morons */
-
-/* taken from time.h */
-#define CLOCK_REALTIME 0
-#define CLOCK_MONOTONIC 1
-#define CLOCK_PROCESS_CPUTIME_ID 2
-#define CLOCK_THREAD_CPUTIME_ID 3
-#define CLOCK_MONOTONIC_RAW 4
-#define CLOCK_REALTIME_COARSE 5
-#define CLOCK_MONOTONIC_COARSE 6
-#define CLOCK_BOOTTIME 7
-#define CLOCK_REALTIME_ALARM 8
-#define CLOCK_BOOTTIME_ALARM 9
-#define CLOCK_SGI_CYCLE 10 /* Hardware specific */
-#define CLOCK_TAI 11
-
-#define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC)
-#define CLOCKS_MONO CLOCK_MONOTONIC
-
-int clock_gettime(int clock,
- struct timespec * t);
-#endif
-
#endif /* OUROBOROS_TIME_UTILS_H */
diff --git a/src/ipcpd/CMakeLists.txt b/src/ipcpd/CMakeLists.txt
index e0b375b6..2e8bda23 100644
--- a/src/ipcpd/CMakeLists.txt
+++ b/src/ipcpd/CMakeLists.txt
@@ -10,5 +10,5 @@ add_subdirectory(normal)
add_subdirectory(shim-udp)
if (NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL GNU)
add_subdirectory(shim-eth-llc)
+ add_subdirectory(tests)
endif ()
-add_subdirectory(tests)
diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c
index 1f85e4f2..c15dacbc 100644
--- a/src/ipcpd/normal/dht.c
+++ b/src/ipcpd/normal/dht.c
@@ -46,6 +46,10 @@
typedef KadMsg kad_msg_t;
typedef KadContactMsg kad_contact_msg_t;
+#ifndef CLOCK_REALTIME_COARSE
+#define CLOCK_REALTIME_COARSE CLOCK_REALTIME
+#endif
+
#define DHT_MAX_REQS 2048 /* KAD recommends rnd(), bmp can be changed. */
#define KAD_ALPHA 3 /* Parallel factor, proven optimal value. */
#define KAD_K 8 /* Replication factor, MDHT value. */
diff --git a/src/irmd/main.c b/src/irmd/main.c
index de4a07ab..d93f1755 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1687,7 +1687,7 @@ void * mainloop(void * o)
(void) o;
while (true) {
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__APPLE__)
fd_set fds;
struct timeval timeout = {(IRMD_ACCEPT_TIMEOUT / 1000),
(IRMD_ACCEPT_TIMEOUT % 1000) * 1000};
@@ -1710,7 +1710,7 @@ void * mainloop(void * o)
}
ret_msg.code = IRM_MSG_CODE__IRM_REPLY;
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__APPLE__)
FD_ZERO(&fds);
FD_SET(irmd.sockfd, &fds);
if (select(irmd.sockfd + 1, &fds, NULL, NULL, &timeout) <= 0)
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index c6b70d71..550bbc08 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -35,36 +35,42 @@ set(HAVE_ROBUST_MUTEX CACHE STRING "Have robust mutexes")
find_library(LIBGCRYPT_LIBRARIES gcrypt)
if (LIBGCRYPT_LIBRARIES)
- find_path(GCRYPT_INCLUDE_DIR gcrypt.h HINTS /usr/include /usr/local/include)
- if (NOT ${GCRYPT_INCLUDE_DIR} STREQUAL "GRYPT_INCLUDE_DIR-NOTFOUND")
- file(STRINGS ${GCRYPT_INCLUDE_DIR}/gcrypt.h GCSTR
+ find_path(LIBGCRYPT_INCLUDE_DIR gcrypt.h HINTS /usr/include /usr/local/include)
+ if (NOT LIBGCRYPT_INCLUDE_DIR STREQUAL "GRYPT_INCLUDE_DIR-NOTFOUND")
+ 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}\")")
if (NOT GCVER VERSION_LESS "1.7.0")
- include_directories(${GCRYPT_INCLUDE_DIR})
set(HAVE_LIBGCRYPT "1" CACHE STRING "Have libgcrypt")
endif()
endif ()
else ()
- set(LIBGCRYPT_LIBRARIES "")
+ set(LIBGCRYPT_LIBRARIES "")
+ set(LIBGCRYPT_INCLUDE_DIR "")
endif ()
find_package(OpenSSL)
if (OPENSSL_FOUND)
- include_directories(${OPENSSL_INCLUDE_DIR})
set(HAVE_OPENSSL "1" CACHE STRING "Have OpenSSL")
+else ()
+ set (OPENSSL_INCLUDE_DIR "")
endif ()
-find_path(LINUX_RND_HDR sys/random.h HINTS /usr/include/ /usr/local/include/)
-if (NOT ${LINUX_RND_HDR} STREQUAL "LINUX_RND_HDR-NOTFOUND")
- message(STATUS "Found sys/random.h in ${LINUX_RND_HDR}")
- include_directories(${LINUX_RND_HDR})
- set(HAVE_SYS_RANDOM "1" CACHE STRING "Have Random Header")
-endif ()
+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")
+ message(STATUS "Found sys/random.h in ${SYS_RND_HDR}")
+ set(HAVE_SYS_RANDOM "1" CACHE STRING "Have random header")
+ else ()
+ set(SYS_RND_HDR "")
+ endif ()
+endif()
-if (NOT ((CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") OR
+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"
@@ -117,6 +123,7 @@ target_link_libraries(ouroboros ${LIBRT_LIBRARIES}
install(TARGETS ouroboros LIBRARY DESTINATION usr/lib)
-target_include_directories(ouroboros PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
+target_include_directories(ouroboros PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
+ ${SYS_RND_HDR} ${LIBGCRYPT_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
add_subdirectory(tests)
diff --git a/src/lib/bitmap.c b/src/lib/bitmap.c
index ec663ec7..ce1a3ee9 100644
--- a/src/lib/bitmap.c
+++ b/src/lib/bitmap.c
@@ -22,6 +22,7 @@
*/
#include <ouroboros/bitmap.h>
+
#include <assert.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/lib/hashtable.c b/src/lib/hashtable.c
index 77b56075..2b49ecba 100644
--- a/src/lib/hashtable.c
+++ b/src/lib/hashtable.c
@@ -21,7 +21,6 @@
* 02110-1301 USA
*/
-#include <ouroboros/config.h>
#include <ouroboros/hashtable.h>
#include <ouroboros/list.h>
#include <ouroboros/errno.h>
diff --git a/src/lib/random.c b/src/lib/random.c
index 17973695..4ce378cd 100644
--- a/src/lib/random.c
+++ b/src/lib/random.c
@@ -24,10 +24,20 @@
#include <ouroboros/config.h>
#include <ouroboros/random.h>
-#if defined(HAVE_SYS_RANDOM)
+#if defined(__APPLE__) /* Barf */
+#undef __OSX_AVAILABLE
+#define __OSX_AVAILABLE(arg)
+#undef __IOS_AVAILABLE
+#define __IOS_AVAILABLE(arg)
+#undef __TVOS_AVAILABLE
+#define __TVOS_AVAILABLE(arg)
+#undef __WATCHOS_AVAILABLE
+#define __WATCHOS_AVAILABLE(arg)
+#include <sys/random.h>
+#elif defined(HAVE_SYS_RANDOM)
#include <sys/random.h>
#elif defined(HAVE_LIBGCRYPT)
-#include <grypt.h>
+#include <gcrypt.h>
#elif defined(__FreeBSD__)
#include <stdlib.h>
#elif defined(HAVE_OPENSSL)
@@ -43,10 +53,13 @@ int random_buffer(void * buf,
#elif defined(HAVE_LIBGCRYPT)
return gcry_randomize(buf, len, GCRY_STRONG_RANDOM);
#elif defined(__FreeBSD__)
- return arc4random_buf(buf, len);
+ arc4random_buf(buf, len);
+ return 0;
#elif defined(HAVE_OPENSSL)
if (len > 0 && len < INT_MAX)
return RAND_bytes((unsigned char *) buf, (int) len);
return -1;
+#elif defined(__APPLE__)
+ return getentropy(buf, len);
#endif
}
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c
index d454fef8..59f32056 100644
--- a/src/lib/shm_rdrbuff.c
+++ b/src/lib/shm_rdrbuff.c
@@ -123,11 +123,11 @@ static char * rdrb_filename(void)
{
char * str;
- str = malloc(strlen(SHM_RDRB_PREFIX) + 1);
+ str = malloc(strlen(SHM_RDRB_NAME) + 1);
if (str == NULL)
return NULL;
- sprintf(str, "%s", SHM_RDRB_PREFIX);
+ sprintf(str, "%s", SHM_RDRB_NAME);
return str;
}
diff --git a/src/lib/tests/CMakeLists.txt b/src/lib/tests/CMakeLists.txt
index 46a3e91f..41c2074a 100644
--- a/src/lib/tests/CMakeLists.txt
+++ b/src/lib/tests/CMakeLists.txt
@@ -14,6 +14,7 @@ create_test_sourcelist(${PARENT_DIR}_tests test_suite.c
)
add_executable(${PARENT_DIR}_test EXCLUDE_FROM_ALL ${${PARENT_DIR}_tests})
+
target_link_libraries(${PARENT_DIR}_test ouroboros)
add_dependencies(check ${PARENT_DIR}_test)
diff --git a/src/lib/tests/time_utils_test.c b/src/lib/tests/time_utils_test.c
index 86636c15..2878132b 100644
--- a/src/lib/tests/time_utils_test.c
+++ b/src/lib/tests/time_utils_test.c
@@ -33,7 +33,7 @@ static void ts_print(struct timespec * s)
static void tv_print(struct timeval * v)
{
- printf("timeval is %zd:%ld.\n", (ssize_t) v->tv_sec, v->tv_usec);
+ printf("timeval is %zd:%zu.\n", (ssize_t) v->tv_sec, (size_t) v->tv_usec);
}
static void ts_init(struct timespec * s,
diff --git a/src/lib/time_utils.c b/src/lib/time_utils.c
index 07994af2..c644c889 100644
--- a/src/lib/time_utils.c
+++ b/src/lib/time_utils.c
@@ -142,16 +142,3 @@ int ts_to_tv(const struct timespec * src,
return 0;
}
-
-#ifdef __APPLE__
-int clock_gettime(int clock,
- struct timespec * t)
-{
- struct timeval tv;
- int ret = gettimeofday(&tv, NULL);
- t->tv_sec = tv.tv_sec;
- t->tv_nsec = tv.tv_usec * 1000;
- (void) clock;
- return ret;
-}
-#endif