| Index: b/lib/helper.c |
| =================================================================== |
| --- a/lib/helper.c |
| +++ b/lib/helper.c |
| @@ -139,6 +139,23 @@ void fuse_cmdline_help(void) |
| " allowed (default: 10)\n"); |
| } |
| |
| +/* In case if fuse daemon exited abnormally (e.g. SIGKILL) |
| + * then mountpoint is left in inconsistent state. |
| + * This function checks if mountpoint in such state and unmounts it. |
| + */ |
| +static int check_mountpoint(const char *mount) |
| +{ |
| + struct stat buff; |
| + if (stat(mount, &buff) == -1 && errno == ENOTCONN) { |
| + fprintf(stderr, "fuse: mountpoint '%s' is in inconsistent state. " |
| + "It looks like it was not unmounted correctly. " |
| + "Unmounting it now.\n", mount); |
| + fuse_kern_unmount(mount, -1); |
| + return 1; |
| + } |
| + return 0; |
| +} |
| + |
| static int fuse_helper_opt_proc(void *data, const char *arg, int key, |
| struct fuse_args *outargs) |
| { |
| @@ -152,6 +169,7 @@ static int fuse_helper_opt_proc(void *da |
| return fuse_opt_add_opt(&opts->mountpoint, arg); |
| } |
| |
| + check_mountpoint(arg); |
| char mountpoint[PATH_MAX] = ""; |
| if (realpath(arg, mountpoint) == NULL) { |
| fuse_log(FUSE_LOG_ERR, |
| @@ -245,7 +263,9 @@ int fuse_daemonize(int foreground) |
| case 0: |
| break; |
| default: |
| - (void) read(waiter[0], &completed, sizeof(completed)); |
| + if (read(waiter[0], &completed, sizeof(completed)) == -1) { |
| + perror("fuse_daemonize(parent): pipe read"); |
| + } |
| _exit(0); |
| } |
| |
| @@ -267,7 +287,9 @@ int fuse_daemonize(int foreground) |
| |
| /* Propagate completion of daemon initialization */ |
| completed = 1; |
| - (void) write(waiter[1], &completed, sizeof(completed)); |
| + if (write(waiter[1], &completed, sizeof(completed)) == -1) { |
| + perror("fuse_daemonize(child): pipe write"); |
| + } |
| close(waiter[0]); |
| close(waiter[1]); |
| } else { |
| @@ -320,6 +342,7 @@ int fuse_main_real(int argc, char *argv[ |
| goto out1; |
| } |
| |
| + check_mountpoint(opts.mountpoint); |
| if (fuse_mount(fuse,opts.mountpoint) != 0) { |
| res = 4; |
| goto out2; |