From 98a0e0e272018a1ae2cc5cd4fa9775c5cfb33dec Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 22 Jun 2024 16:44:23 +0100 Subject: win32: add env var to control error dialogs If the environment variable BB_CRITICAL_ERROR_DIALOGS is set to 1 critical error dialogs are enabled. If unset or set to any other value they aren't. In either case the error messages introduced by commit 790e37727 (win32: revert 'don't set error mode') are issued. The shell exports BB_CRITICAL_ERROR_DIALOGS to the environment immediately on any change so the setting takes effect at once. Adds 104-160 bytes. (GitHub issue #423) --- include/libbb.h | 1 + include/mingw.h | 1 + libbb/appletlib.c | 2 +- libbb/messages.c | 3 ++- shell/ash.c | 1 + win32/mingw.c | 6 ++++++ 6 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index d37d4e64c..9055ed066 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -2418,6 +2418,7 @@ extern const char bbvar[] ALIGN1; #define BB_SKIP_ANSI_EMULATION bbafter(BB_OVERRIDE_APPLETS) #define BB_TERMINAL_MODE bbafter(BB_SKIP_ANSI_EMULATION) #define BB_SYSTEMROOT bbafter(BB_TERMINAL_MODE) +#define BB_CRITICAL_ERROR_DIALOGS bbafter(BB_SYSTEMROOT) #endif extern const int const_int_0; diff --git a/include/mingw.h b/include/mingw.h index fae732332..93fad0605 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -639,3 +639,4 @@ char *quote_arg(const char *arg); char *find_first_executable(const char *name); char *xappendword(const char *str, const char *word); int windows_env(void); +void change_critical_error_dialogs(const char *newval) FAST_FUNC; diff --git a/libbb/appletlib.c b/libbb/appletlib.c index c90285ae9..121959376 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -1352,7 +1352,7 @@ int main(int argc UNUSED_PARAM, char **argv) /* Have this process handle critical errors itself: the default * system-generated error dialogs may be inconvenient. */ - SetErrorMode(SEM_FAILCRITICALERRORS); + change_critical_error_dialogs(getenv(BB_CRITICAL_ERROR_DIALOGS) ?: ""); #endif #if defined(__MINGW64_VERSION_MAJOR) diff --git a/libbb/messages.c b/libbb/messages.c index 12079a2e0..27ba244d6 100644 --- a/libbb/messages.c +++ b/libbb/messages.c @@ -47,7 +47,8 @@ const char bbvar[] ALIGN1 = "BB_OVERRIDE_APPLETS\0" \ "BB_SKIP_ANSI_EMULATION\0" \ "BB_TERMINAL_MODE\0" \ - "BB_SYSTEMROOT\0"; + "BB_SYSTEMROOT\0" \ + "BB_CRITICAL_ERROR_DIALOGS\0"; #endif const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL; /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, diff --git a/shell/ash.c b/shell/ash.c index ad77689e7..817b5635f 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -2443,6 +2443,7 @@ static const struct { { VSTRFIXED|VTEXTFIXED|VUNSET, BB_SKIP_ANSI_EMULATION, change_terminal_mode }, { VSTRFIXED|VTEXTFIXED|VUNSET, BB_TERMINAL_MODE, change_terminal_mode }, { VSTRFIXED|VTEXTFIXED|VUNSET, BB_OVERRIDE_APPLETS, change_override_applets }, + { VSTRFIXED|VTEXTFIXED|VUNSET, BB_CRITICAL_ERROR_DIALOGS, change_critical_error_dialogs }, #endif }; diff --git a/win32/mingw.c b/win32/mingw.c index 4398f5462..49e1bcfa4 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -2507,3 +2507,9 @@ windows_env(void) } return FALSE; } + +void FAST_FUNC +change_critical_error_dialogs(const char *newval) +{ + SetErrorMode(strcmp(newval, "1") == 0 ? 0 : SEM_FAILCRITICALERRORS); +} -- cgit v1.2.3-55-g6feb