cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH 3/3] mkfs i18n:
@ 2011-09-06 17:41 Carlos Maiolino
  2011-09-06 18:29 ` Bob Peterson
  2011-09-06 19:10 ` Steven Whitehouse
  0 siblings, 2 replies; 7+ messages in thread
From: Carlos Maiolino @ 2011-09-06 17:41 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Use rpmatch() function to get answer to
yes-or-no questions during mkfs confirmation

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
 gfs2/mkfs/main_mkfs.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 4751f19..d68cf98 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -456,8 +456,11 @@ fail:
 
 static void are_you_sure(struct gfs2_sbd *sdp)
 {
-	char input[32];
+	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)
@@ -465,14 +468,25 @@ static void are_you_sure(struct gfs2_sbd *sdp)
 	printf( _("This will destroy any data on %s.\n"), sdp->device_name);
 	check_dev_content(sdp->device_name);
 	close(fd);
-	printf( _("\nAre you sure you want to proceed? [y/n] "));
-	if(!fgets(input, 32, stdin))
-		die( _("unable to read from stdin\n"));
+	
+	do{
+		printf( _("\nAre 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 (input[0] != 'y')
-		die( _("aborted\n"));
-	else
-		printf("\n");
+	if(line)
+		free(line);
 }
 
 /**
-- 
1.7.6



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-09-22  9:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-06 17:41 [Cluster-devel] [PATCH 3/3] mkfs i18n: Carlos Maiolino
2011-09-06 18:29 ` Bob Peterson
2011-09-06 19:10 ` Steven Whitehouse
2011-09-20 17:27   ` Carlos Maiolino
2011-09-21  0:33     ` Carlos Maiolino
2011-09-22  9:47       ` Steven Whitehouse
2011-09-22  9:50     ` Steven Whitehouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).