Skip to contentSkip to conversation

mkfs.gfs2: make are you sure EOF happy

PATCH New Alexander Aring 2 participants 2 messages Jan 13, 2021 – Jan 14, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.gfs2: make are you sure EOF happy

This patch adds a check for getline() error, as the manpage states out that -1 is returned in EOF case we answer such case and possible other errors with no. If you currently press ctrl-d during this question an endless loop of asking this question over and over again will occur. However this patch changes to handle errors with no and prints a newline so the user have a new clean shell prompt afterwards. If getline reads zero characters .e.g '\n', the question is if we are sure is asked again.

---
 gfs2/mkfs/main_mkfs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
gfs2/mkfs/main_mkfs.c +6 -1
index 5e34ca1f..e6fc6532 100644
@@ -528,9 +528,14 @@ static int are_you_sure(void)
 		   `locale -k noexpr` */
 		printf( _("Are you sure you want to proceed? [y/n] "));
 		ret = getline(&line, &len, stdin);
+		if (ret < 0) {
+			printf("\n");
+			free(line);
+			return 0;
+		}
 		res = rpmatch(line);
 		free(line);
-		if (ret <= 0)
+		if (ret == 0)
 			continue;
 		if (res == 1) /* Yes */
 			return 1;
Signature · 1 line
2.26.2
Applied
#1 lore raw

PATCH 1/1 mkfs.gfs2: make are you sure EOF happy

Quoted 8 lines · Alexander Aring

This patch adds a check for getline() error, as the manpage states out that -1 is returned in EOF case we answer such case and possible other errors with no. If you currently press ctrl-d during this question an endless loop of asking this question over and over again will occur. However this patch changes to handle errors with no and prints a newline so the user have a new clean shell prompt afterwards. If getline reads zero characters .e.g '\n', the question is if we are sure is asked again.

Quoted 4 lines
---
  gfs2/mkfs/main_mkfs.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)

Applied, thanks Alex.

Andy

Quoted 22 lines
gfs2/mkfs/main_mkfs.c +6 -1
index 5e34ca1f..e6fc6532 100644
@@ -528,9 +528,14 @@ static int are_you_sure(void)
  		   `locale -k noexpr` */
  		printf( _("Are you sure you want to proceed? [y/n] "));
  		ret = getline(&line, &len, stdin);
+		if (ret < 0) {
+			printf("\n");
+			free(line);
+			return 0;
+		}
  		res = rpmatch(line);
  		free(line);
-		if (ret <= 0)
+		if (ret == 0)
  			continue;
  		if (res == 1) /* Yes */
  			return 1;