From 0b3e64e4b056cf6b17c4bdc45100c11bcc116e8d Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Thu, 15 May 2014 15:12:41 +0400 Subject: triton: close file descriptors immediately in triton_unregister_handler --- accel-pppd/triton/md.c | 23 +++++++---------------- accel-pppd/triton/triton_p.h | 1 - 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/accel-pppd/triton/md.c b/accel-pppd/triton/md.c index a7eb5c8..600b968 100644 --- a/accel-pppd/triton/md.c +++ b/accel-pppd/triton/md.c @@ -96,23 +96,16 @@ static void *md_thread(void *arg) if (r) triton_thread_wakeup(h->ctx->thread); } - - pthread_mutex_lock(&freed_list_lock); - while (!list_empty(&freed_list)) { - h = list_entry(freed_list.next, typeof(*h), entry); - list_move(&h->entry, &freed_list2); - } - pthread_mutex_unlock(&freed_list_lock); while (!list_empty(&freed_list2)) { h = list_entry(freed_list2.next, typeof(*h), entry); list_del(&h->entry); - if (h->fd != -1) { - r = epoll_ctl(epoll_fd, EPOLL_CTL_DEL, h->fd, NULL); - close(h->fd); - } mempool_free(h); } + + pthread_mutex_lock(&freed_list_lock); + list_splice_init(&freed_list, &freed_list2); + pthread_mutex_unlock(&freed_list_lock); } return NULL; @@ -139,14 +132,12 @@ void __export triton_md_register_handler(struct triton_context_t *ctx, struct tr void __export triton_md_unregister_handler(struct triton_md_handler_t *ud, int c) { struct _triton_md_handler_t *h = (struct _triton_md_handler_t *)ud->tpd; + triton_md_disable_handler(ud, MD_MODE_READ | MD_MODE_WRITE); - + if (c) { - h->fd = ud->fd; + close(ud->fd); ud->fd = -1; - } else { - triton_md_disable_handler(ud, MD_MODE_READ | MD_MODE_WRITE); - h->fd = -1; } spin_lock(&h->ctx->lock); diff --git a/accel-pppd/triton/triton_p.h b/accel-pppd/triton/triton_p.h index d86f1bc..443cede 100644 --- a/accel-pppd/triton/triton_p.h +++ b/accel-pppd/triton/triton_p.h @@ -53,7 +53,6 @@ struct _triton_md_handler_t struct _triton_context_t *ctx; struct epoll_event epoll_event; uint32_t trig_epoll_events; - int fd; int pending:1; int trig_level:1; struct triton_md_handler_t *ud; -- cgit v1.2.3