summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-10-12 02:15:39 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-10-14 13:19:10 +0200
commitbedd1d4eadde9ab64f924c69eba716b015599e67 (patch)
treeb521ef89c8752334448bee1582b51dbe97851839 /src/lib
parenta483bc8597e5c19e796dc55c0587f1a045bc7281 (diff)
downloadouroboros-bedd1d4eadde9ab64f924c69eba716b015599e67.tar.gz
ouroboros-bedd1d4eadde9ab64f924c69eba716b015599e67.zip
lib: Deprecate ouroboros_init and ourboros_fini
This commit deprecates ouroboros_init and ouroboros_fini and adds them as a constructor or destructor, causing these function to be run automatically when a program that links to the library calls and exits main(). For this to fully work, the library had to be split so that we can avoid the irmd calling these functions (the IRMd has to create the shm structures on which these calls depend). The library is split in 3 parts: libouroboros-dev, libouroboros-irm and libouroboros-common. The latter is linked to the other two so that including libouroboros-dev or libouroboros-irm will also link libouroboros-common.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/CMakeLists.txt64
-rw-r--r--src/lib/dev.c29
-rw-r--r--src/lib/tests/CMakeLists.txt2
3 files changed, 62 insertions, 33 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 6ab5ebc8..c1b8f354 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -73,7 +73,7 @@ if (LIBGCRYPT_LIBRARIES)
string(REGEX REPLACE "^#define GCRYPT_VERSION \"(.*)\".*$" "\\1"
GCVER "${GCSTR}")
if (NOT GCVER VERSION_LESS "1.7.0")
- set (DISABLE_LIBGCRYPT FALSE CACHE BOOL "Disable libgcrypt support")
+ set(DISABLE_LIBGCRYPT FALSE CACHE BOOL "Disable libgcrypt support")
if (NOT DISABLE_LIBGCRYPT)
message(STATUS "libgcrypt support enabled")
set(HAVE_LIBGCRYPT TRUE CACHE INTERNAL "")
@@ -94,7 +94,7 @@ endif ()
find_package(OpenSSL QUIET)
if (OPENSSL_FOUND)
- set (DISABLE_OPENSSL FALSE CACHE BOOL "Disable OpenSSL support")
+ set(DISABLE_OPENSSL FALSE CACHE BOOL "Disable OpenSSL support")
if (NOT DISABLE_OPENSSL)
message(STATUS "OpenSSL support enabled")
set(HAVE_OPENSSL TRUE)
@@ -104,7 +104,7 @@ if (OPENSSL_FOUND)
endif ()
if (NOT HAVE_OPENSSL)
- set (OPENSSL_INCLUDE_DIR "")
+ set(OPENSSL_INCLUDE_DIR "")
endif ()
if (APPLE OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
@@ -129,12 +129,12 @@ 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")
+math(EXPR SHM_BUFFER_EXPR "1 << 17")
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
+set(SYS_MAX_FLOWS 10240 CACHE STRING
"Maximum number of total flows for this system")
-set(AP_MAX_FLOWS 1024 CACHE STRING
+set(AP_MAX_FLOWS 4096 CACHE STRING
"Maximum number of flows in an application")
set(AP_RES_FDS 64 CACHE STRING
"Number of reserved flow descriptors per application")
@@ -148,7 +148,7 @@ 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
+ set(PTHREAD_COND_CLOCK "CLOCK_REALTIME" CACHE INTERNAL
"Clock to use for condition variable timing")
endif ()
set(SOCKET_TIMEOUT 1000 CACHE STRING
@@ -168,17 +168,24 @@ set(SHM_RDRB_BLOCK_SIZE "sysconf(_SC_PAGESIZE)" CACHE STRING
set(SHM_RBUFF_LOCKLESS 0 CACHE BOOL
"Enable shared memory lockless rbuff support")
-set(SOURCE_FILES
+set(SOURCE_FILES_DEV
# Add source files here
- bitmap.c
- btree.c
cacep.c
- crc32.c
dev.c
frct_pci.c
+ timerwheel.c
+ )
+
+set(SOURCE_FILES_IRM
+ irm.c
+)
+
+set(SOURCE_FILES_COMMON
+ bitmap.c
+ btree.c
+ crc32.c
hash.c
hashtable.c
- irm.c
list.c
lockfile.c
logs.c
@@ -195,29 +202,48 @@ set(SOURCE_FILES
shm_rdrbuff.c
sockets.c
time_utils.c
- timerwheel.c
tpm.c
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}
+add_library(ouroboros-common SHARED ${SOURCE_FILES_COMMON} ${IRM_PROTO_SRCS}
+ ${IPCP_PROTO_SRCS} ${DIF_CONFIG_PROTO_SRCS})
+
+add_library(ouroboros-dev SHARED ${SOURCE_FILES_DEV} ${IRM_PROTO_SRCS}
${IPCP_PROTO_SRCS} ${DIF_CONFIG_PROTO_SRCS} ${CACEP_PROTO_SRCS})
+add_library(ouroboros-irm SHARED ${SOURCE_FILES_IRM} ${IRM_PROTO_SRCS}
+ ${IPCP_PROTO_SRCS} ${DIF_CONFIG_PROTO_SRCS})
+
include(AddCompileFlags)
if (CMAKE_BUILD_TYPE MATCHES Debug)
- add_compile_flags(ouroboros -DCONFIG_OUROBOROS_DEBUG)
+ add_compile_flags(ouroboros-common -DCONFIG_OUROBOROS_DEBUG)
+ add_compile_flags(ouroboros-dev -DCONFIG_OUROBOROS_DEBUG)
+ add_compile_flags(ouroboros-irm -DCONFIG_OUROBOROS_DEBUG)
endif (CMAKE_BUILD_TYPE MATCHES Debug)
-target_link_libraries(ouroboros ${LIBRT_LIBRARIES}
+target_link_libraries(ouroboros-common ${LIBRT_LIBRARIES}
${LIBPTHREAD_LIBRARIES} ${PROTOBUF_C_LIBRARY} ${OPENSSL_LIBRARIES}
${LIBGCRYPT_LIBRARIES} ${FUSE_LIBRARIES})
-install(TARGETS ouroboros LIBRARY DESTINATION usr/lib)
+target_link_libraries(ouroboros-dev ouroboros-common)
+
+target_link_libraries(ouroboros-irm ouroboros-common)
+
+install(TARGETS ouroboros-common LIBRARY DESTINATION usr/lib)
+install(TARGETS ouroboros-dev LIBRARY DESTINATION usr/lib)
+install(TARGETS ouroboros-irm LIBRARY DESTINATION usr/lib)
+
+target_include_directories(ouroboros-common PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
+ ${SYS_RND_HDR} ${LIBGCRYPT_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
+
+target_include_directories(ouroboros-dev PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
+ ${SYS_RND_HDR} ${LIBGCRYPT_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
-target_include_directories(ouroboros PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
+target_include_directories(ouroboros-irm PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
${SYS_RND_HDR} ${LIBGCRYPT_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
add_subdirectory(tests)
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 9cb6f2ed..99d3ecec 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -595,11 +595,16 @@ static int flow_init(int port_id,
return fd;
}
-int ouroboros_init(const char * ap_name)
+__attribute__((constructor)) static void init(int argc,
+ char ** argv,
+ char ** envp)
{
- int i;
- int j;
- int ret = -ENOMEM;
+ const char * ap_name = argv[0];
+ int i;
+ int j;
+
+ (void) argc;
+ (void) envp;
assert(ai.ap_name == NULL);
@@ -618,10 +623,8 @@ int ouroboros_init(const char * ap_name)
goto fail_fqset;
ai.rdrb = shm_rdrbuff_open();
- if (ai.rdrb == NULL) {
- ret = -EIRMD;
+ if (ai.rdrb == NULL)
goto fail_rdrb;
- }
ai.flows = malloc(sizeof(*ai.flows) * AP_MAX_FLOWS);
if (ai.flows == NULL)
@@ -651,10 +654,8 @@ int ouroboros_init(const char * ap_name)
if (ai.ap_name == NULL)
goto fail_ap_name;
- if (api_announce((char *) ai.ap_name)) {
- ret = -EIRMD;
+ if (api_announce((char *) ai.ap_name))
goto fail_announce;
- }
}
for (i = 0; i < SYS_MAX_FLOWS; ++i) {
@@ -680,7 +681,7 @@ int ouroboros_init(const char * ap_name)
if (ai.tw == NULL)
goto fail_timerwheel;
- return 0;
+ return;
fail_timerwheel:
pthread_rwlock_destroy(&ai.lock);
@@ -710,10 +711,12 @@ int ouroboros_init(const char * ap_name)
fail_fqueues:
bmp_destroy(ai.fds);
fail_fds:
- return ret;
+ fprintf(stderr, "FATAL: ouroboros-dev init failed. "
+ "Make sure an IRMd is running.\n\n");
+ exit(EXIT_FAILURE);
}
-void ouroboros_fini()
+__attribute__((destructor)) static void fini(void)
{
int i = 0;
diff --git a/src/lib/tests/CMakeLists.txt b/src/lib/tests/CMakeLists.txt
index 0edd4a42..a9ff207e 100644
--- a/src/lib/tests/CMakeLists.txt
+++ b/src/lib/tests/CMakeLists.txt
@@ -22,7 +22,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)
+target_link_libraries(${PARENT_DIR}_test ouroboros-common)
add_dependencies(check ${PARENT_DIR}_test)