Initialize TKM client library in tkm.c
authorReto Buerki <reet@codelabs.ch>
Thu, 7 Jun 2012 15:45:34 +0000 (17:45 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 19 Mar 2013 14:23:45 +0000 (15:23 +0100)
src/charon-tkm/src/charon-tkm.c
src/charon-tkm/src/tkm/tkm.c
src/charon-tkm/tests/test_runner.c

index 8731d78..3e52fa4 100644 (file)
@@ -32,7 +32,7 @@
 #include <utils/backtrace.h>
 #include <threading/thread.h>
 
-#include <tkm/client.h>
+#include "tkm.h"
 
 /**
  * PID file, in which charon-tkm stores its process id
@@ -294,8 +294,12 @@ int main(int argc, char *argv[])
                goto deinit;
        }
 
-       /* initialize TKM client lib */
-       tkmlib_init();
+       /* initialize TKM client */
+       if (!tkm_init())
+       {
+               DBG1(DBG_DMN, "init of TKM client failed - aborting %s", dmn_name);
+               goto deinit;
+       }
 
        /* add handler for SEGV and ILL,
         * INT and TERM are handled by sigwait() in run() */
@@ -320,11 +324,11 @@ int main(int argc, char *argv[])
 
        unlink_pidfile();
        status = 0;
-       tkmlib_final();
 
 deinit:
        libcharon_deinit();
        libhydra_deinit();
        library_deinit();
+       tkm_deinit();
        return status;
 }
index 1e61f88..ebff089 100644 (file)
  * for more details.
  */
 
+#include <tkm/client.h>
+#include <tkm/constants.h>
+
 #include "tkm.h"
 
+#define IKE_SOCKET "/tmp/tkm.rpc.ike"
+
 typedef struct private_tkm_t private_tkm_t;
 
 /**
@@ -41,6 +46,20 @@ bool tkm_init()
 {
        private_tkm_t *this;
 
+       /* initialize TKM client library */
+       tkmlib_init();
+       if (ike_init(IKE_SOCKET) != TKM_OK)
+       {
+               tkmlib_final();
+               return FALSE;
+       }
+
+       if (ike_tkm_reset() != TKM_OK)
+       {
+               tkmlib_final();
+               return FALSE;
+       }
+
        INIT(this,
                .public = {
                        .idmgr = tkm_id_manager_create(),
@@ -62,6 +81,8 @@ void tkm_deinit()
        }
        private_tkm_t *this = (private_tkm_t*)tkm;
        this->public.idmgr->destroy(this->public.idmgr);
+
+       tkmlib_final();
        free(this);
        tkm = NULL;
 }
index 61c2524..c16ad35 100644 (file)
  * for more details.
  */
 
-#include <stdlib.h>
-
+#include "tkm.h"
 #include "test_runner.h"
 
 int main(void)
 {
+       if (!tkm_init())
+       {
+               fprintf(stderr, "Could not connect to TKM, aborting tests\n");
+               return EXIT_FAILURE;
+       }
+
        int number_failed;
        Suite *s = suite_create("TKM tests");
        suite_add_tcase(s, make_id_manager_tests());
@@ -30,6 +35,7 @@ int main(void)
        srunner_run_all(sr, CK_NORMAL);
        number_failed = srunner_ntests_failed(sr);
 
+       tkm_deinit();
        srunner_free(sr);
 
        return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;