usr.sbin/autofs: Make automount(8) call chdir("/") before create_directory()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Fri, 12 Jan 2018 19:46:53 +0000 (21:46 +0200)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Fri, 12 Jan 2018 20:01:54 +0000 (22:01 +0200)
commit108ed43a1e5e7ff8f890085e206d970562bf4a7c
tree354a49cd99c4aae0b1e080b21773648150a12147
parent9a87b1176ceb8af8cd878e1aef5b8ec9122e2f42
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
usr.sbin/autofs/automount.c