aboutsummaryrefslogtreecommitdiff
path: root/lib/fuse_loop_mt.c
diff options
context:
space:
mode:
authorGravatar Miklos Szeredi <miklos@szeredi.hu>2008-02-08 18:35:04 +0000
committerGravatar Miklos Szeredi <miklos@szeredi.hu>2008-02-08 18:35:04 +0000
commit24b009347e8029e16e0b4da56df5a7c28c766920 (patch)
treee938199999ba69ec19ccc1f5d6fe41527f98a983 /lib/fuse_loop_mt.c
parent29e4293327d9365793a0f81cf14198e23ed363a7 (diff)
If the "FUSE_THREAD_STACK" environment is set, initialize the stack size of threads by this value
Diffstat (limited to 'lib/fuse_loop_mt.c')
-rw-r--r--lib/fuse_loop_mt.c14
1 files changed, 13 insertions, 1 deletions
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 <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));