Skip to content

Commit

Permalink
mount.zfs: use getopt_long instead of getopt to guarantee permutation…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
leahneukirchen authored and behlendorf committed Jan 25, 2016
1 parent 91d8884 commit d93b45a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/mount_zfs/mount_zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <sys/stat.h>
#include <libzfs.h>
#include <locale.h>
#include <getopt.h>

#define ZS_COMMENT 0x00000000 /* comment */
#define ZS_ZFSUTIL 0x00000001 /* caller is zfs(8) */
Expand Down Expand Up @@ -387,7 +388,7 @@ main(int argc, char **argv)
opterr = 0;

/* check options */
while ((c = getopt(argc, argv, "sfnvo:h?")) != -1) {
while ((c = getopt_long(argc, argv, "sfnvo:h?", 0, 0)) != -1) {
switch (c) {
case 's':
sloppy = 1;
Expand Down

0 comments on commit d93b45a

Please sign in to comment.