From 7ef762c6ac85e3eb7c21c41cd752ba130279f232 Mon Sep 17 00:00:00 2001 From: Saverio Proto Date: Sat, 5 Apr 2014 12:45:35 +0200 Subject: [PATCH] tinc_start() - skeleton of the API call. The function starts the main tinc thread where the tinc logic will be. We pass the confbase because an application may participate in multiple VPNs at the same time (to be discussed further) --- meshlink-sample/meshlinkapp.c | 3 ++- src/Makefile.am | 2 ++ src/libmeshlink.c | 15 ++++++++++++++- src/libmeshlink.h | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/meshlink-sample/meshlinkapp.c b/meshlink-sample/meshlinkapp.c index 847fad01..3be65352 100644 --- a/meshlink-sample/meshlinkapp.c +++ b/meshlink-sample/meshlinkapp.c @@ -6,7 +6,8 @@ char *confbase = "/tmp/meshlink/"; char *name = "test"; tinc_setup(confbase, name); - +tinc_start(confbase); +sleep(10); //give time to this thread to finish before we exit return 0; } diff --git a/src/Makefile.am b/src/Makefile.am index ad60f454..a2823017 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -167,6 +167,8 @@ libmeshlink_la_SOURCES = \ libmeshlink_la_CFLAGS = -fPIC +libmeshlink_la_LIBADD = -lpthread + ## Conditionally compile device drivers if LINUX diff --git a/src/libmeshlink.c b/src/libmeshlink.c index b4daff3d..5cf366c5 100644 --- a/src/libmeshlink.c +++ b/src/libmeshlink.c @@ -388,7 +388,20 @@ bool tinc_setup(const char* confbaseapi, const char* name) { } -bool tinc_start(const char* path); +bool tinc_start(const char* confbaseapi) { + pthread_t tincThread; + confbase = confbaseapi; + pthread_create(&tincThread,NULL,tinc_main_thread,confbaseapi); + pthread_detach(tincThread); +return true; +} + +bool tinc_main_thread(void * in) { + +confbase = (char*) in; +printf("Hello World %s\n",confbase); + +} bool tinc_stop(); diff --git a/src/libmeshlink.h b/src/libmeshlink.h index 7f64320f..c5e84462 100644 --- a/src/libmeshlink.h +++ b/src/libmeshlink.h @@ -27,6 +27,9 @@ extern char *hosts_dir; extern FILE *fopenmask(const char *filename, const char *mode, mode_t perms); extern int check_port(char *name); + +bool tinc_main_thread(void * in); + /* OLD: tinc_configuration_t provides all information required to setup "/etc/tinc" I think tinc_setup() should basically do what cmd_init() from src/tincctl.c does, except it doesn't have to generate a tinc-up script. */ -- 2.39.5