]> granicus.if.org Git - zfs/commitdiff
mount.zfs: use getopt_long instead of getopt to guarantee permutation of argv.
authorChristian Neukirchen <chneukirchen@gmail.com>
Sat, 23 Jan 2016 20:37:35 +0000 (21:37 +0100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 25 Jan 2016 21:17:18 +0000 (13:17 -0800)
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

cmd/mount_zfs/mount_zfs.c

index e3e8cfc2201557bca7135675cc2ec3d4bda8457a..2fb4d65e92dda54078d7a4641a86d41c99ae302d 100644 (file)
@@ -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) */
@@ -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;