This allows persisted tun device to be cleaned up for reuse.
This is the minimal change to reach the goal using atexit(),
not sure it is the best way.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
---
vpnc.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/vpnc.c b/vpnc.c
index 6ab10eb..f72d8ec 100644
--- a/vpnc.c
+++ b/vpnc.c
@@ -482,11 +482,23 @@ static void setup_tunnel(struct sa_block *s)
}
}
+static struct sa_block *s_atexit_sa;
+static void close_tunnel(struct sa_block *s);
+static void atexit_close(void)
+{
+ if (s_atexit_sa != NULL) {
+ close_tunnel(s_atexit_sa);
+ s_atexit_sa = NULL;
+ }
+}
+
static void config_tunnel(struct sa_block *s)
{
setenv("VPNGATEWAY", inet_ntoa(s->dst), 1);
setenv("reason", "connect", 1);
system(config[CONFIG_SCRIPT]);
+ s_atexit_sa = s;
+ atexit(atexit_close);
}
static void close_tunnel(struct sa_block *s)
--
1.7.8.6
_______________________________________________
vpnc-devel mailing list
vpnc-devel@unix-ag.uni-kl.de
https://lists.unix-ag.uni-kl.de/mailman/listinfo/vpnc-devel
http://www.unix-ag.uni-kl.de/~massar/vpnc/
This is the minimal change to reach the goal using atexit(),
not sure it is the best way.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
---
vpnc.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/vpnc.c b/vpnc.c
index 6ab10eb..f72d8ec 100644
--- a/vpnc.c
+++ b/vpnc.c
@@ -482,11 +482,23 @@ static void setup_tunnel(struct sa_block *s)
}
}
+static struct sa_block *s_atexit_sa;
+static void close_tunnel(struct sa_block *s);
+static void atexit_close(void)
+{
+ if (s_atexit_sa != NULL) {
+ close_tunnel(s_atexit_sa);
+ s_atexit_sa = NULL;
+ }
+}
+
static void config_tunnel(struct sa_block *s)
{
setenv("VPNGATEWAY", inet_ntoa(s->dst), 1);
setenv("reason", "connect", 1);
system(config[CONFIG_SCRIPT]);
+ s_atexit_sa = s;
+ atexit(atexit_close);
}
static void close_tunnel(struct sa_block *s)
--
1.7.8.6
_______________________________________________
vpnc-devel mailing list
vpnc-devel@unix-ag.uni-kl.de
https://lists.unix-ag.uni-kl.de/mailman/listinfo/vpnc-devel
http://www.unix-ag.uni-kl.de/~massar/vpnc/