Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mount.zfs argument order breaks on POSIX-conforming getopt #4222

Closed
leahneukirchen opened this issue Jan 14, 2016 · 1 comment
Closed

mount.zfs argument order breaks on POSIX-conforming getopt #4222

leahneukirchen opened this issue Jan 14, 2016 · 1 comment
Milestone

Comments

@leahneukirchen
Copy link
Contributor

The mount.zfs helper program uses getopt(3) to parse its arguments. mount.zfs is called by util-linux with the non-standard order of <spec> <mountpoint> -o <options> which other tools like mount.nfs or sshfs explicitly expect. (This is specified in EXTERNAL HELPERS in util-linux mount(8).)

This is not a problem on glibc since GNU getopt(3) will reorder the arguments. However, alternative libc such as musl libc (or glibc with $POSIXLY_CORRECT set) will not permute argv and fail to parse the -o <options>.

I see two options here:

  • force the first two arguments to be <device> <mountpoint> and use getopt on the rest.
  • use getopt_long instead, which permutes arguments on glibc and musl.

The latter option has been implemented as a patch by Void Linux: https://github.com/voidlinux/void-packages/commit/0203a5aa0f26bb0ef334e09c8736f35275d06e8f

@behlendorf
Copy link
Contributor

Normally I'd suggest avoiding the use of getopt_long() is ZFS since it's a GNU extension and one of our goals is to keep the code as portable as possible. However, mount.zfs is already one of the few bits of Linux specific bit of code so I don't see any harm in updating it as you suggest. Can you open a PR against zfsonlinux/zfs with the voidlinux/void-packages@0203a5a fix. That way we can get it tested, reviewed, and merged.

behlendorf pushed a commit that referenced this issue Jan 29, 2016
… of argv.

mount.zfs is called by convention (and util-linux) with arguments
last, i.e.

  % mount.zfs <dataset> <mountpoint> -o <options>

This is not a problem on glibc since GNU getopt(3) will reorder the
arguments.  However, alternative libc such as musl libc (or glibc with
$POSIXLY_CORRECT set) will not permute argv and fail to parse the -o
<options>.  Use getopt_long so musl will permute arguments.

Signed-off-by: Christian Neukirchen <chneukirchen@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4222
goulvenriou pushed a commit to Alyseo/zfs that referenced this issue Feb 3, 2016
… of argv.

mount.zfs is called by convention (and util-linux) with arguments
last, i.e.

  % mount.zfs <dataset> <mountpoint> -o <options>

This is not a problem on glibc since GNU getopt(3) will reorder the
arguments.  However, alternative libc such as musl libc (or glibc with
$POSIXLY_CORRECT set) will not permute argv and fail to parse the -o
<options>.  Use getopt_long so musl will permute arguments.

Signed-off-by: Christian Neukirchen <chneukirchen@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#4222
Flefebvre pushed a commit to Flefebvre/zfs that referenced this issue Feb 3, 2016
… of argv.

mount.zfs is called by convention (and util-linux) with arguments
last, i.e.

  % mount.zfs <dataset> <mountpoint> -o <options>

This is not a problem on glibc since GNU getopt(3) will reorder the
arguments.  However, alternative libc such as musl libc (or glibc with
$POSIXLY_CORRECT set) will not permute argv and fail to parse the -o
<options>.  Use getopt_long so musl will permute arguments.

Signed-off-by: Christian Neukirchen <chneukirchen@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#4222
Flefebvre pushed a commit to Flefebvre/zfs that referenced this issue Feb 3, 2016
… of argv.

mount.zfs is called by convention (and util-linux) with arguments
last, i.e.

  % mount.zfs <dataset> <mountpoint> -o <options>

This is not a problem on glibc since GNU getopt(3) will reorder the
arguments.  However, alternative libc such as musl libc (or glibc with
$POSIXLY_CORRECT set) will not permute argv and fail to parse the -o
<options>.  Use getopt_long so musl will permute arguments.

Signed-off-by: Christian Neukirchen <chneukirchen@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#4222
Flefebvre pushed a commit to Flefebvre/zfs that referenced this issue Feb 3, 2016
… of argv.

mount.zfs is called by convention (and util-linux) with arguments
last, i.e.

  % mount.zfs <dataset> <mountpoint> -o <options>

This is not a problem on glibc since GNU getopt(3) will reorder the
arguments.  However, alternative libc such as musl libc (or glibc with
$POSIXLY_CORRECT set) will not permute argv and fail to parse the -o
<options>.  Use getopt_long so musl will permute arguments.

Signed-off-by: Christian Neukirchen <chneukirchen@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#4222
@behlendorf behlendorf added this to the 0.6.5.5 milestone Mar 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants