Skip to content

Commit

Permalink
win32: add env var to control error dialogs
Browse files Browse the repository at this point in the history
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 790e377 (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 rmyorston#423)
  • Loading branch information
rmyorston committed Jun 22, 2024
1 parent 790e377 commit 98a0e0e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/libbb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion libbb/appletlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion libbb/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions shell/ash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
6 changes: 6 additions & 0 deletions win32/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 98a0e0e

Please sign in to comment.