diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fuse.c | 4 | ||||
-rw-r--r-- | lib/fuse_i.h | 1 | ||||
-rw-r--r-- | lib/fuse_mt.c | 25 |
3 files changed, 30 insertions, 0 deletions
@@ -781,6 +781,7 @@ void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd) struct fuse_in_header *in = (struct fuse_in_header *) cmd->buf; void *inarg = cmd->buf + sizeof(struct fuse_in_header); size_t argsize; + struct fuse_context *ctx = fuse_get_context(f); dec_avail(f); @@ -789,6 +790,9 @@ void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd) in->opcode, in->ino, cmd->buflen); fflush(stdout); } + + ctx->uid = in->uid; + ctx->gid = in->gid; argsize = cmd->buflen - sizeof(struct fuse_in_header); diff --git a/lib/fuse_i.h b/lib/fuse_i.h index 604c297..d587af1 100644 --- a/lib/fuse_i.h +++ b/lib/fuse_i.h @@ -37,6 +37,7 @@ struct fuse { int numavail; struct fuse_context *(*getcontext)(struct fuse *); struct fuse_context context; + pthread_key_t context_key; }; struct fuse_dirhandle { diff --git a/lib/fuse_mt.c b/lib/fuse_mt.c index 4534d0f..b8756ac 100644 --- a/lib/fuse_mt.c +++ b/lib/fuse_mt.c @@ -69,9 +69,28 @@ static void start_thread(struct fuse_worker *w) pthread_detach(thrid); } +static struct fuse_context *mt_getcontext(struct fuse *f) +{ + struct fuse_context *ctx; + + ctx = (struct fuse_context *) pthread_getspecific(f->context_key); + if(ctx == NULL) { + ctx = (struct fuse_context *) malloc(sizeof(struct fuse_context)); + pthread_setspecific(f->context_key, ctx); + } + + return ctx; +} + +static void mt_freecontext(void *data) +{ + free(data); +} + void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data) { struct fuse_worker *w; + int res; w = malloc(sizeof(struct fuse_worker)); w->f = f; @@ -79,6 +98,12 @@ void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data) w->proc = proc; f->numworker = 1; + res = pthread_key_create(&f->context_key, mt_freecontext); + if(res != 0) { + fprintf(stderr, "Failed to create thread specific key\n"); + exit(1); + } + f->getcontext = mt_getcontext; do_work(w); } |