[Cluster-devel] [PATCH 2/3] mkfs: Remove unneeded open/close fd test from are_you_sure()
Carlos Maiolino
cmaiolino at redhat.com
Tue Sep 27 16:08:22 UTC 2011
are_you_sure() function should not make an open/close
test on the underlying device. The pourpose of this
function is just to ask a yes/no question to the user.
If we need a function to do this test, we should create
a new function with its specific pourpose.
This patch also fix a call to are_you_sure() function and
move the are_you_sure() function to the begining of the
file, allowing it to be used in another part of the code
Signed-off-by: Carlos Maiolino <cmaiolino at redhat.com>
---
gfs2/mkfs/main_mkfs.c | 75 ++++++++++++++++++++++--------------------------
1 files changed, 34 insertions(+), 41 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index cc678fe..8802ef7 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -289,6 +289,39 @@ static void test_locking(char *lockproto, char *locktable)
}
}
+/**
+ * are_you_sure - protect lusers from themselves
+ * @sdp: the command line
+ *
+ */
+
+static void are_you_sure(void)
+{
+ char *line = NULL;
+ size_t len = 0;
+ int ret = -1;
+ int res = 0;
+
+ do{
+ printf( _("Are you sure you want to proceed? [y/n]"));
+ ret = getline(&line, &len, stdin);
+ res = rpmatch(line);
+
+ if (res > 0){
+ free(line);
+ return;
+ }
+ if (!res){
+ printf("\n");
+ die( _("aborted\n"));
+ }
+
+ }while(ret >= 0);
+
+ if(line)
+ free(line);
+}
+
static void verify_bsize(struct gfs2_sbd *sdp)
{
unsigned int x;
@@ -448,46 +481,6 @@ fail:
exit(execv(args[0], args));
}
-/**
- * are_you_sure - protect lusers from themselves
- * @sdp: the command line
- *
- */
-
-static void are_you_sure(struct gfs2_sbd *sdp)
-{
- char *line = NULL;
- size_t len = 0;
- int fd;
- int ret = -1;
- int res = 0;
-
- fd = open(sdp->device_name, O_RDONLY|O_CLOEXEC);
- if (fd < 0)
- die( _("Error: device %s not found.\n"), sdp->device_name);
- printf( _("This will destroy any data on %s.\n"), sdp->device_name);
- check_dev_content(sdp->device_name);
- close(fd);
-
- do{
- printf( _("Are you sure you want to proceed? [y/n]"));
- ret = getline(&line, &len, stdin);
- res = rpmatch(line);
-
- if (res > 0){
- free(line);
- return;
- }
- if (!res){
- printf("\n");
- die( _("aborted\n"));
- }
-
- }while(ret >= 0);
-
- if(line)
- free(line);
-}
/**
* print_results - print out summary information
@@ -576,7 +569,7 @@ void main_mkfs(int argc, char *argv[])
}
if (!sdp->override)
- are_you_sure(sdp);
+ are_you_sure();
if (!S_ISREG(st_buf.st_mode) && device_topology(sdp)) {
fprintf(stderr, _("Device topology error\n"));
--
1.7.6
More information about the Cluster-devel
mailing list