diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2019-05-10 18:15:49 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-05-10 18:15:49 +0200 |
commit | 8e8412601f5534abe5a57c4b6d62ab9fb5550ea9 (patch) | |
tree | 4f2285fdca21c2bcf11efd3c118aa3d84337b5c2 /common/console.c | |
parent | f44e7eebd5e3022af5659baf81fcdbfe5ce44268 (diff) | |
parent | 90df2a955e3c66fee2c59f67d9274e6a9addd9ce (diff) | |
download | barebox-8e8412601f5534abe5a57c4b6d62ab9fb5550ea9.tar.gz barebox-8e8412601f5534abe5a57c4b6d62ab9fb5550ea9.tar.xz |
Merge branch 'for-next/ctrlc'
Diffstat (limited to 'common/console.c')
-rw-r--r-- | common/console.c | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/common/console.c b/common/console.c index 47ccf2e54d..406722a1da 100644 --- a/common/console.c +++ b/common/console.c @@ -574,18 +574,60 @@ void console_flush(void) } EXPORT_SYMBOL(console_flush); -#ifndef ARCH_HAS_CTRLC +static int ctrlc_abort; +static int ctrlc_allowed; + +void ctrlc_handled(void) +{ + ctrlc_abort = 0; +} + /* test if ctrl-c was pressed */ -int ctrlc (void) +int ctrlc(void) { + int ret = 0; + + if (!ctrlc_allowed) + return 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 */ + +static int console_ctrlc_init(void) +{ + globalvar_add_simple_bool("console.ctrlc_allowed", &ctrlc_allowed); + return 0; +} +device_initcall(console_ctrlc_init); + +void console_ctrlc_allow(void) +{ + ctrlc_allowed = 1; +} + +void console_ctrlc_forbid(void) +{ + ctrlc_allowed = 0; +} + +BAREBOX_MAGICVAR_NAMED(global_console_ctrlc_allowed, global.console.ctrlc_allowed, + "If true, scripts can be aborted with ctrl-c"); BAREBOX_MAGICVAR_NAMED(global_linux_bootargs_console, global.linux.bootargs.console, "console= argument for Linux from the stdout-path property in /chosen node"); |