usr.sbin/autofs: Make automount(8) call chdir("/") before create_directory()
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=224601
Unlike automountd where the daemon is daemonized or lesser-daemonized,
an automount process isn't necessarily at /, and this results in
creating unneeded directories at the current directory.
In the example below, mounting autofs on /mnt/media fails because the
command mkdirs mnt/media instead of /mnt/media. If /mnt/media already
exists the command can mount autofs on /mnt/media, but it still mkdirs
unneeded directories mnt/media.
Calling chdir("/") before creation and restoring the directory after
creation avoids this.
--
[root@]~# automount -L
/mnt/media -nosuid -media # indirect map referenced at /etc/auto_master:8
[root@]~# ls mnt
ls: mnt: No such file or directory
[root@]~# automount
automount: cannot mount map -media on /mnt/media: No such file or directory
[root@]~# mount | grep autofs
[root@]~# ls mnt
media
[root@]~# tree mnt
mnt
`-- media