Unmount while dav_run_msgloop is still running

This commit is contained in:
wbaumann 2016-04-09 19:43:46 +00:00
parent 5a2e6a0daa
commit dfe67b208a
3 changed files with 27 additions and 7 deletions

View File

@ -1,6 +1,10 @@
ChangeLog for davfs2
--------------------

2016-04-09 Werner Baumann (werner.baumann@onlinehome.de)
* kernel_interface.c, mount_davfs.c:
Unmount while dav_run_msgloop is still running.

2016-04-04 Werner Baumann (werner.baumann@onlinehome.de)
* cache.c, kernel_interface.c:
Fix compiler warnings.

View File

@ -117,6 +117,9 @@ struct create_out {
/* File descriptor of the fuse device. */
static int fuse_device;

/* The mountpoint. */
const char *mountpoint;

/* Buffer used for communication with the kernel module (in and out). */
static size_t buf_size;
static char *buf;
@ -212,6 +215,8 @@ dav_init_kernel_interface(const char *url, const char *mpoint,
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG),
"Initializing kernel interface");

mountpoint = mpoint;

buf_size = args->buf_size * 1024;
if (buf_size < (FUSE_MIN_READ_BUFFER + 1024))
buf_size = FUSE_MIN_READ_BUFFER + 1024;
@ -280,12 +285,14 @@ dav_run_msgloop(volatile int *keep_on_running)
{
dav_register_kernel_interface(&write_dir_entry);

int unmounting = 0;

struct timeval tv;
tv.tv_sec = idle_time;
tv.tv_usec = 0;
time_t last_tidy_cache = time(NULL);

while (*keep_on_running) {
while (1) {

fd_set fds;
FD_ZERO(&fds);
@ -294,6 +301,17 @@ dav_run_msgloop(volatile int *keep_on_running)
if (debug)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "SELECT: %i", ret);

if (!*keep_on_running && !unmounting) {
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("unmounting %s"),
mountpoint);
unmounting = 1;
pid_t pid = fork();
if (pid == 0) {
execl("/bin/umount", "umount", "-il", mountpoint, NULL);
_exit(EXIT_FAILURE);
}
}

if (ret > 0) {
ssize_t bytes_read = read(fuse_device, buf, buf_size);
if (bytes_read <= 0) {
@ -322,6 +340,8 @@ dav_run_msgloop(volatile int *keep_on_running)
}
continue;
} else {
if (errno == EINTR)
continue;
break;
}


View File

@ -363,12 +363,8 @@ main(int argc, char *argv[])
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "Closing");
dav_close_cache(&got_sigterm);
dav_close_webdav();
if (dav_is_mounted()) {
char *prog = xasprintf("/bin/umount -il %s", mpoint);
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("unmounting %s"), mpoint);
if (system(prog) != 0 && dav_is_mounted())
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("unmounting failed"));
}
if (dav_is_mounted())
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("unmounting failed"));
if (debug)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "Removing %s", pidfile);
remove(pidfile);