mount.zfs: use getopt_long instead of getopt to guarantee permutation 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
This commit is contained in:
Christian Neukirchen 2016-01-23 21:37:35 +01:00 committed by Brian Behlendorf
parent 6f7acfc9c9
commit a5ab85824d
1 changed files with 2 additions and 1 deletions

View File

@ -32,6 +32,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <libzfs.h> #include <libzfs.h>
#include <locale.h> #include <locale.h>
#include <getopt.h>
#define ZS_COMMENT 0x00000000 /* comment */ #define ZS_COMMENT 0x00000000 /* comment */
#define ZS_ZFSUTIL 0x00000001 /* caller is zfs(8) */ #define ZS_ZFSUTIL 0x00000001 /* caller is zfs(8) */
@ -389,7 +390,7 @@ main(int argc, char **argv)
opterr = 0; opterr = 0;
/* check options */ /* check options */
while ((c = getopt(argc, argv, "sfnvo:h?")) != -1) { while ((c = getopt_long(argc, argv, "sfnvo:h?", 0, 0)) != -1) {
switch (c) { switch (c) {
case 's': case 's':
sloppy = 1; sloppy = 1;