From: Jes Sorensen Date: Wed, 2 Nov 2011 21:06:47 +0000 (+1100) Subject: mdadm: Rearrange option parsing for KillSubarray and UpdateSubarray X-Git-Tag: mdadm-3.2.3~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a53aeec7f333e22682930d8fe228b572b7f55c9;p=thirdparty%2Fmdadm.git mdadm: Rearrange option parsing for KillSubarray and UpdateSubarray Extracting the 'subarray' arg for these options was being done at the wrong place which lead to the code being a bit confusing and looking wrong. So reformat that code a bit better and move the extraction of 'subarray' down to the main parsing of these options rather than the mode setting. Signed-off-by: NeilBrown --- diff --git a/mdadm.c b/mdadm.c index 56de7b7e..8e0ce186 100644 --- a/mdadm.c +++ b/mdadm.c @@ -212,13 +212,17 @@ int main(int argc, char *argv[]) case 'I': newmode = INCREMENTAL; shortopt = short_bitmap_auto_options; break; case AutoDetect: - newmode = AUTODETECT; break; + newmode = AUTODETECT; + break; case MiscOpt: case 'D': case 'E': case 'X': - case 'Q': newmode = MISC; break; + case 'Q': + newmode = MISC; + break; + case 'R': case 'S': case 'o': @@ -229,17 +233,15 @@ int main(int argc, char *argv[]) case DetailPlatform: case KillSubarray: case UpdateSubarray: - if (opt == KillSubarray || opt == UpdateSubarray) { - if (subarray) { - fprintf(stderr, Name ": subarray can only" - " be specified once\n"); - exit(2); - } - subarray = optarg; - } case UdevRules: - case 'K': if (!mode) newmode = MISC; break; - case NoSharing: newmode = MONITOR; break; + case 'K': + if (!mode) + newmode = MISC; + break; + + case NoSharing: + newmode = MONITOR; + break; } if (mode && newmode == mode) { /* everybody happy ! */ @@ -924,6 +926,14 @@ int main(int argc, char *argv[]) case O(MISC, DetailPlatform): case O(MISC, KillSubarray): case O(MISC, UpdateSubarray): + if (opt == KillSubarray || opt == UpdateSubarray) { + if (subarray) { + fprintf(stderr, Name ": subarray can only" + " be specified once\n"); + exit(2); + } + subarray = optarg; + } if (devmode && devmode != opt && (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) { fprintf(stderr, Name ": --examine/-E cannot be given with ");