diff --git a/src/fusedav.c b/src/fusedav.c
index ed990e6d6289c362c8a52a96c78045bc9d4bcdc5..11f7ae7796f45160f10a667f948b1f15fdf936c2 100644 (file)
--- a/src/fusedav.c
+++ b/src/fusedav.c
ne_lock_store *lock_store = NULL;
struct ne_lock *lock = NULL;
int lock_thread_exit = 0;
+int lock_timeout = 60;
#define MIME_XATTR "user.mime_type"
#define MAX_REDIRECTS 10
-#define LOCK_TIMEOUT 8
struct fill_info {
void *buf;
@@ -248,7 +248,7 @@ static void getdir_propfind_callback(void *userdata, const char *href, const ne_
else
t = fn;
- dir_cache_add(f->root, t, is_dir);
+ dir_cache_add(f->root, t);
f->filler(f->buf, h = ne_path_unescape(t), NULL, 0);
free(h);
}
@@ -260,7 +260,6 @@ static void getdir_propfind_callback(void *userdata, const char *href, const ne_
static void getdir_cache_callback(
const char *root,
const char *fn,
- int is_dir,
void *user) {
struct fill_info *f = user;
const char *path,
void *buf,
fuse_fill_dir_t filler,
- off_t offset,
- struct fuse_file_info *fi) {
+ __unused off_t offset,
+ __unused struct fuse_file_info *fi) {
struct fill_info f;
ne_session *session;
return 0;
}
-static int dav_mkdir(const char *path, mode_t mode) {
+static int dav_mkdir(const char *path, __unused mode_t mode) {
char fn[PATH_MAX];
ne_session *session;
return r;
}
-static int dav_release(const char *path, struct fuse_file_info *info) {
+static int dav_release(const char *path, __unused struct fuse_file_info *info) {
void *f = NULL;
int r = 0;
ne_session *session;
return r;
}
-static int dav_fsync(const char *path, int isdatasync, struct fuse_file_info *info) {
+static int dav_fsync(const char *path, __unused int isdatasync, __unused struct fuse_file_info *info) {
void *f = NULL;
int r = 0;
ne_session *session;
return r;
}
-static int dav_mknod(const char *path, mode_t mode, dev_t rdev) {
+static int dav_mknod(const char *path, mode_t mode, __unused dev_t rdev) {
char tempfile[PATH_MAX];
int fd;
ne_session *session;
-
+
path = path_cvt(path);
if (debug)
fprintf(stderr, "mknod(%s)\n", path);
return 0;
}
-static int dav_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *info) {
+static int dav_read(const char *path, char *buf, size_t size, off_t offset, __unused struct fuse_file_info *info) {
void *f = NULL;
ssize_t r;
@@ -633,8 +632,6 @@ static int dav_read(const char *path, char *buf, size_t size, off_t offset, stru
goto finish;
}
- fprintf(stderr, "read: %i\n", r);
-
finish:
if (f)
file_cache_unref(f);
return r;
}
-static int dav_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *info) {
+static int dav_write(const char *path, const char *buf, size_t size, off_t offset, __unused struct fuse_file_info *info) {
void *f = NULL;
ssize_t r;
void *userdata,
const ne_propname *pname,
const char *value,
- const ne_status *status) {
+ __unused const ne_status *status) {
struct listxattr_info *l = userdata;
int n;
}
}
-static void listxattr_propfind_callback(void *userdata, const char *href, const ne_prop_result_set *results) {
+static void listxattr_propfind_callback(void *userdata, __unused const char *href, const ne_prop_result_set *results) {
struct listxattr_info *l = userdata;
ne_propset_iterate(results, listxattr_iterator, l);
}
void *userdata,
const ne_propname *pname,
const char *value,
- const ne_status *status) {
+ __unused const ne_status *status) {
struct getxattr_info *g = userdata;
return 0;
}
-static void getxattr_propfind_callback(void *userdata, const char *href, const ne_prop_result_set *results) {
+static void getxattr_propfind_callback(void *userdata, __unused const char *href, const ne_prop_result_set *results) {
struct getxattr_info *g = userdata;
ne_propset_iterate(results, getxattr_iterator, g);
}
e = argv0;
fprintf(stderr,
- "%s [-h] [-D] [-u USERNAME] [-p PASSWORD] [-o OPTIONS] URL MOUNTPOINT\n"
+ "%s [-hDL] [-t SECS] [-u USERNAME] [-p PASSWORD] [-o OPTIONS] URL MOUNTPOINT\n"
"\t-h Show this help\n"
"\t-D Enable debug mode\n"
"\t-u Username if required\n"
"\t-p Password if required\n"
- "\t-o Additional FUSE mount options\n",
+ "\t-o Additional FUSE mount options\n"
+ "\t-L Locking the repository during mount\n"
+ "\t-t Set lock timeout\n",
e);
}
-static void exit_handler(int s) {
+static void exit_handler(__unused int sig) {
static const char m[] = "*** Caught signal ***\n";
if(fuse != NULL)
fuse_exit(fuse);
write(2, m, strlen(m));
}
+static void empty_handler(__unused int sig) {}
+
static int setup_signal_handlers(void) {
struct sigaction sa;
-
+ sigset_t m;
+
sa.sa_handler = exit_handler;
sigemptyset(&(sa.sa_mask));
sa.sa_flags = 0;
return -1;
}
+ /* Used to shut down the locking thread */
+ sa.sa_handler = empty_handler;
+
+ if (sigaction(SIGUSR1, &sa, NULL) == -1) {
+ fprintf(stderr, "Cannot set user signals: %s\n", strerror(errno));
+ return -1;
+ }
+
+ sigemptyset(&m);
+ pthread_sigmask(SIG_BLOCK, &m, &m);
+ sigdelset(&m, SIGHUP);
+ sigdelset(&m, SIGINT);
+ sigdelset(&m, SIGTERM);
+ sigaddset(&m, SIGPIPE);
+ sigaddset(&m, SIGUSR1);
+ pthread_sigmask(SIG_SETMASK, &m, NULL);
+
return 0;
}
static int create_lock(void) {
ne_session *session;
- char token[64], _owner[64], *owner;
- char hn[32];
+ char _owner[64], *owner;
int i;
int ret;
owner = owner;
}
- gethostname(hn, sizeof(hn)-1);
- hn[sizeof(hn)-1] = 0;
-
- snprintf(token, sizeof(token), "%s.%lu.%lu", hn, (unsigned long) getpid(), (unsigned long) time(NULL));
-
ne_fill_server_uri(session, &lock->uri);
lock->uri.path = strdup(base_directory);
lock->depth = NE_DEPTH_INFINITE;
- lock->timeout = LOCK_TIMEOUT+2;
+ lock->timeout = lock_timeout;
lock->owner = strdup(owner);
-/* lock->token = strdup(token); */
+ if (debug)
+ fprintf(stderr, "Acquiring lock...\n");
+
for (i = 0; i < MAX_REDIRECTS; i++) {
const ne_uri *u;
return 0;
}
+static int remove_lock(void) {
+ ne_session *session;
+
+ assert(lock);
+
+ if (!(session = session_get(0)))
+ return -1;
+
+ if (debug)
+ fprintf(stderr, "Removing lock...\n");
+
+ if (ne_unlock(session, lock)) {
+ fprintf(stderr, "UNLOCK failed: %s\n", ne_get_error(session));
+ return -1;
+ }
+
+ return 0;
+}
+
static void *lock_thread_func(__unused void *p) {
ne_session *session;
+ sigset_t block;
if (debug)
fprintf(stderr, "lock_thread entering\n");
if (!(session = session_get(1)))
return NULL;
+ sigemptyset(&block);
+ sigaddset(&block, SIGUSR1);
+
assert(lock);
while (!lock_thread_exit) {
- lock->timeout = LOCK_TIMEOUT;
+ int r, t;
+
+ lock->timeout = lock_timeout;
+ pthread_sigmask(SIG_BLOCK, &block, NULL);
+ r = ne_lock_refresh(session, lock);
+ pthread_sigmask(SIG_UNBLOCK, &block, NULL);
-
- if (ne_lock_refresh(session, lock)) {
+ if (r) {
fprintf(stderr, "LOCK refresh failed: %s\n", ne_get_error(session));
break;
}
if (lock_thread_exit)
break;
- sleep(LOCK_TIMEOUT);
+ t = lock_timeout/2;
+ if (t <= 0)
+ t = 1;
+ sleep(t);
}
if (debug)
if (setup_signal_handlers() < 0)
goto finish;
- while ((c = getopt(argc, argv, "hu:p:Do:L")) != -1) {
+ while ((c = getopt(argc, argv, "hu:p:Do:Lt:")) != -1) {
switch(c) {
case 'u':
case 'L':
enable_locking = 1;
break;
+
+ case 't':
+ if ((lock_timeout = atoi(optarg)) < 0) {
+ fprintf(stderr, "Invalid lock timeout '%s'\n", optarg);
+ goto finish;
+ }
+ break;
case 'h':
+ ret = 0;
+
+ /* fall through */
default:
usage(argv[0]);
goto finish;
mount_args_strings[0] = argv[optind];
if (o) {
- mount_args_strings[1] = "-o";
+ mount_args_strings[1] = (char*) "-o";
mount_args_strings[2] = o;
mount_args.argc += 2;
}
}
if (enable_locking && create_lock() >= 0) {
- if (pthread_create(&lock_thread, NULL, lock_thread_func, NULL) < 0) {
- fprintf(stderr, "pthread_create(): %s\n", strerror(errno));
+ int r;
+ if ((r = pthread_create(&lock_thread, NULL, lock_thread_func, NULL)) < 0) {
+ fprintf(stderr, "pthread_create(): %s\n", strerror(r));
goto finish;
}
lock_thread_running = 1;
}
- fuse_loop(fuse);
+ fuse_loop_mt(fuse);
if (debug)
fprintf(stderr, "Exiting cleanly.\n");
if (lock_thread_running) {
lock_thread_exit = 1;
- pthread_kill(lock_thread, SIGPIPE);
+ pthread_kill(lock_thread, SIGUSR1);
pthread_join(lock_thread, NULL);
+ remove_lock();
ne_lockstore_destroy(lock_store);
}