[DRBD-cvs] svn commit by phil - r2282 - trunk/user - Von: "Graham, Simon" <Simon.Graham@stratus.com> Current

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Mon Jul 17 10:25:52 CEST 2006


Author: phil
Date: 2006-07-17 10:25:51 +0200 (Mon, 17 Jul 2006)
New Revision: 2282

Modified:
   trunk/user/drbdmeta.c
Log:
Von: "Graham, Simon" <Simon.Graham at stratus.com>

Currently, drbdmeta always prompts for confirmation before updating
meta-data - this is fine for interactive use but if you want to
initialize meta-data programmatically (as part of provisioning a box for
example) it causes problems. I would propose adding a "-force" option to
drbdmeta that overrides this and assumes a 'yes' answer to all
questions.



Modified: trunk/user/drbdmeta.c
===================================================================
--- trunk/user/drbdmeta.c	2006-07-17 07:35:49 UTC (rev 2281)
+++ trunk/user/drbdmeta.c	2006-07-17 08:25:51 UTC (rev 2282)
@@ -36,6 +36,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <errno.h>
+#include <getopt.h>
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -50,6 +51,13 @@
 extern FILE* yyin;
 YYSTYPE yylval;
 
+int     force = 0;
+
+struct option metaopt[] = {
+    { "force",  no_argument,    0, 'f' },
+    { NULL,     0,              0, 0 },
+};
+
 #define PAGE_SIZE  getpagesize()
 #define PAGE_MASK  (~(PAGE_SIZE-1))
 #define PAGE_ALIGN(addr)	(((addr)+PAGE_SIZE-1)&PAGE_MASK)
@@ -792,11 +800,19 @@
 	size_t n = 0;
 	int ok;
 
-	printf("\n%s\n[need to type '%s' to confirm] ", text, yes);
-	ok = getline(&answer,&n,stdin) == N &&
-	     strncmp(answer,yes,N-1) == 0;
-	if (answer) free(answer);
-	printf("\n");
+        printf("\n%s\n", text);
+
+        if (force) {
+            printf("*** confirmation forced via --force option ***\n");
+            ok = 1;
+        }
+        else {
+            printf("[need to type '%s' to confirm] ", yes);
+            ok = getline(&answer,&n,stdin) == N &&
+                strncmp(answer,yes,N-1) == 0;
+            if (answer) free(answer);
+            printf("\n");
+        }
 	return ok;
 }
 
@@ -2278,7 +2294,7 @@
 	size_t i;
 
 	printf
-	    ("\nUSAGE: %s DEVICE FORMAT [FORMAT ARGS...] COMMAND [CMD ARGS...]\n",
+	    ("\nUSAGE: %s [--force] DEVICE FORMAT [FORMAT ARGS...] COMMAND [CMD ARGS...]\n",
 	     progname);
 
 	printf("\nFORMATS:\n");
@@ -2408,14 +2424,32 @@
 	if (argc < 4)
 		print_usage_and_exit();
 
+        /* Check for options (e.g. --force) */
+        while (1) {
+            int c = getopt_long(argc,argv,make_optstring(metaopt,0),metaopt,0);
+
+            if (c == -1)
+                break;
+
+            switch (c) {
+            case 'f':
+                force = 1;
+                break;
+            default:
+                print_usage_and_exit();
+                break;
+            }
+        }
+
+        // Next argument to process is specified by optind...
+        ai = optind;
+
 	/* FIXME should have a "drbd_cfg_new" and a "drbd_cfg_free"
 	 * function, maybe even a "get" and "put" ?
 	 */
 	cfg = calloc(1, sizeof(struct format));
-	cfg->drbd_dev_name = argv[1];
+	cfg->drbd_dev_name = argv[ai++];
 
-	/* argv[0] is progname, argv[1] was drbd_dev_name. */
-	ai = 2;
 	if (parse_format(cfg, argv + ai, argc - ai, &ai)) {
 		/* parse has already printed some error message */
 		exit(20);



More information about the drbd-cvs mailing list