If the "FUSE_THREAD_STACK" environment is set, initialize the stack size of threads...
authorMiklos Szeredi <miklos@szeredi.hu>
Fri, 8 Feb 2008 18:35:04 +0000 (18:35 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Fri, 8 Feb 2008 18:35:04 +0000 (18:35 +0000)
ChangeLog
lib/fuse_loop_mt.c

index 0e6d2e3ef8d13c20fa294daf23aac2680e9b4ab9..435eadadac3ab66313ac458ae850ab2755668e9b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,9 @@
 
        * Support the st_blksize field in struct stat
 
+       * If the "FUSE_THREAD_STACK" environment is set, initialize the
+       stack size of threads by this value.  Patch by Florin Malita
+
 2008-02-03  Csaba Henk <csaba.henk@creo.hu>
 
        * lib/mount_bsd.c:
index dba8dbc6f305f9e87fac5d3a5a2421e8b96f1ce9..c458d1e4f95d1e753626fa5fe499f0d1203ebe08 100644 (file)
@@ -19,6 +19,9 @@
 #include <errno.h>
 #include <sys/time.h>
 
+/* Environment var controlling the thread stack size */
+#define ENVNAME_THREAD_STACK "FUSE_THREAD_STACK"
+
 struct fuse_worker {
        struct fuse_worker *prev;
        struct fuse_worker *next;
@@ -131,6 +134,8 @@ static int fuse_start_thread(struct fuse_mt *mt)
        sigset_t oldset;
        sigset_t newset;
        int res;
+       pthread_attr_t attr;
+       char *stack_size;
        struct fuse_worker *w = malloc(sizeof(struct fuse_worker));
        if (!w) {
                fprintf(stderr, "fuse: failed to allocate worker structure\n");
@@ -146,6 +151,12 @@ static int fuse_start_thread(struct fuse_mt *mt)
                return -1;
        }
 
+       /* Override default stack size */
+       pthread_attr_init(&attr);
+       stack_size = getenv(ENVNAME_THREAD_STACK);
+       if (stack_size && pthread_attr_setstacksize(&attr, atoi(stack_size)))
+               fprintf(stderr, "fuse: invalid stack size: %s\n", stack_size);
+
        /* Disallow signal reception in worker threads */
        sigemptyset(&newset);
        sigaddset(&newset, SIGTERM);
@@ -153,8 +164,9 @@ static int fuse_start_thread(struct fuse_mt *mt)
        sigaddset(&newset, SIGHUP);
        sigaddset(&newset, SIGQUIT);
        pthread_sigmask(SIG_BLOCK, &newset, &oldset);
-       res = pthread_create(&w->thread_id, NULL, fuse_do_work, w);
+       res = pthread_create(&w->thread_id, &attr, fuse_do_work, w);
        pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+       pthread_attr_destroy(&attr);
        if (res != 0) {
                fprintf(stderr, "fuse: error creating thread: %s\n",
                        strerror(res));