]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Improve option parsing
authorNeil Brown <neilb@suse.de>
Mon, 5 Dec 2005 05:54:33 +0000 (05:54 +0000)
committerNeil Brown <neilb@suse.de>
Mon, 5 Dec 2005 05:54:33 +0000 (05:54 +0000)
stuff

====Do Not Remove====
Status: ok
Signed-off-by: Neil Brown <neilb@suse.de>
Assemble.c
ChangeLog
Makefile
ReadMe.c
mdadm.c
mdadm.h

index d251500d3f0750a746134075b7e625b2ed00e60e..c78a1b16c6067495a2789873b119db259afcb32e 100644 (file)
@@ -204,11 +204,9 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                        /* Impossible! */
                        fprintf(stderr, Name ": fstat failed for %s: %s\n",
                                devname, strerror(errno));
-                       close(dfd);
                } else if ((stb.st_mode & S_IFMT) != S_IFBLK) {
                        fprintf(stderr, Name ": %s is not a block device.\n",
                                devname);
-                       close(dfd);
                } else if (!tst && (tst = guess_super(dfd)) == NULL) {
                        if ((inargv && verbose >= 0) || verbose > 0)
                                fprintf(stderr, Name ": no recogniseable superblock\n");
@@ -216,11 +214,10 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                        if ((inargv && verbose >= 0) || verbose > 0)
                                fprintf( stderr, Name ": no RAID superblock on %s\n",
                                         devname);
-                       close(dfd);
                } else {
                        tst->ss->getinfo_super(&info, &ident2, super);
-                       close(dfd);
                }
+               if (dfd >= 0) close(dfd);
 
                if (ident->uuid_set &&
                    (!super || same_uuid(info.uuid, ident->uuid, tst->ss->swapuuid)==0)) {
index 76cc6eaf7a03e21e2bc22a8d7d7b2e355eb6fc04..141e1b2bfeda11e48001376852e73c8a76886e3f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@ Changes Prior to this release
     -   Support little-endian (Rather than hostendian) bitmaps.
     -   Return correct error code from 'mdadm -S'
     -   Remove extra blank line from 'mdadm -Eb' output.
+    -   Improve option parsing so that -a and -b do not have
+       optional arguements: the arg is either required or not
+       depending on context.
     -   Allow scanning of devices listed in /proc/partitions even
        if they don't appear in /dev.
 
index 05b653bdaa471b57cb1ad97f75e979469d04cb58..81102ea8e3aa8a9eb415b3565bd0867949d060c8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -98,7 +98,7 @@ mdassemble : $(ASSEMBLE_SRCS) mdadm.h
 
 mdassemble.static : $(ASSEMBLE_SRCS) mdadm.h
        rm -f $(OBJS)
-       $(CC) $(LDFLAGS) $(ASSEMBLE_FLAGS) -static -o mdassemble $(ASSEMBLE_SRCS)
+       $(CC) $(LDFLAGS) $(ASSEMBLE_FLAGS) -static -o mdassemble.static $(ASSEMBLE_SRCS)
 
 mdassemble.uclibc : $(ASSEMBLE_SRCS) mdadm.h
        rm -f $(OBJS)
index cd69a1c6ebc587285c89ccf7b7aaf13d46cc7e10..81766ddd8e895eac60a75fa4c22498463954e9a0 100644 (file)
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -91,7 +91,8 @@ char Version[] = Name " - v2.1 - 12 September 2005\n";
  *     At the time if writing, there is only minimal support.
  */
 
-char short_options[]="-ABCDEFGQhVXvqb::c:i:l:p:m:n:x:u:c:d:z:U:sa::rfRSow1te:";
+char short_options[]="-ABCDEFGQhVXvqbc:i:l:p:m:n:x:u:c:d:z:U:sarfRSow1te:";
+char short_bitmap_auto_options[]="-ABCDEFGQhVXvqb:c:i:l:p:m:n:x:u:c:d:z:U:sa:rfRSow1te:";
 struct option long_options[] = {
     {"manage",    0, 0, '@'},
     {"misc",      0, 0, '#'},
diff --git a/mdadm.c b/mdadm.c
index 8af61e9627df5e5ea241e0f5ab30e8a74ee82935..80873b221697e399232443511927890b6faa5e50 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -93,6 +93,7 @@ int main(int argc, char *argv[])
        struct supertype *ss = NULL;
        int writemostly = 0;
        int re_add = 0;
+       char *shortopt = short_options;
 
        int copies;
 
@@ -113,7 +114,7 @@ int main(int argc, char *argv[])
 
        while ((option_index = -1) ,
               (opt=getopt_long(argc, argv,
-                               short_options, long_options,
+                               shortopt, long_options,
                                &option_index)) != -1) {
                int newmode = mode;
                /* firstly, some mode-independant options */
@@ -150,6 +151,10 @@ int main(int argc, char *argv[])
                        if (mode == ASSEMBLE || mode == BUILD || mode == CREATE || mode == GROW)
                                break; /* b means bitmap */
                        brief = 1;
+                       if (optarg) {
+                               fprintf(stderr, Name ": -b cannot have any extra immediately after it, sorry.\n");
+                               exit(2);
+                       }
                        continue;
 
                case ':':
@@ -164,19 +169,24 @@ int main(int argc, char *argv[])
 
                switch(opt) {
                case '@': /* just incase they say --manage */
-                       newmode = MANAGE; break;
+                       newmode = MANAGE;
+                       shortopt = short_bitmap_auto_options;
+                       break;
                case 'a':
                case 'r':
                case 'f':
                case 6: /* re-add */
-                       if (!mode) newmode = MANAGE; 
+                       if (!mode) {
+                               newmode = MANAGE;
+                               shortopt = short_bitmap_auto_options;
+                       }
                        break;
 
-               case 'A': newmode = ASSEMBLE; break;
-               case 'B': newmode = BUILD; break;
-               case 'C': newmode = CREATE; break;
+               case 'A': newmode = ASSEMBLE; shortopt = short_bitmap_auto_options; break;
+               case 'B': newmode = BUILD; shortopt = short_bitmap_auto_options; break;
+               case 'C': newmode = CREATE; shortopt = short_bitmap_auto_options; break;
                case 'F': newmode = MONITOR;break;
-               case 'G': newmode = GROW; break;
+               case 'G': newmode = GROW; shortopt = short_bitmap_auto_options; break;
 
                case '#':
                case 'D':
diff --git a/mdadm.h b/mdadm.h
index 97831b49628b878450cb80fcb4058f8772b07a18..29bbdc48a3d624b657b90845ae39acd3f4dcbd90 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -91,6 +91,7 @@ enum mode {
 };
 
 extern char short_options[];
+extern char short_bitmap_auto_options[];
 extern struct option long_options[];
 extern char Version[], Usage[], Help[], OptionHelp[],
        Help_create[], Help_build[], Help_assemble[], Help_grow[],