summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/sandbox/os/common.c2
-rw-r--r--common/console.c28
-rw-r--r--common/hush.c3
-rw-r--r--common/parser.c1
-rw-r--r--include/common.h4
5 files changed, 30 insertions, 8 deletions
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 665e819..a7ea8f2 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -94,7 +94,7 @@ int linux_tstc(int fd)
return 0;
}
-int ctrlc(void)
+int arch_ctrlc(void)
{
char chr;
diff --git a/common/console.c b/common/console.c
index 47ccf2e..b6685ec 100644
--- a/common/console.c
+++ b/common/console.c
@@ -574,18 +574,36 @@ void console_flush(void)
}
EXPORT_SYMBOL(console_flush);
-#ifndef ARCH_HAS_CTRLC
+static int ctrlc_abort;
+
+void ctrlc_handled(void)
+{
+ ctrlc_abort = 0;
+}
+
/* test if ctrl-c was pressed */
-int ctrlc (void)
+int ctrlc(void)
{
+ int ret = 0;
+
+ if (ctrlc_abort)
+ return 1;
+
poller_call();
+#ifdef ARCH_HAS_CTRLC
+ ret = arch_ctrlc();
+#else
if (tstc() && getchar() == 3)
- return 1;
- return 0;
+ ret = 1;
+#endif
+
+ if (ret)
+ ctrlc_abort = 1;
+
+ return ret;
}
EXPORT_SYMBOL(ctrlc);
-#endif /* ARCH_HAS_CTRC */
BAREBOX_MAGICVAR_NAMED(global_linux_bootargs_console, global.linux.bootargs.console,
"console= argument for Linux from the stdout-path property in /chosen node");
diff --git a/common/hush.c b/common/hush.c
index d2f9cc7..dab9b04 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -1734,7 +1734,7 @@ static int parse_stream_outer(struct p_context *ctx, struct in_str *inp, int fla
return 1;
}
b_free(&temp);
- } while (rcode != -1 && !(flag & FLAG_EXIT_FROM_LOOP)); /* loop on syntax errors, return on EOF */
+ } while (!ctrlc() && rcode != -1 && !(flag & FLAG_EXIT_FROM_LOOP)); /* loop on syntax errors, return on EOF */
return code;
}
@@ -1932,6 +1932,7 @@ int run_shell(void)
login();
do {
+ ctrlc_handled();
setup_file_in_str(&input);
rcode = parse_stream_outer(&ctx, &input, FLAG_PARSE_SEMICOLON);
if (rcode < -1) {
diff --git a/common/parser.c b/common/parser.c
index 397d268..fb9ef42 100644
--- a/common/parser.c
+++ b/common/parser.c
@@ -283,6 +283,7 @@ int run_shell(void)
/* invalid command or not repeatable, forget it */
lastcommand[0] = 0;
}
+ ctrlc_handled();
}
}
return 0;
diff --git a/include/common.h b/include/common.h
index 11d26cb..723b9c7 100644
--- a/include/common.h
+++ b/include/common.h
@@ -68,7 +68,9 @@ int readline (const char *prompt, char *buf, int len);
long get_ram_size (volatile long *, long);
/* common/console.c */
-int ctrlc (void);
+int ctrlc(void);
+int arch_ctrlc(void);
+void ctrlc_handled(void);
#ifdef ARCH_HAS_STACK_DUMP
void dump_stack(void);