Created attachment 189116 [details]
Fixes the issue.
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
automount: cannot mount map -media on /mnt/media: No such file or directory
[root@]~# mount | grep autofs
[root@]~# ls mnt
[root@]~# tree mnt
Assign it to -fs list.
I just tripped over this too. As an alternative to adding chdir("/") we could make create_directory take an "int absolute" parameter and anchor the paths being created in that case.
trasz, any preference of how you'd like this to be fixed?
The create_directory() should always be passed an absolute path. There's even the assert, in usr.sbin/autofs/common.c:create_directory():
assert(path == '/');
Thus, my preferred fix would be to figure out how the path ends up being relative, and fixing that.
That's easy then:
140 * +1 to skip the leading slash.
142 copy = tofree = checked_strdup(path + 1);
We're not copying the leading slash for some reason. Maybe because you didn't want to try to mkdir("/")?
I think you're right regarding the leading slash. I have no idea why it's like this, I'm afraid - it ignores EEXIST couple of lines below...
Can you commit the fix ?
I ported and maintain autofs in NetBSD and DragonFlyBSD, with the chdir("/") patch.
I'll replace it with above.
The leading slash is ignored because otherwise strsep() will return '\0' on
concat() doesn't concatenate the separator when either of the strings passed in is empty. In this case, partial is empty on the first iteration, hence the separator not being included in the first pass.
There's a few different ways to tackle this, heres one with a bit more description:
*** Bug 246496 has been marked as a duplicate of this bug. ***