1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Get rid of fatalbox() completely.

It's an incoherent concept! There should not be any such thing as an
error box that terminates the entire program but is not modal. If it's
bad enough to terminate the whole program, i.e. _all_ currently live
connections, then there's no point in permitting progress to continue
in windows other than the affected one, because all windows are
affected anyway.

So all previous uses of fatalbox() have become modalfatalbox(), except
those which looked to me as if they shouldn't have been fatal in the
first place, e.g. lingering pieces of error handling in winnet.c which
ought to have had the severity of 'give up on this particular Socket
and close it' rather than 'give up on the ENTIRE UNIVERSE'.
This commit is contained in:
Simon Tatham 2017-11-26 17:43:02 +00:00
parent d1f62c3e0f
commit 4f3f4ed691
11 changed files with 26 additions and 138 deletions

View File

@ -88,7 +88,6 @@ void set_raw_mouse_mode(void *frontend, int m) { }
void request_paste(void *frontend) { } void request_paste(void *frontend) { }
void do_beep(void *frontend, int a) { } void do_beep(void *frontend, int a) { }
void sys_cursor(void *frontend, int x, int y) { } void sys_cursor(void *frontend, int x, int y) { }
void fatalbox(const char *fmt, ...) { exit(0); }
void modalfatalbox(const char *fmt, ...) { exit(0); } void modalfatalbox(const char *fmt, ...) { exit(0); }
void nonfatal(const char *fmt, ...) { } void nonfatal(const char *fmt, ...) { }

15
pscp.c
View File

@ -91,21 +91,6 @@ static void tell_user(FILE *stream, const char *fmt, ...)
/* /*
* Print an error message and perform a fatal exit. * Print an error message and perform a fatal exit.
*/ */
void fatalbox(const char *fmt, ...)
{
char *str, *str2;
va_list ap;
va_start(ap, fmt);
str = dupvprintf(fmt, ap);
str2 = dupcat("Fatal: ", str, "\n", NULL);
sfree(str);
va_end(ap);
tell_str(stderr, str2);
sfree(str2);
errs++;
cleanup_exit(1);
}
void modalfatalbox(const char *fmt, ...) void modalfatalbox(const char *fmt, ...)
{ {
char *str, *str2; char *str, *str2;

14
psftp.c
View File

@ -2442,20 +2442,6 @@ static int verbose = 0;
/* /*
* Print an error message and perform a fatal exit. * Print an error message and perform a fatal exit.
*/ */
void fatalbox(const char *fmt, ...)
{
char *str, *str2;
va_list ap;
va_start(ap, fmt);
str = dupvprintf(fmt, ap);
str2 = dupcat("Fatal: ", str, "\n", NULL);
sfree(str);
va_end(ap);
fputs(str2, stderr);
sfree(str2);
cleanup_exit(1);
}
void modalfatalbox(const char *fmt, ...) void modalfatalbox(const char *fmt, ...)
{ {
char *str, *str2; char *str, *str2;

View File

@ -642,10 +642,8 @@ void optimised_move(void *frontend, int, int, int);
void set_raw_mouse_mode(void *frontend, int); void set_raw_mouse_mode(void *frontend, int);
void connection_fatal(void *frontend, const char *, ...); void connection_fatal(void *frontend, const char *, ...);
void nonfatal(const char *, ...); void nonfatal(const char *, ...);
void fatalbox(const char *, ...);
void modalfatalbox(const char *, ...); void modalfatalbox(const char *, ...);
#ifdef macintosh #ifdef macintosh
#pragma noreturn(fatalbox)
#pragma noreturn(modalfatalbox) #pragma noreturn(modalfatalbox)
#endif #endif
void do_beep(void *frontend, int); void do_beep(void *frontend, int);

View File

@ -1085,19 +1085,19 @@ static termline *lineptr(Terminal *term, int y, int lineno, int screen)
/* We assume that we don't screw up and retrieve something out of range. */ /* We assume that we don't screw up and retrieve something out of range. */
if (line == NULL) { if (line == NULL) {
fatalbox("line==NULL in terminal.c\n" modalfatalbox("line==NULL in terminal.c\n"
"lineno=%d y=%d w=%d h=%d\n" "lineno=%d y=%d w=%d h=%d\n"
"count(scrollback=%p)=%d\n" "count(scrollback=%p)=%d\n"
"count(screen=%p)=%d\n" "count(screen=%p)=%d\n"
"count(alt=%p)=%d alt_sblines=%d\n" "count(alt=%p)=%d alt_sblines=%d\n"
"whichtree=%p treeindex=%d\n\n" "whichtree=%p treeindex=%d\n\n"
"Please contact <putty@projects.tartarus.org> " "Please contact <putty@projects.tartarus.org> "
"and pass on the above information.", "and pass on the above information.",
lineno, y, term->cols, term->rows, lineno, y, term->cols, term->rows,
term->scrollback, count234(term->scrollback), term->scrollback, count234(term->scrollback),
term->screen, count234(term->screen), term->screen, count234(term->screen),
term->alt_screen, count234(term->alt_screen), term->alt_sblines, term->alt_screen, count234(term->alt_screen),
whichtree, treeindex); term->alt_sblines, whichtree, treeindex);
} }
assert(line != NULL); assert(line != NULL);

View File

@ -3705,18 +3705,6 @@ void nonfatal_message_box(void *window, const char *msg)
FALSE, &buttons_ok); FALSE, &buttons_ok);
} }
void fatalbox(const char *p, ...)
{
va_list ap;
char *msg;
va_start(ap, p);
msg = dupvprintf(p, ap);
va_end(ap);
fatal_message_box(NULL, msg);
sfree(msg);
cleanup_exit(1);
}
void nonfatal(const char *p, ...) void nonfatal(const char *p, ...)
{ {
va_list ap; va_list ap;

View File

@ -23,16 +23,6 @@
SockAddr unix_sock_addr(const char *path); SockAddr unix_sock_addr(const char *path);
Socket new_unix_listener(SockAddr listenaddr, Plug plug); Socket new_unix_listener(SockAddr listenaddr, Plug plug);
void fatalbox(const char *p, ...)
{
va_list ap;
fprintf(stderr, "FATAL ERROR: ");
va_start(ap, p);
vfprintf(stderr, p, ap);
va_end(ap);
fputc('\n', stderr);
exit(1);
}
void modalfatalbox(const char *p, ...) void modalfatalbox(const char *p, ...)
{ {
va_list ap; va_list ap;

View File

@ -29,23 +29,6 @@ static void *logctx;
static struct termios orig_termios; static struct termios orig_termios;
void fatalbox(const char *p, ...)
{
struct termios cf;
va_list ap;
premsg(&cf);
fprintf(stderr, "FATAL ERROR: ");
va_start(ap, p);
vfprintf(stderr, p, ap);
va_end(ap);
fputc('\n', stderr);
postmsg(&cf);
if (logctx) {
log_free(logctx);
logctx = NULL;
}
cleanup_exit(1);
}
void modalfatalbox(const char *p, ...) void modalfatalbox(const char *p, ...)
{ {
struct termios cf; struct termios cf;

View File

@ -5522,23 +5522,6 @@ void optimised_move(void *frontend, int to, int from, int lines)
} }
#endif #endif
/*
* Print a message box and perform a fatal exit.
*/
void fatalbox(const char *fmt, ...)
{
va_list ap;
char *stuff, morestuff[100];
va_start(ap, fmt);
stuff = dupvprintf(fmt, ap);
va_end(ap);
sprintf(morestuff, "%.70s Fatal Error", appname);
MessageBox(hwnd, stuff, morestuff, MB_ICONERROR | MB_OK);
sfree(stuff);
cleanup_exit(1);
}
/* /*
* Print a modal (Really Bad) message box and perform a fatal exit. * Print a modal (Really Bad) message box and perform a fatal exit.
*/ */

View File

@ -257,7 +257,7 @@ void sk_init(void)
winsock_module = load_system32_dll("wsock32.dll"); winsock_module = load_system32_dll("wsock32.dll");
} }
if (!winsock_module) if (!winsock_module)
fatalbox("Unable to load any WinSock library"); modalfatalbox("Unable to load any WinSock library");
#ifndef NO_IPV6 #ifndef NO_IPV6
/* Check if we have getaddrinfo in Winsock */ /* Check if we have getaddrinfo in Winsock */
@ -348,7 +348,7 @@ void sk_init(void)
if (!sk_startup(2,2) && if (!sk_startup(2,2) &&
!sk_startup(2,0) && !sk_startup(2,0) &&
!sk_startup(1,1)) { !sk_startup(1,1)) {
fatalbox("Unable to initialise WinSock"); modalfatalbox("Unable to initialise WinSock");
} }
sktree = newtree234(cmpfortree); sktree = newtree234(cmpfortree);
@ -1529,26 +1529,20 @@ void try_send(Actual_Socket s)
*/ */
s->writable = FALSE; s->writable = FALSE;
return; return;
} else if (nsent == 0 || } else {
err == WSAECONNABORTED || err == WSAECONNRESET) {
/* /*
* If send() returns CONNABORTED or CONNRESET, we * If send() returns a socket error, we unfortunately
* unfortunately can't just call plug_closing(), * can't just call plug_closing(), because it's quite
* because it's quite likely that we're currently * likely that we're currently _in_ a call from the
* _in_ a call from the code we'd be calling back * code we'd be calling back to, so we'd have to make
* to, so we'd have to make half the SSH code * half the SSH code reentrant. Instead we flag a
* reentrant. Instead we flag a pending error on * pending error on the socket, to be dealt with (by
* the socket, to be dealt with (by calling * calling plug_closing()) at some suitable future
* plug_closing()) at some suitable future moment. * moment.
*/ */
s->pending_error = err; s->pending_error = err;
queue_toplevel_callback(socket_error_callback, s); queue_toplevel_callback(socket_error_callback, s);
return; return;
} else {
/* We're inside the Windows frontend here, so we know
* that the frontend handle is unnecessary. */
logevent(NULL, winsock_error_string(err));
fatalbox("%s", winsock_error_string(err));
} }
} else { } else {
if (s->sending_oob) { if (s->sending_oob) {
@ -1738,12 +1732,8 @@ void select_result(WPARAM wParam, LPARAM lParam)
ret = p_recv(s->s, buf, sizeof(buf), MSG_OOB); ret = p_recv(s->s, buf, sizeof(buf), MSG_OOB);
noise_ultralight(ret); noise_ultralight(ret);
if (ret <= 0) { if (ret <= 0) {
const char *str = (ret == 0 ? "Internal networking trouble" : int err = p_WSAGetLastError();
winsock_error_string(p_WSAGetLastError())); plug_closing(s->plug, winsock_error_string(err), err, 0);
/* We're inside the Windows frontend here, so we know
* that the frontend handle is unnecessary. */
logevent(NULL, str);
fatalbox("%s", str);
} else { } else {
plug_receive(s->plug, 2, buf, ret); plug_receive(s->plug, 2, buf, ret);
} }

View File

@ -22,20 +22,6 @@ struct agent_callback {
int len; int len;
}; };
void fatalbox(const char *p, ...)
{
va_list ap;
fprintf(stderr, "FATAL ERROR: ");
va_start(ap, p);
vfprintf(stderr, p, ap);
va_end(ap);
fputc('\n', stderr);
if (logctx) {
log_free(logctx);
logctx = NULL;
}
cleanup_exit(1);
}
void modalfatalbox(const char *p, ...) void modalfatalbox(const char *p, ...)
{ {
va_list ap; va_list ap;