From bedd1d4eadde9ab64f924c69eba716b015599e67 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 12 Oct 2017 02:15:39 +0200 Subject: 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. --- src/lib/dev.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/lib/dev.c') 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; -- cgit v1.2.3