From 24b009347e8029e16e0b4da56df5a7c28c766920 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Fri, 8 Feb 2008 18:35:04 +0000 Subject: [PATCH] If the "FUSE_THREAD_STACK" environment is set, initialize the stack size of threads by this value --- ChangeLog | 3 +++ lib/fuse_loop_mt.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0e6d2e3..435eada 100644 --- 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 * lib/mount_bsd.c: diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c index dba8dbc..c458d1e 100644 --- a/lib/fuse_loop_mt.c +++ b/lib/fuse_loop_mt.c @@ -19,6 +19,9 @@ #include #include +/* 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)); -- 2.30.2