diff --git a/diod/diod.c b/diod/diod.c index c7218701..ceb49f1a 100644 --- a/diod/diod.c +++ b/diod/diod.c @@ -676,6 +676,7 @@ _service_run (srvmode_t mode, int rfdno, int wfdno) errn_exit (n, "pthread_join _service_loop_rdma"); #endif + np_srv_shutdown(ss.srv); diod_fini (ss.srv); np_srv_destroy (ss.srv); } diff --git a/libnpfs/npfs.h b/libnpfs/npfs.h index 88859991..8a399866 100644 --- a/libnpfs/npfs.h +++ b/libnpfs/npfs.h @@ -342,6 +342,7 @@ struct Npuser { /* srv.c */ Npsrv *np_srv_create(int nwthread, int flags); void np_srv_destroy(Npsrv *srv); +void np_srv_shutdown(Npsrv *srv); void np_srv_remove_conn_pre(Npsrv *, Npconn *); void np_srv_remove_conn_post(Npsrv *); int np_srv_add_conn(Npsrv *, Npconn *); diff --git a/libnpfs/srv.c b/libnpfs/srv.c index 0bd12b45..41ee2f97 100644 --- a/libnpfs/srv.c +++ b/libnpfs/srv.c @@ -78,6 +78,23 @@ np_srv_create(int nwthread, int flags) return NULL; } +/* Shut down all connection */ +void +np_srv_shutdown(Npsrv *srv) +{ + Npconn *cc; + + /* Shut down all connections */ + xpthread_mutex_lock(&srv->lock); + for (cc = srv->conns; cc != NULL; cc = cc->next) + pthread_cancel(cc->rthread); + + /* Wait for all connections to shutdown... */ + while (srv->conncount > 0) + xpthread_cond_wait(&srv->conncountcond, &srv->lock); + xpthread_mutex_unlock(&srv->lock); +} + void np_srv_destroy(Npsrv *srv) {