From: Miklos Szeredi <miklos@szeredi.hu>
Date: Tue, 29 Nov 2005 20:07:23 +0000 (+0000)
Subject: fix
X-Git-Tag: fuse_2_5_0_pre1~5
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=40d7b38b29cb251e84b3619b8040ac248d944e84;p=qemu-gpiodev%2Flibfuse.git

fix
---

diff --git a/ChangeLog b/ChangeLog
index 50bd2db..ca86052 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,10 @@
 	* Check if '-msoft-float' option is supported by compiler when
 	configuring for a 2.4.x kernel.  Bug report by Mark Haney
 
+	* In multithreaded loop send a TERM signal to the main thread if
+	one of the other threads exit.  Needed on FreeBSD for a clean exit
+	on umount.  Should not cause any harm on Linux either
+
 2005-11-28  Miklos Szeredi <miklos@szeredi.hu>
 
 	* Fix bug in 32-bit file handle compatibility
diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c
index 0532230..37f0922 100644
--- a/lib/fuse_loop_mt.c
+++ b/lib/fuse_loop_mt.c
@@ -27,6 +27,7 @@ struct fuse_worker {
     struct fuse_chan *ch;
     struct fuse_chan *prevch;
     pthread_t threads[FUSE_MAX_WORKERS];
+    pthread_t main_thread;
     int exit;
     int error;
 };
@@ -59,7 +60,6 @@ static int start_thread(struct fuse_worker *w, pthread_t *thread_id);
 static void *do_work(void *data)
 {
     struct fuse_worker *w = (struct fuse_worker *) data;
-    int is_mainthread = (w->numworker == 1);
     size_t bufsize = fuse_chan_bufsize(w->prevch);
     char *buf = (char *) malloc(bufsize);
     if (!buf) {
@@ -107,9 +107,10 @@ static void *do_work(void *data)
     }
     pthread_cleanup_pop(1);
 
-    /* Wait for cancellation */
-    if (!is_mainthread)
+    if (pthread_self() != w->main_thread) {
+        pthread_kill(w->main_thread, SIGTERM);
         pause();
+    }
 
     return NULL;
 }
@@ -162,6 +163,7 @@ int fuse_session_loop_mt(struct fuse_session *se)
     w->error = 0;
     w->numworker = 1;
     w->numavail = 1;
+    w->main_thread = pthread_self();
     mutex_init(&w->lock);
 
     do_work(w);