Variant for chroot ?
Variant for chroot ?
Posted Mar 13, 2026 4:34 UTC (Fri) by wtarreau (subscriber, #51152)Parent article: Practical uses for a null filesystem
What I'd like to see would be a variant of chroot() which would automatically create such a nullfs, enter it and lazy-unmount it so that once the caller dies, it's automatically unmounted. It would allow to completely isolate the caller. I'm using chroot() to empty directories with no permissions as an isolation for daemons and it works reasonably well because you cannot easily escape it (nowhere to mkdir+chroot+cd again). Of course the daemon must not hold any FD pointing to an external directory! In this case we could imagine something like this:
#define NULLFS_DIR (const char *)1
chroot(NULLFS_DIR); // mount nullfs and mark it lazy-umount (will it work before chdir()?)
chdir("/");
