Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 May 2014 16:29:02 +0000 (UTC)
From:      Marius Strobl <marius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r265454 - head/sbin/gvinum
Message-ID:  <201405061629.s46GT2j8001722@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marius
Date: Tue May  6 16:29:02 2014
New Revision: 265454
URL: http://svnweb.freebsd.org/changeset/base/265454

Log:
  - Allow foot shooting with the resetconfig command via the -f option.
  - Fix typos preventing -f to actually work with the create command.
  - Initialize flags to zero rather than using stack garbage when handling
    the grow command.
  
  MFC after:	3 days
  Sponsored by:	Bally Wulff Games & Entertainment GmbH

Modified:
  head/sbin/gvinum/gvinum.8
  head/sbin/gvinum/gvinum.c

Modified: head/sbin/gvinum/gvinum.8
==============================================================================
--- head/sbin/gvinum/gvinum.8	Tue May  6 15:44:46 2014	(r265453)
+++ head/sbin/gvinum/gvinum.8	Tue May  6 16:29:02 2014	(r265454)
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd October 1, 2013
+.Dd May 6, 2014
 .Dt GVINUM 8
 .Os
 .Sh NAME
@@ -168,7 +168,7 @@ the beginning of the plex if the
 .Fl f
 flag is specified, or otherwise at the location of the parity check pointer.
 All subdisks in the plex must be up for a parity check.
-.It Ic resetconfig
+.It Ic resetconfig Oo Fl f Oc
 Reset the complete
 .Nm
 configuration.

Modified: head/sbin/gvinum/gvinum.c
==============================================================================
--- head/sbin/gvinum/gvinum.c	Tue May  6 15:44:46 2014	(r265453)
+++ head/sbin/gvinum/gvinum.c	Tue May  6 16:29:02 2014	(r265454)
@@ -71,7 +71,7 @@ void	gvinum_parityop(int, char **, int);
 void	gvinum_printconfig(int, char **);
 void	gvinum_raid5(int, char **);
 void	gvinum_rename(int, char **);
-void	gvinum_resetconfig(void);
+void	gvinum_resetconfig(int, char **);
 void	gvinum_rm(int, char **);
 void	gvinum_saveconfig(void);
 void	gvinum_setstate(int, char **);
@@ -193,8 +193,8 @@ gvinum_create(int argc, char **argv)
 			flags |= GV_FLAG_F;
 		/* Else it must be a file. */
 		} else {
-			if ((tmp = fopen(argv[1], "r")) == NULL) {
-				warn("can't open '%s' for reading", argv[1]);
+			if ((tmp = fopen(argv[i], "r")) == NULL) {
+				warn("can't open '%s' for reading", argv[i]);
 				return;
 			}
 		}	
@@ -723,7 +723,7 @@ gvinum_help(void)
 	    "        Change the name of the specified object.\n"
 	    "rebuildparity plex [-f]\n"
 	    "        Rebuild the parity blocks of a RAID-5 plex.\n"
-	    "resetconfig\n"
+	    "resetconfig [-f]\n"
 	    "        Reset the complete gvinum configuration\n"
 	    "rm [-r] [-f] volume | plex | subdisk | drive\n"
 	    "        Remove an object.\n"
@@ -1102,26 +1102,40 @@ gvinum_rm(int argc, char **argv)
 }
 
 void
-gvinum_resetconfig(void)
+gvinum_resetconfig(int argc, char **argv)
 {
 	struct gctl_req *req;
 	const char *errstr;
 	char reply[32];
+	int flags, i;
 
-	if (!isatty(STDIN_FILENO)) {
-		warn("Please enter this command from a tty device\n");
-		return;
+	flags = 0;
+	while ((i = getopt(argc, argv, "f")) != -1) {
+		switch (i) {
+		case 'f':
+			flags |= GV_FLAG_F;
+			break;
+		default:
+			warn("invalid flag: %c", i);
+			return;
+		}
 	}
-	printf(" WARNING!  This command will completely wipe out your gvinum"
-	    "configuration.\n"
-	    " All data will be lost.  If you really want to do this,"
-	    " enter the text\n\n"
-	    " NO FUTURE\n"
-	    " Enter text -> ");
-	fgets(reply, sizeof(reply), stdin);
-	if (strcmp(reply, "NO FUTURE\n")) {
-		printf("\n No change\n");
-		return;
+	if ((flags & GV_FLAG_F) == 0) {
+		if (!isatty(STDIN_FILENO)) {
+			warn("Please enter this command from a tty device\n");
+			return;
+		}
+		printf(" WARNING!  This command will completely wipe out"
+		    " your gvinum configuration.\n"
+		    " All data will be lost.  If you really want to do this,"
+		    " enter the text\n\n"
+		    " NO FUTURE\n"
+		    " Enter text -> ");
+		fgets(reply, sizeof(reply), stdin);
+		if (strcmp(reply, "NO FUTURE\n")) {
+			printf("\n No change\n");
+			return;
+		}
 	}
 	req = gctl_get_handle();
 	gctl_ro_param(req, "class", -1, "VINUM");
@@ -1262,6 +1276,7 @@ gvinum_grow(int argc, char **argv)
 	const char *errstr;
 	int drives, volumes, plexes, subdisks, flags;
 
+	flags = 0;
 	drives = volumes = plexes = subdisks = 0;
 	if (argc < 3) {
 		warnx("usage:\tgrow plex drive\n");
@@ -1372,7 +1387,7 @@ parseline(int argc, char **argv)
 	else if (!strcmp(argv[0], "rename"))
 		gvinum_rename(argc, argv);
 	else if (!strcmp(argv[0], "resetconfig"))
-		gvinum_resetconfig();
+		gvinum_resetconfig(argc, argv);
 	else if (!strcmp(argv[0], "rm"))
 		gvinum_rm(argc, argv);
 	else if (!strcmp(argv[0], "saveconfig"))



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405061629.s46GT2j8001722>