]> granicus.if.org Git - zfs/commitdiff
Fix zhack argument processing
authorBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 31 Aug 2016 01:56:36 +0000 (18:56 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 31 Aug 2016 21:32:46 +0000 (14:32 -0700)
The argument processing is zhack makes the assumption that getopt()
will not permute argv.  This isn't true for the GNU implementation of
getopt() unless the optstring is prefixed with a '+'.  In which case
this is equivalent to setting the POSIXLY_CORRECT environment variable

In addition, update the usage() and optstrings to reflect the existing
supported options.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: liaoyuxiangqin <guo.yong33@zte.com.cn>
Closes #5047

cmd/zhack/zhack.c
tests/runfiles/linux.run

index cc4f174c661e9d40ecea8c7e63cea1ca74fb7a31..e76945141afbda96984d9e2dae38bedd636a42b7 100644 (file)
@@ -69,9 +69,10 @@ usage(void)
        (void) fprintf(stderr,
            "    feature stat <pool>\n"
            "        print information about enabled features\n"
-           "    feature enable [-d desc] <pool> <feature>\n"
+           "    feature enable [-r] [-d desc] <pool> <feature>\n"
            "        add a new enabled feature to the pool\n"
            "        -d <desc> sets the feature's description\n"
+           "        -r set read-only compatible flag for feature\n"
            "    feature ref [-md] <pool> <feature>\n"
            "        change the refcount on the given feature\n"
            "        -d decrease instead of increase the refcount\n"
@@ -318,7 +319,7 @@ zhack_do_feature_enable(int argc, char **argv)
        feature.fi_feature = SPA_FEATURE_NONE;
 
        optind = 1;
-       while ((c = getopt(argc, argv, "rmd:")) != -1) {
+       while ((c = getopt(argc, argv, "+rd:")) != -1) {
                switch (c) {
                case 'r':
                        feature.fi_flags |= ZFEATURE_FLAG_READONLY_COMPAT;
@@ -416,7 +417,7 @@ zhack_do_feature_ref(int argc, char **argv)
        feature.fi_feature = SPA_FEATURE_NONE;
 
        optind = 1;
-       while ((c = getopt(argc, argv, "md")) != -1) {
+       while ((c = getopt(argc, argv, "+md")) != -1) {
                switch (c) {
                case 'm':
                        feature.fi_flags |= ZFEATURE_FLAG_MOS;
@@ -522,7 +523,7 @@ main(int argc, char **argv)
        dprintf_setup(&argc, argv);
        zfs_prop_init();
 
-       while ((c = getopt(argc, argv, "c:d:")) != -1) {
+       while ((c = getopt(argc, argv, "+c:d:")) != -1) {
                switch (c) {
                case 'c':
                        g_importargs.cachefile = optarg;
index 5685ea21ba780d217d44c70534a4ed326b74bd22..783eef94f4be0d3ee7627d4d217f19ea104c5faa 100644 (file)
@@ -295,7 +295,6 @@ tests = ['zpool_history_001_neg', 'zpool_history_002_pos']
 # DISABLED:
 # zpool_import_012_pos - sharenfs issue
 # zpool_import_all_001_pos - partition issue
-# zpool_import_features_003_pos - zhack: invalid option -- 'r'
 [tests/functional/cli_root/zpool_import]
 tests = ['zpool_import_001_pos', 'zpool_import_002_pos',
     'zpool_import_003_pos', 'zpool_import_004_pos', 'zpool_import_005_pos',
@@ -303,7 +302,7 @@ tests = ['zpool_import_001_pos', 'zpool_import_002_pos',
     'zpool_import_009_neg', 'zpool_import_010_pos', 'zpool_import_011_neg',
     'zpool_import_013_neg',
     'zpool_import_features_001_pos', 'zpool_import_features_002_neg',
-    'zpool_import_missing_001_pos',
+    'zpool_import_features_003_pos','zpool_import_missing_001_pos',
     'zpool_import_missing_002_pos', 'zpool_import_missing_003_pos',
     'zpool_import_rename_001_pos']