#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #define bail(msg) \ do { printf("mount_to_symlink: %s: %m\n", msg); exit(1); } while (0) int main(int argc, char **argv) { struct stat stat = {}; char *mnt, *mnt_fdpath; int mnt_fd; if (argc != 2) bail("need argument"); mnt = argv[1]; // open mountpoint fd mnt_fd = open(mnt, O_PATH | O_CLOEXEC | O_NOFOLLOW); if (mnt_fd < 0) bail("open(, O_PATH|O_NOFOLLOW)"); // get fdpaths asprintf(&mnt_fdpath, "/proc/self/fd/%d", mnt_fd); // try to mount umount2(mnt_fdpath, MNT_DETACH); printf("umount2(%s, MNT_DETACH) = %m (%d)\n", mnt, -errno); return 0; }