From 4a257d8c65e0649e3994e15398a416fa408bd8a7 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Thu, 30 Jul 2009 14:46:56 +0000 Subject: [PATCH] Print error when getline() fails (thanks to Ivan Stankovic) git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@76 36d66b0a-2a48-0410-832c-cd162a569da5 --- ChangeLog | 1 + src/cryptsetup.c | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f1aec1..e01bf13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2009-07-30 Milan Broz * Fix errors when compiled with LUKS_DEBUG. + * Print error when getline fails. 2009-07-28 Milan Broz * Pad luks header to 512 sector size. diff --git a/src/cryptsetup.c b/src/cryptsetup.c index af0ea60..179d351 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -79,19 +79,23 @@ static struct action_type { /* Interface Callbacks */ static int yesDialog(char *msg) { - int r = 0; + char *answer = NULL; + size_t size = 0; + int r = 1; + if(isatty(0) && !opt_batch_mode) { - char *answer=NULL; - size_t size=0; - fprintf(stderr,"\nWARNING!\n========\n"); - fprintf(stderr,"%s\n\nAre you sure? (Type uppercase yes): ",msg); - if(getline(&answer,&size,stdin) == -1) + fprintf(stderr, "\nWARNING!\n========\n"); + fprintf(stderr, "%s\n\nAre you sure? (Type uppercase yes): ", msg); + if(getline(&answer, &size, stdin) == -1) { + perror("getline"); + free(answer); return 0; - if(strcmp(answer,"YES\n") == 0) - r = 1; + } + if(strcmp(answer, "YES\n")) + r = 0; free(answer); - } else - r = 1; + } + return r; } -- 2.7.4