summaryrefslogtreecommitdiffstats
path: root/fdisk/cfdisk.c
diff options
context:
space:
mode:
authorFrancesco Cosoleto2010-12-18 19:24:03 +0100
committerKarel Zak2010-12-30 23:57:16 +0100
commit0d8589c56547098d9026856c85dbf0d72d72e36c (patch)
tree886ba5a25ff604fcb5e7e55939e0ae358bda743f /fdisk/cfdisk.c
parentwipefs: fail if more device arguments specified (diff)
downloadkernel-qcow2-util-linux-0d8589c56547098d9026856c85dbf0d72d72e36c.tar.gz
kernel-qcow2-util-linux-0d8589c56547098d9026856c85dbf0d72d72e36c.tar.xz
kernel-qcow2-util-linux-0d8589c56547098d9026856c85dbf0d72d72e36c.zip
cfdisk: close the program when terminal isn't present
cfdisk was getting characters without checking ERR return code, causing an endless while loop in do_curses_fdisk() or in other functions when the terminal is lost. [kzak@redhat.com: - fix coding style, remove CR macro] Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisk/cfdisk.c')
-rw-r--r--fdisk/cfdisk.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c
index 1e078a9fe..866d02af0 100644
--- a/fdisk/cfdisk.c
+++ b/fdisk/cfdisk.c
@@ -150,7 +150,6 @@
#define COL_ID_WIDTH 25
-#define CR '\015'
#define ESC '\033'
#define DEL '\177'
#define BELL '\007'
@@ -428,7 +427,7 @@ fdexit(int ret) {
static int
get_string(char *str, int len, char *def) {
size_t cells = 0, i = 0;
- int x, y, key;
+ int x, y;
int use_def = FALSE;
wint_t c;
@@ -445,13 +444,21 @@ get_string(char *str, int len, char *def) {
refresh();
+ while (1) {
#if !defined(HAVE_SLCURSES_H) && !defined(HAVE_SLANG_SLCURSES_H) && \
defined(HAVE_LIBNCURSESW) && defined(HAVE_WIDECHAR)
- while ((key = get_wch(&c)) != ERR &&
- c != '\r' && c != '\n' && c != KEY_ENTER) {
+ if (get_wch(&c) == ERR) {
#else
- while ((c = getch()) != '\n' && c != CR) {
+ if ((c = getch()) == ERR) {
#endif
+ if (!isatty(STDIN_FILENO))
+ exit(2);
+ else
+ break;
+ }
+ if (c == '\r' || c == '\n' || c == KEY_ENTER)
+ break;
+
switch (c) {
case ESC:
move(y, x);
@@ -1131,6 +1138,10 @@ menuSelect( int y, int x, struct MenuItem *menuItems, int itemLength,
refresh();
key = getch();
+ if (key == ERR)
+ if (!isatty(STDIN_FILENO))
+ exit(2);
+
/* Clear out all prompts and such */
clear_warning();
for (i = y; i < ylast; i++) {
@@ -1176,7 +1187,7 @@ menuSelect( int y, int x, struct MenuItem *menuItems, int itemLength,
}
/* Enter equals the keyboard shortcut of current menu item */
- if (key == CR)
+ if (key == '\r')
key = menuItems[current].key;
/* Give alternatives for arrow keys in case the window manager