Initialize TKM client library in tkm.c

This commit is contained in:
Reto Buerki
2013-03-19 15:23:45 +01:00
committed by Tobias Brunner
parent 559fe48c50
commit 3d2746309e
3 changed files with 37 additions and 6 deletions
+8 -4
View 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;
}
+21
View File
@@ -14,8 +14,13 @@
* 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;
}
+8 -2
View File
@@ -14,12 +14,17 @@
* 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;