From 2df1c04f30802df9a23a19e22042884430c429d2 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Tue, 6 Nov 2001 15:07:17 +0000 Subject: cleanups --- lib/fuse.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'lib/fuse.c') diff --git a/lib/fuse.c b/lib/fuse.c index 137b5ef..b12c58d 100644 --- a/lib/fuse.c +++ b/lib/fuse.c @@ -407,6 +407,7 @@ static void do_readlink(struct fuse *f, struct fuse_in_header *in) res = f->op.readlink(&cred, path, link, sizeof(link)); g_free(path); } + link[PATH_MAX] = '\0'; send_reply(f, in, res, link, !res ? strlen(link) : 0); } @@ -756,6 +757,17 @@ static void *do_command(void *data) return NULL; } +/* This hack makes it possible to link FUSE with or without the + pthread library */ +__attribute__((weak)) +int pthread_create(pthread_t *thrid __attribute__((unused)), + const pthread_attr_t *attr __attribute__((unused)), + void *(*func)(void *) __attribute__((unused)), + void *arg __attribute__((unused))) +{ + return ENOSYS; +} + void fuse_loop(struct fuse *f) { int res; @@ -787,24 +799,35 @@ void fuse_loop(struct fuse *f) if(f->flags & FUSE_MULTITHREAD) { res = pthread_create(&thrid, &attr, do_command, cmd); - if(res != 0) { - fprintf(stderr, "Error creating thread: %s\n", - strerror(errno)); - exit(1); - } + if(res == 0) + continue; + + fprintf(stderr, "Error creating thread: %s\n", strerror(res)); + fprintf(stderr, "Will run in single thread mode\n"); + f->flags &= ~FUSE_MULTITHREAD; } - else - do_command(cmd); + + do_command(cmd); } } -struct fuse *fuse_new(int flags) +struct fuse *fuse_new(int flags, mode_t root) { struct fuse *f = g_new0(struct fuse, 1); + if(!root) + root = S_IFDIR; + + if(!S_ISDIR(root) && !S_ISREG(root)) { + fprintf(stderr, "Invalid mode for root: 0%o\n", root); + root = S_IFDIR; + } + root &= S_IFMT; + f->flags = flags; + f->rootmode = root; f->fd = -1; - f->dir = NULL; + f->mnt = NULL; f->nametab = g_hash_table_new((GHashFunc) name_hash, (GCompareFunc) name_compare); pthread_mutex_init(&f->lock, NULL); -- cgit v1.2.3