From 5f12fb6a5fe976b9bdaafd3d7a1fc45e616a4f2d Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sat, 1 Aug 2020 18:04:13 -0400 Subject: [PATCH] libfuse cleanup: remove unnecessary files --- libfuse/fuse.pc.in | 11 - libfuse/lib/Makefile.am | 42 ---- libfuse/lib/fuse_versionscript | 207 --------------- libfuse/lib/ulockmgr.c | 444 --------------------------------- libfuse/util/Makefile.am | 58 ----- libfuse/util/init_script | 89 ------- libfuse/util/udev.rules | 1 - libfuse/util/ulockmgr_server.c | 425 ------------------------------- 8 files changed, 1277 deletions(-) delete mode 100644 libfuse/fuse.pc.in delete mode 100644 libfuse/lib/Makefile.am delete mode 100644 libfuse/lib/fuse_versionscript delete mode 100644 libfuse/lib/ulockmgr.c delete mode 100644 libfuse/util/Makefile.am delete mode 100755 libfuse/util/init_script delete mode 100644 libfuse/util/udev.rules delete mode 100644 libfuse/util/ulockmgr_server.c diff --git a/libfuse/fuse.pc.in b/libfuse/fuse.pc.in deleted file mode 100644 index 8fdb8415..00000000 --- a/libfuse/fuse.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: fuse -Description: Filesystem in Userspace -Version: @VERSION@ -Libs: -L${libdir} -lfuse -pthread -Libs.private: @libfuse_libs@ -Cflags: -I${includedir}/fuse -D_FILE_OFFSET_BITS=64 diff --git a/libfuse/lib/Makefile.am b/libfuse/lib/Makefile.am deleted file mode 100644 index 7c8104a7..00000000 --- a/libfuse/lib/Makefile.am +++ /dev/null @@ -1,42 +0,0 @@ -## Process this file with automake to produce Makefile.in - -AUTOMAKE_OPTIONS = subdir-objects -AM_CPPFLAGS = -I$(top_srcdir)/include -DFUSERMOUNT_DIR=\"$(bindir)\" \ - -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DFUSE_USE_VERSION=26 - -lib_LTLIBRARIES = libfuse.la libulockmgr.la - -if BSD -mount_source = mount_bsd.c -else -mount_source = mount.c mount_util.c mount_util.h -endif - -libfuse_la_SOURCES = \ - fuse.c \ - fuse_i.h \ - fuse_kern_chan.c \ - fuse_loop.c \ - fuse_loop_mt.c \ - fuse_lowlevel.c \ - fuse_misc.h \ - fuse_mt.c \ - fuse_opt.c \ - fuse_session.c \ - fuse_signals.c \ - buffer.c \ - cuse_lowlevel.c \ - helper.c \ - $(mount_source) - -libfuse_la_LDFLAGS = -pthread @libfuse_libs@ -version-number 2:9:7 \ - -Wl,--version-script,$(srcdir)/fuse_versionscript - -if NETBSD -libfuse_la_LIBADD = -lperfuse -lpuffs -endif - -libulockmgr_la_SOURCES = ulockmgr.c -libulockmgr_la_LDFLAGS = -pthread -version-number 1:0:1 - -EXTRA_DIST = fuse_versionscript diff --git a/libfuse/lib/fuse_versionscript b/libfuse/lib/fuse_versionscript deleted file mode 100644 index 8d91887d..00000000 --- a/libfuse/lib/fuse_versionscript +++ /dev/null @@ -1,207 +0,0 @@ -FUSE_2.2 { - global: - fuse_destroy; - fuse_exit; - fuse_exited; - fuse_invalidate; - fuse_is_lib_option; - fuse_loop; - fuse_loop_mt; - fuse_loop_mt_proc; - fuse_main; - fuse_main_compat1; - fuse_main_compat2; - fuse_mount_compat1; - fuse_new_compat1; - fuse_new_compat2; - fuse_process_cmd; - fuse_read_cmd; - fuse_set_getcontext_func; - fuse_setup_compat2; -}; - -FUSE_2.4 { - global: - fuse_add_dirent; - fuse_chan_bufsize; - fuse_chan_data; - fuse_chan_destroy; - fuse_chan_fd; - fuse_chan_receive; - fuse_chan_send; - fuse_chan_session; - fuse_dirent_size; - fuse_kern_chan_new; - fuse_lowlevel_is_lib_option; - fuse_reply_attr; - fuse_reply_buf; - fuse_reply_entry; - fuse_reply_err; - fuse_reply_none; - fuse_reply_readlink; - fuse_reply_write; - fuse_reply_xattr; - fuse_req_userdata; - fuse_session_add_chan; - fuse_session_destroy; - fuse_session_exit; - fuse_session_exited; - fuse_session_loop; - fuse_session_loop_mt; - fuse_session_new; - fuse_session_next_chan; - fuse_session_process; - fuse_session_reset; -} FUSE_2.2; - -FUSE_2.5 { - global: - fuse_lowlevel_new_compat; - fuse_main_real_compat22; - fuse_mount_compat22; - fuse_new_compat22; - fuse_opt_parse; - fuse_opt_add_opt; - fuse_opt_add_arg; - fuse_opt_free_args; - fuse_opt_match; - fuse_parse_cmdline; - fuse_remove_signal_handlers; - fuse_reply_create; - fuse_reply_open; - fuse_reply_open_compat; - fuse_reply_statfs; - fuse_reply_statfs_compat; - fuse_setup_compat22; - fuse_set_signal_handlers; -} FUSE_2.4; - -FUSE_2.6 { - global: - fuse_add_direntry; - fuse_chan_new; - fuse_chan_new_compat24; - fuse_chan_recv; - fuse_daemonize; - fuse_get_session; - fuse_interrupted; - fuse_lowlevel_new; - fuse_lowlevel_new_compat25; - fuse_main_real; - fuse_main_real_compat25; - fuse_mount; - fuse_mount_compat25; - fuse_new; - fuse_new_compat25; - fuse_opt_insert_arg; - fuse_reply_lock; - fuse_req_interrupt_func; - fuse_req_interrupted; - fuse_session_remove_chan; - fuse_setup; - fuse_setup_compat25; - fuse_teardown; - fuse_teardown_compat22; - fuse_unmount; - fuse_unmount_compat22; -} FUSE_2.5; - -FUSE_2.7 { - global: - fuse_fs_access; - fuse_fs_bmap; - fuse_fs_chmod; - fuse_fs_chown; - fuse_fs_create; - fuse_fs_destroy; - fuse_fs_fgetattr; - fuse_fs_flush; - fuse_fs_fsync; - fuse_fs_fsyncdir; - fuse_fs_ftruncate; - fuse_fs_getattr; - fuse_fs_getxattr; - fuse_fs_init; - fuse_fs_link; - fuse_fs_listxattr; - fuse_fs_lock; - fuse_fs_mkdir; - fuse_fs_mknod; - fuse_fs_new; - fuse_fs_open; - fuse_fs_opendir; - fuse_fs_read; - fuse_fs_readdir; - fuse_fs_readlink; - fuse_fs_release; - fuse_fs_releasedir; - fuse_fs_removexattr; - fuse_fs_rename; - fuse_fs_rmdir; - fuse_fs_setxattr; - fuse_fs_statfs; - fuse_fs_symlink; - fuse_fs_truncate; - fuse_fs_unlink; - fuse_fs_utimens; - fuse_fs_write; - fuse_register_module; - fuse_reply_iov; - fuse_version; -} FUSE_2.6; - -FUSE_2.7.5 { - global: - fuse_reply_bmap; -} FUSE_2.7; - -FUSE_2.8 { - global: - cuse_lowlevel_new; - cuse_lowlevel_main; - cuse_lowlevel_setup; - cuse_lowlevel_teardown; - fuse_fs_ioctl; - fuse_fs_poll; - fuse_get_context; - fuse_getgroups; - fuse_lowlevel_notify_inval_entry; - fuse_lowlevel_notify_inval_inode; - fuse_lowlevel_notify_poll; - fuse_notify_poll; - fuse_opt_add_opt_escaped; - fuse_pollhandle_destroy; - fuse_reply_ioctl; - fuse_reply_ioctl_iov; - fuse_reply_ioctl_retry; - fuse_reply_poll; - fuse_req_ctx; - fuse_req_getgroups; - fuse_session_data; -} FUSE_2.7.5; - -FUSE_2.9 { - global: - fuse_buf_copy; - fuse_buf_size; - fuse_fs_read_buf; - fuse_fs_write_buf; - fuse_lowlevel_notify_retrieve; - fuse_lowlevel_notify_store; - fuse_reply_data; - fuse_session_process_buf; - fuse_session_receive_buf; - fuse_start_cleanup_thread; - fuse_stop_cleanup_thread; - fuse_clean_cache; - fuse_lowlevel_notify_delete; - fuse_fs_flock; -} FUSE_2.8; - -FUSE_2.9.1 { - global: - fuse_fs_fallocate; - - local: - *; -} FUSE_2.9; diff --git a/libfuse/lib/ulockmgr.c b/libfuse/lib/ulockmgr.c deleted file mode 100644 index 718d37c6..00000000 --- a/libfuse/lib/ulockmgr.c +++ /dev/null @@ -1,444 +0,0 @@ -/* - libulockmgr: Userspace Lock Manager Library - Copyright (C) 2006 Miklos Szeredi - - This program can be distributed under the terms of the GNU LGPLv2. - See the file COPYING.LIB -*/ - -/* #define DEBUG 1 */ - -#include "ulockmgr.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct message { - unsigned intr : 1; - unsigned nofd : 1; - pthread_t thr; - int cmd; - int fd; - struct flock lock; - int error; -}; - -struct fd_store { - struct fd_store *next; - int fd; - int inuse; -}; - -struct owner { - struct owner *next; - struct owner *prev; - struct fd_store *fds; - void *id; - size_t id_len; - int cfd; -}; - -static pthread_mutex_t ulockmgr_lock; -static int ulockmgr_cfd = -1; -static struct owner owner_list = { .next = &owner_list, .prev = &owner_list }; - -#define MAX_SEND_FDS 2 - -static void list_del_owner(struct owner *owner) -{ - struct owner *prev = owner->prev; - struct owner *next = owner->next; - prev->next = next; - next->prev = prev; -} - -static void list_add_owner(struct owner *owner, struct owner *next) -{ - struct owner *prev = next->prev; - owner->next = next; - owner->prev = prev; - prev->next = owner; - next->prev = owner; -} - -/* - * There's a bug in the linux kernel (< 2.6.22) recv() implementation - * on AF_UNIX, SOCK_STREAM sockets, that could cause it to return - * zero, even if data was available. Retrying the recv will return - * the data in this case. - */ -static int do_recv(int sock, void *buf, size_t len, int flags) -{ - int res = recv(sock, buf, len, flags); - if (res == 0) - res = recv(sock, buf, len, flags); - - return res; -} - -static int ulockmgr_send_message(int sock, void *buf, size_t buflen, - int *fdp, int numfds) -{ - struct msghdr msg; - struct cmsghdr *p_cmsg; - struct iovec vec; - size_t cmsgbuf[CMSG_SPACE(sizeof(int) * MAX_SEND_FDS) / sizeof(size_t)]; - int res; - - assert(numfds <= MAX_SEND_FDS); - msg.msg_control = cmsgbuf; - msg.msg_controllen = sizeof(cmsgbuf); - p_cmsg = CMSG_FIRSTHDR(&msg); - p_cmsg->cmsg_level = SOL_SOCKET; - p_cmsg->cmsg_type = SCM_RIGHTS; - p_cmsg->cmsg_len = CMSG_LEN(sizeof(int) * numfds); - memcpy(CMSG_DATA(p_cmsg), fdp, sizeof(int) * numfds); - msg.msg_controllen = p_cmsg->cmsg_len; - msg.msg_name = NULL; - msg.msg_namelen = 0; - msg.msg_iov = &vec; - msg.msg_iovlen = 1; - msg.msg_flags = 0; - vec.iov_base = buf; - vec.iov_len = buflen; - res = sendmsg(sock, &msg, MSG_NOSIGNAL); - if (res == -1) { - perror("libulockmgr: sendmsg"); - return -1; - } - if ((size_t) res != buflen) { - fprintf(stderr, "libulockmgr: sendmsg short\n"); - return -1; - } - return 0; -} - -static int ulockmgr_start_daemon(void) -{ - int sv[2]; - int res; - char tmp[64]; - - res = socketpair(AF_UNIX, SOCK_STREAM, 0, sv); - if (res == -1) { - perror("libulockmgr: socketpair"); - return -1; - } - snprintf(tmp, sizeof(tmp), "exec ulockmgr_server %i", sv[0]); - res = system(tmp); - close(sv[0]); - if (res == -1 || !WIFEXITED(res) || WEXITSTATUS(res) != 0) { - close(sv[1]); - return -1; - } - ulockmgr_cfd = sv[1]; - return 0; -} - -static struct owner *ulockmgr_new_owner(const void *id, size_t id_len) -{ - int sv[2]; - int res; - char c = 'm'; - struct owner *o; - - if (ulockmgr_cfd == -1 && ulockmgr_start_daemon() == -1) - return NULL; - - o = calloc(1, sizeof(struct owner) + id_len); - if (!o) { - fprintf(stderr, "libulockmgr: failed to allocate memory\n"); - return NULL; - } - o->id = o + 1; - o->id_len = id_len; - res = socketpair(AF_UNIX, SOCK_STREAM, 0, sv); - if (res == -1) { - perror("libulockmgr: socketpair"); - goto out_free; - } - res = ulockmgr_send_message(ulockmgr_cfd, &c, sizeof(c), &sv[0], 1); - close(sv[0]); - if (res == -1) { - close(ulockmgr_cfd); - ulockmgr_cfd = -1; - goto out_close; - } - - o->cfd = sv[1]; - memcpy(o->id, id, id_len); - list_add_owner(o, &owner_list); - - return o; - - out_close: - close(sv[1]); - out_free: - free(o); - return NULL; -} - -static int ulockmgr_send_request(struct message *msg, const void *id, - size_t id_len) -{ - int sv[2]; - int cfd; - struct owner *o; - struct fd_store *f = NULL; - struct fd_store *newf = NULL; - struct fd_store **fp; - int fd = msg->fd; - int cmd = msg->cmd; - int res; - int unlockall = (cmd == F_SETLK && msg->lock.l_type == F_UNLCK && - msg->lock.l_start == 0 && msg->lock.l_len == 0); - - for (o = owner_list.next; o != &owner_list; o = o->next) - if (o->id_len == id_len && memcmp(o->id, id, id_len) == 0) - break; - - if (o == &owner_list) - o = NULL; - - if (!o && cmd != F_GETLK && msg->lock.l_type != F_UNLCK) - o = ulockmgr_new_owner(id, id_len); - - if (!o) { - if (cmd == F_GETLK) { - res = fcntl(msg->fd, F_GETLK, &msg->lock); - return (res == -1) ? -errno : 0; - } else if (msg->lock.l_type == F_UNLCK) - return 0; - else - return -ENOLCK; - } - - if (unlockall) - msg->nofd = 1; - else { - for (fp = &o->fds; *fp; fp = &(*fp)->next) { - f = *fp; - if (f->fd == fd) { - msg->nofd = 1; - break; - } - } - } - - if (!msg->nofd) { - newf = f = calloc(1, sizeof(struct fd_store)); - if (!f) { - fprintf(stderr, "libulockmgr: failed to allocate memory\n"); - return -ENOLCK; - } - } - - res = socketpair(AF_UNIX, SOCK_STREAM, 0, sv); - if (res == -1) { - perror("libulockmgr: socketpair"); - free(newf); - return -ENOLCK; - } - - cfd = sv[1]; - sv[1] = msg->fd; - res = ulockmgr_send_message(o->cfd, msg, sizeof(struct message), sv, - msg->nofd ? 1 : 2); - close(sv[0]); - if (res == -1) { - free(newf); - close(cfd); - return -EIO; - } - - if (newf) { - newf->fd = msg->fd; - newf->next = o->fds; - o->fds = newf; - } - if (f) - f->inuse++; - - res = do_recv(cfd, msg, sizeof(struct message), MSG_WAITALL); - if (res == -1) { - perror("libulockmgr: recv"); - msg->error = EIO; - } else if (res != sizeof(struct message)) { - fprintf(stderr, "libulockmgr: recv short\n"); - msg->error = EIO; - } else if (cmd == F_SETLKW && msg->error == EAGAIN) { - pthread_mutex_unlock(&ulockmgr_lock); - while (1) { - sigset_t old; - sigset_t unblock; - int errno_save; - - sigemptyset(&unblock); - sigaddset(&unblock, SIGUSR1); - pthread_sigmask(SIG_UNBLOCK, &unblock, &old); - res = do_recv(cfd, msg, sizeof(struct message), - MSG_WAITALL); - errno_save = errno; - pthread_sigmask(SIG_SETMASK, &old, NULL); - if (res == sizeof(struct message)) - break; - else if (res >= 0) { - fprintf(stderr, "libulockmgr: recv short\n"); - msg->error = EIO; - break; - } else if (errno_save != EINTR) { - errno = errno_save; - perror("libulockmgr: recv"); - msg->error = EIO; - break; - } - msg->intr = 1; - res = send(o->cfd, msg, sizeof(struct message), - MSG_NOSIGNAL); - if (res == -1) { - perror("libulockmgr: send"); - msg->error = EIO; - break; - } - if (res != sizeof(struct message)) { - fprintf(stderr, "libulockmgr: send short\n"); - msg->error = EIO; - break; - } - } - pthread_mutex_lock(&ulockmgr_lock); - - } - if (f) - f->inuse--; - close(cfd); - if (unlockall) { - for (fp = &o->fds; *fp;) { - f = *fp; - if (f->fd == fd && !f->inuse) { - *fp = f->next; - free(f); - } else - fp = &f->next; - } - if (!o->fds) { - list_del_owner(o); - close(o->cfd); - free(o); - } - /* Force OK on unlock-all, since it _will_ succeed once the - owner is deleted */ - msg->error = 0; - } - - return -msg->error; -} - -#ifdef DEBUG -static uint32_t owner_hash(const unsigned char *id, size_t id_len) -{ - uint32_t h = 0; - size_t i; - for (i = 0; i < id_len; i++) - h = ((h << 8) | (h >> 24)) ^ id[i]; - - return h; -} -#endif - -static int ulockmgr_canonicalize(int fd, struct flock *lock) -{ - off_t offset; - if (lock->l_whence == SEEK_CUR) { - offset = lseek(fd, 0, SEEK_CUR); - if (offset == (off_t) -1) - return -errno; - } else if (lock->l_whence == SEEK_END) { - struct stat stbuf; - int res = fstat(fd, &stbuf); - if (res == -1) - return -errno; - - offset = stbuf.st_size; - } else - offset = 0; - - lock->l_whence = SEEK_SET; - lock->l_start += offset; - - if (lock->l_start < 0) - return -EINVAL; - - if (lock->l_len < 0) { - lock->l_start += lock->l_len; - if (lock->l_start < 0) - return -EINVAL; - lock->l_len = -lock->l_len; - } - if (lock->l_len && lock->l_start + lock->l_len - 1 < 0) - return -EINVAL; - - return 0; -} - -int ulockmgr_op(int fd, int cmd, struct flock *lock, const void *owner, - size_t owner_len) -{ - int err; - struct message msg; - sigset_t old; - sigset_t block; - - if (cmd != F_GETLK && cmd != F_SETLK && cmd != F_SETLKW) - return -EINVAL; - - if (lock->l_type != F_RDLCK && lock->l_type != F_WRLCK && - lock->l_type != F_UNLCK) - return -EINVAL; - - if (lock->l_whence != SEEK_SET && lock->l_whence != SEEK_CUR && - lock->l_whence != SEEK_END) - return -EINVAL; - -#ifdef DEBUG - fprintf(stderr, "libulockmgr: %i %i %i %lli %lli own: 0x%08x\n", - cmd, lock->l_type, lock->l_whence, lock->l_start, lock->l_len, - owner_hash(owner, owner_len)); -#endif - - /* Unlock should never block anyway */ - if (cmd == F_SETLKW && lock->l_type == F_UNLCK) - cmd = F_SETLK; - - memset(&msg, 0, sizeof(struct message)); - msg.cmd = cmd; - msg.fd = fd; - msg.lock = *lock; - err = ulockmgr_canonicalize(fd, &msg.lock); - if (err) - return err; - - sigemptyset(&block); - sigaddset(&block, SIGUSR1); - pthread_sigmask(SIG_BLOCK, &block, &old); - pthread_mutex_lock(&ulockmgr_lock); - err = ulockmgr_send_request(&msg, owner, owner_len); - pthread_mutex_unlock(&ulockmgr_lock); - pthread_sigmask(SIG_SETMASK, &old, NULL); - if (!err && cmd == F_GETLK) { - if (msg.lock.l_type == F_UNLCK) - lock->l_type = F_UNLCK; - else - *lock = msg.lock; - } - - return err; -} diff --git a/libfuse/util/Makefile.am b/libfuse/util/Makefile.am deleted file mode 100644 index 059d5fc2..00000000 --- a/libfuse/util/Makefile.am +++ /dev/null @@ -1,58 +0,0 @@ -## Process this file with automake to produce Makefile.in - -AM_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -bin_PROGRAMS = fusermount ulockmgr_server -noinst_PROGRAMS = mount.fuse - -# we re-use mount_util.c from the library, but do want to keep ourself -# as stand-alone as possible. in order to make an out-of-source build -# possible, we "generate" the file from its original location by -# copying it over. -fusermount_SOURCES = fusermount.c mount_util.c -fusermount_CPPFLAGS = -I$(top_srcdir)/lib -BUILT_SOURCES = mount_util.c -mount_util.c: $(top_srcdir)/lib/mount_util.c - @cp $(top_srcdir)/lib/mount_util.c . - -mount_fuse_SOURCES = mount.fuse.c - -ulockmgr_server_SOURCES = ulockmgr_server.c -ulockmgr_server_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_REENTRANT -ulockmgr_server_LDFLAGS = -pthread - -install-exec-hook: - -chmod u+s $(DESTDIR)$(bindir)/fusermount - @if test ! -e $(DESTDIR)/dev/fuse; then \ - $(MKDIR_P) $(DESTDIR)/dev; \ - echo "mknod $(DESTDIR)/dev/fuse -m 0666 c 10 229 || true"; \ - mknod $(DESTDIR)/dev/fuse -m 0666 c 10 229 || true; \ - fi - -EXTRA_DIST = udev.rules init_script - -MOUNT_FUSE_PATH = @MOUNT_FUSE_PATH@ -UDEV_RULES_PATH = @UDEV_RULES_PATH@ -INIT_D_PATH = @INIT_D_PATH@ - -install-exec-local: - $(MKDIR_P) $(DESTDIR)$(MOUNT_FUSE_PATH) - $(INSTALL_PROGRAM) $(builddir)/mount.fuse $(DESTDIR)$(MOUNT_FUSE_PATH)/mount.fuse - $(MKDIR_P) $(DESTDIR)$(INIT_D_PATH) - $(INSTALL_SCRIPT) $(srcdir)/init_script $(DESTDIR)$(INIT_D_PATH)/fuse - @if test -x /usr/sbin/update-rc.d; then \ - echo "/usr/sbin/update-rc.d fuse start 34 S . start 41 0 6 . || true"; \ - /usr/sbin/update-rc.d fuse start 34 S . start 41 0 6 . || true; \ - fi - -install-data-local: - $(MKDIR_P) $(DESTDIR)$(UDEV_RULES_PATH) - $(INSTALL_DATA) $(srcdir)/udev.rules $(DESTDIR)$(UDEV_RULES_PATH)/99-fuse.rules - -uninstall-local: - rm -f $(DESTDIR)$(MOUNT_FUSE_PATH)/mount.fuse - rm -f $(DESTDIR)$(UDEV_RULES_PATH)/99-fuse.rules - rm -f $(DESTDIR)$(INIT_D_PATH)/fuse - @if test -x /usr/sbin/update-rc.d; then \ - echo "/usr/sbin/update-rc.d fuse remove || true"; \ - /usr/sbin/update-rc.d fuse remove || true; \ - fi diff --git a/libfuse/util/init_script b/libfuse/util/init_script deleted file mode 100755 index 331b33ad..00000000 --- a/libfuse/util/init_script +++ /dev/null @@ -1,89 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: fuse -# Required-Start: -# Should-Start: udev -# Required-Stop: -# Default-Start: S -# Default-Stop: -# Short-Description: Start and stop fuse. -# Description: Load the fuse module and mount the fuse control -# filesystem. -### END INIT INFO - -set -e - -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -MOUNTPOINT=/sys/fs/fuse/connections - -# Gracefully exit if the package has been removed. -which fusermount &>/dev/null || exit 5 - -case "$1" in - start|restart|force-reload) - if ! grep -qw fuse /proc/filesystems; then - echo -n "Loading fuse module" - if ! modprobe fuse >/dev/null 2>&1; then - echo " failed!" - exit 1 - else - echo "." - fi - else - echo "Fuse filesystem already available." - fi - if grep -qw fusectl /proc/filesystems && \ - ! grep -qw $MOUNTPOINT /proc/mounts; then - echo -n "Mounting fuse control filesystem" - if ! mount -t fusectl fusectl $MOUNTPOINT >/dev/null 2>&1; then - echo " failed!" - exit 1 - else - echo "." - fi - else - echo "Fuse control filesystem already available." - fi - ;; - stop) - if ! grep -qw fuse /proc/filesystems; then - echo "Fuse filesystem not loaded." - exit 7 - fi - if grep -qw $MOUNTPOINT /proc/mounts; then - echo -n "Unmounting fuse control filesystem" - if ! umount $MOUNTPOINT >/dev/null 2>&1; then - echo " failed!" - else - echo "." - fi - else - echo "Fuse control filesystem not mounted." - fi - if grep -qw "^fuse" /proc/modules; then - echo -n "Unloading fuse module" - if ! rmmod fuse >/dev/null 2>&1; then - echo " failed!" - else - echo "." - fi - else - echo "Fuse module not loaded." - fi - ;; - status) - echo -n "Checking fuse filesystem" - if ! grep -qw fuse /proc/filesystems; then - echo " not available." - exit 3 - else - echo " ok." - fi - ;; - *) - echo "Usage: $0 {start|stop|restart|force-reload|status}" - exit 1 - ;; -esac - -exit 0 diff --git a/libfuse/util/udev.rules b/libfuse/util/udev.rules deleted file mode 100644 index 95851114..00000000 --- a/libfuse/util/udev.rules +++ /dev/null @@ -1 +0,0 @@ -KERNEL=="fuse", MODE="0666" diff --git a/libfuse/util/ulockmgr_server.c b/libfuse/util/ulockmgr_server.c deleted file mode 100644 index 273c7d92..00000000 --- a/libfuse/util/ulockmgr_server.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - ulockmgr_server: Userspace Lock Manager Server - Copyright (C) 2006 Miklos Szeredi - - This program can be distributed under the terms of the GNU GPL. - See the file COPYING. -*/ - -/* #define DEBUG 1 */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct message { - unsigned intr : 1; - unsigned nofd : 1; - pthread_t thr; - int cmd; - int fd; - struct flock lock; - int error; -}; - -struct fd_store { - struct fd_store *next; - int fd; - int origfd; - int inuse; -}; - -struct owner { - struct fd_store *fds; - pthread_mutex_t lock; -}; - -struct req_data { - struct owner *o; - int cfd; - struct fd_store *f; - struct message msg; -}; - -#define MAX_SEND_FDS 2 - -static int receive_message(int sock, void *buf, size_t buflen, int *fdp, - int *numfds) -{ - struct msghdr msg; - struct iovec iov; - size_t ccmsg[CMSG_SPACE(sizeof(int) * MAX_SEND_FDS) / sizeof(size_t)]; - struct cmsghdr *cmsg; - int res; - int i; - - assert(*numfds <= MAX_SEND_FDS); - iov.iov_base = buf; - iov.iov_len = buflen; - - memset(&msg, 0, sizeof(msg)); - memset(ccmsg, -1, sizeof(ccmsg)); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = ccmsg; - msg.msg_controllen = sizeof(ccmsg); - - res = recvmsg(sock, &msg, MSG_WAITALL); - if (!res) { - /* retry on zero return, see do_recv() in ulockmgr.c */ - res = recvmsg(sock, &msg, MSG_WAITALL); - if (!res) - return 0; - } - if (res == -1) { - perror("ulockmgr_server: recvmsg"); - return -1; - } - if ((size_t) res != buflen) { - fprintf(stderr, "ulockmgr_server: short message received\n"); - return -1; - } - - cmsg = CMSG_FIRSTHDR(&msg); - if (cmsg) { - if (cmsg->cmsg_type != SCM_RIGHTS) { - fprintf(stderr, - "ulockmgr_server: unknown control message %d\n", - cmsg->cmsg_type); - return -1; - } - memcpy(fdp, CMSG_DATA(cmsg), sizeof(int) * *numfds); - if (msg.msg_flags & MSG_CTRUNC) { - fprintf(stderr, - "ulockmgr_server: control message truncated\n"); - for (i = 0; i < *numfds; i++) - close(fdp[i]); - *numfds = 0; - } - } else { - if (msg.msg_flags & MSG_CTRUNC) { - fprintf(stderr, - "ulockmgr_server: control message truncated(*)\n"); - - /* There's a bug in the Linux kernel, that if - not all file descriptors were allocated, - then the cmsg header is not filled in */ - cmsg = (struct cmsghdr *) ccmsg; - memcpy(fdp, CMSG_DATA(cmsg), sizeof(int) * *numfds); - for (i = 0; i < *numfds; i++) - close(fdp[i]); - } - *numfds = 0; - } - return res; -} - -static int closefrom(int minfd) -{ - DIR *dir = opendir("/proc/self/fd"); - if (dir) { - int dfd = dirfd(dir); - struct dirent *ent; - while ((ent = readdir(dir))) { - char *end; - int fd = strtol(ent->d_name, &end, 10); - if (ent->d_name[0] && !end[0] && fd >= minfd && - fd != dfd) - close(fd); - } - closedir(dir); - } - return 0; -} - -static void send_reply(int cfd, struct message *msg) -{ - int res = send(cfd, msg, sizeof(struct message), MSG_NOSIGNAL); - if (res == -1) - perror("ulockmgr_server: sending reply"); -#ifdef DEBUG - fprintf(stderr, "ulockmgr_server: error: %i\n", msg->error); -#endif -} - -static void *process_request(void *d_) -{ - struct req_data *d = d_; - int res; - - assert(d->msg.cmd == F_SETLKW); - res = fcntl(d->f->fd, F_SETLK, &d->msg.lock); - if (res == -1 && errno == EAGAIN) { - d->msg.error = EAGAIN; - d->msg.thr = pthread_self(); - send_reply(d->cfd, &d->msg); - res = fcntl(d->f->fd, F_SETLKW, &d->msg.lock); - } - d->msg.error = (res == -1) ? errno : 0; - pthread_mutex_lock(&d->o->lock); - d->f->inuse--; - pthread_mutex_unlock(&d->o->lock); - send_reply(d->cfd, &d->msg); - close(d->cfd); - free(d); - - return NULL; -} - -static void process_message(struct owner *o, struct message *msg, int cfd, - int fd) -{ - struct fd_store *f = NULL; - struct fd_store *newf = NULL; - struct fd_store **fp; - struct req_data *d; - pthread_t tid; - int res; - -#ifdef DEBUG - fprintf(stderr, "ulockmgr_server: %i %i %i %lli %lli\n", - msg->cmd, msg->lock.l_type, msg->lock.l_whence, - msg->lock.l_start, msg->lock.l_len); -#endif - - if (msg->cmd == F_SETLK && msg->lock.l_type == F_UNLCK && - msg->lock.l_start == 0 && msg->lock.l_len == 0) { - for (fp = &o->fds; *fp;) { - f = *fp; - if (f->origfd == msg->fd && !f->inuse) { - close(f->fd); - *fp = f->next; - free(f); - } else - fp = &f->next; - } - if (!msg->nofd) - close(fd); - - msg->error = 0; - send_reply(cfd, msg); - close(cfd); - return; - } - - if (msg->nofd) { - for (fp = &o->fds; *fp; fp = &(*fp)->next) { - f = *fp; - if (f->origfd == msg->fd) - break; - } - if (!*fp) { - fprintf(stderr, "ulockmgr_server: fd %i not found\n", - msg->fd); - msg->error = EIO; - send_reply(cfd, msg); - close(cfd); - return; - } - } else { - newf = f = malloc(sizeof(struct fd_store)); - if (!f) { - msg->error = ENOLCK; - send_reply(cfd, msg); - close(cfd); - return; - } - - f->fd = fd; - f->origfd = msg->fd; - f->inuse = 0; - } - - if (msg->cmd == F_GETLK || msg->cmd == F_SETLK || - msg->lock.l_type == F_UNLCK) { - res = fcntl(f->fd, msg->cmd, &msg->lock); - msg->error = (res == -1) ? errno : 0; - send_reply(cfd, msg); - close(cfd); - if (newf) { - newf->next = o->fds; - o->fds = newf; - } - return; - } - - d = malloc(sizeof(struct req_data)); - if (!d) { - msg->error = ENOLCK; - send_reply(cfd, msg); - close(cfd); - free(newf); - return; - } - - f->inuse++; - d->o = o; - d->cfd = cfd; - d->f = f; - d->msg = *msg; - res = pthread_create(&tid, NULL, process_request, d); - if (res) { - msg->error = ENOLCK; - send_reply(cfd, msg); - close(cfd); - free(d); - f->inuse--; - free(newf); - return; - } - - if (newf) { - newf->next = o->fds; - o->fds = newf; - } - pthread_detach(tid); -} - -static void sigusr1_handler(int sig) -{ - (void) sig; - /* Nothing to do */ -} - -static void process_owner(int cfd) -{ - struct owner o; - struct sigaction sa; - - memset(&sa, 0, sizeof(struct sigaction)); - sa.sa_handler = sigusr1_handler; - sigemptyset(&sa.sa_mask); - - if (sigaction(SIGUSR1, &sa, NULL) == -1) { - perror("ulockmgr_server: cannot set sigusr1 signal handler"); - exit(1); - } - - memset(&o, 0, sizeof(struct owner)); - pthread_mutex_init(&o.lock, NULL); - while (1) { - struct message msg; - int rfds[2]; - int res; - int numfds = 2; - - res = receive_message(cfd, &msg, sizeof(msg), rfds, &numfds); - if (!res) - break; - if (res == -1) - exit(1); - - if (msg.intr) { - if (numfds != 0) - fprintf(stderr, - "ulockmgr_server: too many fds for intr\n"); - pthread_kill(msg.thr, SIGUSR1); - } else { - if (numfds != 2) - continue; - - pthread_mutex_lock(&o.lock); - process_message(&o, &msg, rfds[0], rfds[1]); - pthread_mutex_unlock(&o.lock); - } - } - if (o.fds) - fprintf(stderr, - "ulockmgr_server: open file descriptors on exit\n"); -} - -int main(int argc, char *argv[]) -{ - int nullfd; - char *end; - int cfd; - sigset_t empty; - - if (argc != 2 || !argv[1][0]) - goto out_inval; - - cfd = strtol(argv[1], &end, 10); - if (*end) - goto out_inval; - - /* demonize current process */ - switch(fork()) { - case -1: - perror("ulockmgr_server: fork"); - exit(1); - case 0: - break; - default: - _exit(0); - } - - if (setsid() == -1) { - perror("ulockmgr_server: setsid"); - exit(1); - } - - (void) chdir("/"); - - sigemptyset(&empty); - sigprocmask(SIG_SETMASK, &empty, NULL); - - if (dup2(cfd, 4) == -1) { - perror("ulockmgr_server: dup2"); - exit(1); - } - cfd = 4; - nullfd = open("/dev/null", O_RDWR); - if (nullfd >= 0) { - dup2(nullfd, 0); - dup2(nullfd, 1); - } - close(3); - closefrom(5); - while (1) { - char c; - int sock; - int pid; - int numfds = 1; - int res = receive_message(cfd, &c, sizeof(c), &sock, &numfds); - if (!res) - break; - if (res == -1) - exit(1); - assert(numfds == 1); - - pid = fork(); - if (pid == -1) { - perror("ulockmgr_server: fork"); - close(sock); - continue; - } - if (pid == 0) { - close(cfd); - pid = fork(); - if (pid == -1) { - perror("ulockmgr_server: fork"); - _exit(1); - } - if (pid == 0) - process_owner(sock); - _exit(0); - } - waitpid(pid, NULL, 0); - close(sock); - } - return 0; - -out_inval: - fprintf(stderr, "%s should be started by libulockmgr\n", argv[0]); - return 1; -}