summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--accel-pppd/CMakeLists.txt3
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c8
-rw-r--r--accel-pppd/ctrl/pppoe/pppoe.c3
-rw-r--r--accel-pppd/ctrl/pptp/pptp.c3
-rw-r--r--accel-pppd/fdtrash.c31
-rw-r--r--accel-pppd/include/fdtrash.h6
-rw-r--r--accel-pppd/ppp/ppp.c7
7 files changed, 51 insertions, 10 deletions
diff --git a/accel-pppd/CMakeLists.txt b/accel-pppd/CMakeLists.txt
index 0702e5e4..dc4b557c 100644
--- a/accel-pppd/CMakeLists.txt
+++ b/accel-pppd/CMakeLists.txt
@@ -66,9 +66,8 @@ ADD_EXECUTABLE(accel-pppd
pwdb.c
ipdb.c
-
+ fdtrash.c
iprange.c
-
utils.c
log.c
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c
index d8a98f8d..c629bb35 100644
--- a/accel-pppd/ctrl/l2tp/l2tp.c
+++ b/accel-pppd/ctrl/l2tp/l2tp.c
@@ -26,6 +26,7 @@
#include "crypto.h"
#include "connlimit.h"
+#include "fdtrash.h"
#include "memdebug.h"
@@ -116,7 +117,6 @@ static void l2tp_disconnect(struct l2tp_conn_t *conn)
struct l2tp_packet_t *pack;
triton_md_unregister_handler(&conn->hnd);
- close(conn->hnd.fd);
if (conn->timeout_timer.tpd)
triton_timer_del(&conn->timeout_timer);
@@ -139,10 +139,12 @@ static void l2tp_disconnect(struct l2tp_conn_t *conn)
pthread_mutex_unlock(&l2tp_lock);
if (conn->ppp.fd != -1)
- close(conn->ppp.fd);
+ fdtrash_add(conn->ppp.fd);
if (conn->tunnel_fd != -1)
- close(conn->tunnel_fd);
+ fdtrash_add(conn->tunnel_fd);
+
+ fdtrash_add(conn->hnd.fd);
triton_event_fire(EV_CTRL_FINISHED, &conn->ppp);
diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c
index 73ddb913..ddd61e79 100644
--- a/accel-pppd/ctrl/pppoe/pppoe.c
+++ b/accel-pppd/ctrl/pppoe/pppoe.c
@@ -27,6 +27,7 @@
#endif
#include "connlimit.h"
+#include "fdtrash.h"
#include "pppoe.h"
@@ -117,7 +118,7 @@ static void disconnect(struct pppoe_conn_t *conn)
pppoe_send_PADT(conn);
- close(conn->disc_sock);
+ fdtrash_add(conn->disc_sock);
triton_event_fire(EV_CTRL_FINISHED, &conn->ppp);
diff --git a/accel-pppd/ctrl/pptp/pptp.c b/accel-pppd/ctrl/pptp/pptp.c
index 2f0c5efd..9cbb51fe 100644
--- a/accel-pppd/ctrl/pptp/pptp.c
+++ b/accel-pppd/ctrl/pptp/pptp.c
@@ -22,6 +22,7 @@
#include "iprange.h"
#include "utils.h"
#include "cli.h"
+#include "fdtrash.h"
#include "connlimit.h"
@@ -76,7 +77,7 @@ static void disconnect(struct pptp_conn_t *conn)
log_ppp_debug("pptp: disconnect\n");
triton_md_unregister_handler(&conn->hnd);
- close(conn->hnd.fd);
+ fdtrash_add(conn->hnd.fd);
if (conn->timeout_timer.tpd)
triton_timer_del(&conn->timeout_timer);
diff --git a/accel-pppd/fdtrash.c b/accel-pppd/fdtrash.c
new file mode 100644
index 00000000..c43de8d5
--- /dev/null
+++ b/accel-pppd/fdtrash.c
@@ -0,0 +1,31 @@
+#include <unistd.h>
+
+#include "triton.h"
+#include "fdtrash.h"
+
+static void fdtrash_close(struct triton_context_t *ctx)
+{
+ triton_context_unregister(ctx);
+}
+
+struct triton_context_t ctx = {
+ .close = fdtrash_close,
+};
+
+static void __close(void *arg)
+{
+ close((long)arg);
+}
+
+void __export fdtrash_add(long fd)
+{
+ triton_context_call(&ctx, (triton_event_func)__close, (void *)fd);
+}
+
+static void init()
+{
+ triton_context_register(&ctx, NULL);
+ triton_context_wakeup(&ctx);
+}
+
+DEFINE_INIT(10, init);
diff --git a/accel-pppd/include/fdtrash.h b/accel-pppd/include/fdtrash.h
new file mode 100644
index 00000000..4144573d
--- /dev/null
+++ b/accel-pppd/include/fdtrash.h
@@ -0,0 +1,6 @@
+#ifndef __FDTRASH__H_
+#define __FDTRASH__H_
+
+void fdtrash_add(long fd);
+
+#endif
diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c
index 4f3beb9e..ef8aa36c 100644
--- a/accel-pppd/ppp/ppp.c
+++ b/accel-pppd/ppp/ppp.c
@@ -19,6 +19,7 @@
#include "ppp.h"
#include "ppp_fsm.h"
#include "log.h"
+#include "fdtrash.h"
#include "spinlock.h"
#include "mempool.h"
@@ -223,9 +224,9 @@ static void destablish_ppp(struct ppp_t *ppp)
triton_md_unregister_handler(&ppp->chan_hnd);
triton_md_unregister_handler(&ppp->unit_hnd);
- close(ppp->unit_fd);
- close(ppp->chan_fd);
- close(ppp->fd);
+ fdtrash_add(ppp->unit_fd);
+ fdtrash_add(ppp->chan_fd);
+ fdtrash_add(ppp->fd);
ppp->unit_fd = -1;
ppp->chan_fd = -1;