If any of the first three file descriptors are closed when squashfuse is
launched, it will get a fd <= 2 when it opens the squashfs image file.
Unfortunately fuse_daemonize() from libfuse unconditionally clobbers fds 0-2
by dup2-ing /dev/null over them. This made the squashfuse image inaccessible
and things went very poorly.
Fix by simply making sure fds 0-2 are open before calling sqfs_ll_open() so
it is guaranteed to get a safe fd.
Reproduction (previously failed with "No such file or directory", now
succeeds):
0<&- squashfuse_ll fs.image /tmp/crap
ls /tmp/crap
If any of the first three file descriptors are closed when squashfuse is launched, it will get a fd <= 2 when it opens the squashfs image file.
Unfortunately fuse_daemonize() from libfuse unconditionally clobbers fds 0-2 by dup2-ing /dev/null over them. This made the squashfuse image inaccessible and things went very poorly.
Fix by simply making sure fds 0-2 are open before calling sqfs_ll_open() so it is guaranteed to get a safe fd.
Reproduction (previously failed with "No such file or directory", now succeeds): 0<&- squashfuse_ll fs.image /tmp/crap ls /tmp/crap