void fuse_kern_unmount(const char *mountpoint, int fd)
{
    int res;
#ifdef __SOLARIS__
    int pid;
#endif /* __SOLARIS__ */

    if (!mountpoint)
        return;

    if (fd != -1) {
        struct pollfd pfd;

        pfd.fd = fd;
        pfd.events = 0;
        res = poll(&pfd, 1, 0);
        /* If file poll returns POLLERR on the device file descriptor,
           then the filesystem is already unmounted */
        if (res == 1 && (pfd.revents & POLLERR))
            return;
              /*
               * Need to close file descriptor, otherwise synchronous umount
               * would recurse into filesystem, and deadlock.
               */
        close(fd);
    }
#ifndef __SOLARIS__
    fusermount(1, 0, 1, "", mountpoint);
#else /* __SOLARIS__ */
    if (geteuid() == 0) {
        fuse_mnt_umount("fuse", mountpoint, 1);
        return;
    }

    res = umount2(mountpoint, 2);
    if (res == 0)
        return;

    pid = fork();
    if(pid == -1)
        return;

    if(pid == 0) {
        const char *argv[] =
            { FUSERMOUNT_PROG, "-u", "-q", "-z", "--", mountpoint, NULL };

        exec_fusermount(argv);
        _exit(1);
    }
    waitpid(pid, NULL, 0);
#endif /* __SOLARIS__ */
}
void fuse_kern_unmount(const char *mountpoint, int fd)
{
    int res;
#ifdef __SOLARIS__
    int pid;
#endif  

    if (!mountpoint)
        return;

    if (fd != -1) {
        struct pollfd pfd;

        pfd.fd = fd;
        pfd.events = 0;
        res = poll(&pfd, 1, 0);
         
        if (res == 1 && (pfd.revents & POLLERR))
            return;
               
        close(fd);
    }
#ifndef __SOLARIS__
    fusermount(1, 0, 1, "", mountpoint);
#else  
    if (geteuid() == 0) {
        fuse_mnt_umount("fuse", mountpoint, 1);
        return;
    }

    res = umount2(mountpoint, 2);
    if (res == 0)
        return;

    pid = fork();
    if(pid == -1)
        return;

    if(pid == 0) {
        const char *argv[] =
            { FUSERMOUNT_PROG, "-u", "-q", "-z", "--", mountpoint, NULL };

        exec_fusermount(argv);
        _exit(1);
    }
    waitpid(pid, NULL, 0);
#endif  
}