From 4f3f4ed691ed88701d542de71d665a03dee22b1c Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 26 Nov 2017 17:43:02 +0000 Subject: [PATCH] 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'. --- fuzzterm.c | 1 - pscp.c | 15 --------------- psftp.c | 14 -------------- putty.h | 2 -- terminal.c | 26 +++++++++++++------------- unix/gtkdlg.c | 12 ------------ unix/uxpgnt.c | 10 ---------- unix/uxplink.c | 17 ----------------- windows/window.c | 17 ----------------- windows/winnet.c | 36 +++++++++++++----------------------- windows/winplink.c | 14 -------------- 11 files changed, 26 insertions(+), 138 deletions(-) diff --git a/fuzzterm.c b/fuzzterm.c index 255fc6fb..707c4ae8 100644 --- a/fuzzterm.c +++ b/fuzzterm.c @@ -88,7 +88,6 @@ void set_raw_mouse_mode(void *frontend, int m) { } void request_paste(void *frontend) { } void do_beep(void *frontend, int a) { } void sys_cursor(void *frontend, int x, int y) { } -void fatalbox(const char *fmt, ...) { exit(0); } void modalfatalbox(const char *fmt, ...) { exit(0); } void nonfatal(const char *fmt, ...) { } diff --git a/pscp.c b/pscp.c index 210362df..87a760c2 100644 --- a/pscp.c +++ b/pscp.c @@ -91,21 +91,6 @@ static void tell_user(FILE *stream, const char *fmt, ...) /* * 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, ...) { char *str, *str2; diff --git a/psftp.c b/psftp.c index e4e77c3a..643389da 100644 --- a/psftp.c +++ b/psftp.c @@ -2442,20 +2442,6 @@ static int verbose = 0; /* * 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, ...) { char *str, *str2; diff --git a/putty.h b/putty.h index 0dd48a5a..ba7e123a 100644 --- a/putty.h +++ b/putty.h @@ -642,10 +642,8 @@ void optimised_move(void *frontend, int, int, int); void set_raw_mouse_mode(void *frontend, int); void connection_fatal(void *frontend, const char *, ...); void nonfatal(const char *, ...); -void fatalbox(const char *, ...); void modalfatalbox(const char *, ...); #ifdef macintosh -#pragma noreturn(fatalbox) #pragma noreturn(modalfatalbox) #endif void do_beep(void *frontend, int); diff --git a/terminal.c b/terminal.c index d5d5314a..96a00266 100644 --- a/terminal.c +++ b/terminal.c @@ -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. */ if (line == NULL) { - fatalbox("line==NULL in terminal.c\n" - "lineno=%d y=%d w=%d h=%d\n" - "count(scrollback=%p)=%d\n" - "count(screen=%p)=%d\n" - "count(alt=%p)=%d alt_sblines=%d\n" - "whichtree=%p treeindex=%d\n\n" - "Please contact " - "and pass on the above information.", - lineno, y, term->cols, term->rows, - term->scrollback, count234(term->scrollback), - term->screen, count234(term->screen), - term->alt_screen, count234(term->alt_screen), term->alt_sblines, - whichtree, treeindex); + modalfatalbox("line==NULL in terminal.c\n" + "lineno=%d y=%d w=%d h=%d\n" + "count(scrollback=%p)=%d\n" + "count(screen=%p)=%d\n" + "count(alt=%p)=%d alt_sblines=%d\n" + "whichtree=%p treeindex=%d\n\n" + "Please contact " + "and pass on the above information.", + lineno, y, term->cols, term->rows, + term->scrollback, count234(term->scrollback), + term->screen, count234(term->screen), + term->alt_screen, count234(term->alt_screen), + term->alt_sblines, whichtree, treeindex); } assert(line != NULL); diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index 9015dff3..5c69cb56 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -3705,18 +3705,6 @@ void nonfatal_message_box(void *window, const char *msg) 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, ...) { va_list ap; diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index cb85b160..de990b93 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -23,16 +23,6 @@ SockAddr unix_sock_addr(const char *path); 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, ...) { va_list ap; diff --git a/unix/uxplink.c b/unix/uxplink.c index 2a1926ef..11ca7d1d 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -29,23 +29,6 @@ static void *logctx; 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, ...) { struct termios cf; diff --git a/windows/window.c b/windows/window.c index 88a29dd4..30cbbdc9 100644 --- a/windows/window.c +++ b/windows/window.c @@ -5522,23 +5522,6 @@ void optimised_move(void *frontend, int to, int from, int lines) } #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. */ diff --git a/windows/winnet.c b/windows/winnet.c index 86f7735f..12fce5f9 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -257,7 +257,7 @@ void sk_init(void) winsock_module = load_system32_dll("wsock32.dll"); } if (!winsock_module) - fatalbox("Unable to load any WinSock library"); + modalfatalbox("Unable to load any WinSock library"); #ifndef NO_IPV6 /* Check if we have getaddrinfo in Winsock */ @@ -348,7 +348,7 @@ void sk_init(void) if (!sk_startup(2,2) && !sk_startup(2,0) && !sk_startup(1,1)) { - fatalbox("Unable to initialise WinSock"); + modalfatalbox("Unable to initialise WinSock"); } sktree = newtree234(cmpfortree); @@ -1529,26 +1529,20 @@ void try_send(Actual_Socket s) */ s->writable = FALSE; return; - } else if (nsent == 0 || - err == WSAECONNABORTED || err == WSAECONNRESET) { + } else { /* - * If send() returns CONNABORTED or CONNRESET, we - * unfortunately can't just call plug_closing(), - * because it's quite likely that we're currently - * _in_ a call from the code we'd be calling back - * to, so we'd have to make half the SSH code - * reentrant. Instead we flag a pending error on - * the socket, to be dealt with (by calling - * plug_closing()) at some suitable future moment. + * If send() returns a socket error, we unfortunately + * can't just call plug_closing(), because it's quite + * likely that we're currently _in_ a call from the + * code we'd be calling back to, so we'd have to make + * half the SSH code reentrant. Instead we flag a + * pending error on the socket, to be dealt with (by + * calling plug_closing()) at some suitable future + * moment. */ s->pending_error = err; queue_toplevel_callback(socket_error_callback, s); 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 { 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); noise_ultralight(ret); if (ret <= 0) { - const char *str = (ret == 0 ? "Internal networking trouble" : - winsock_error_string(p_WSAGetLastError())); - /* We're inside the Windows frontend here, so we know - * that the frontend handle is unnecessary. */ - logevent(NULL, str); - fatalbox("%s", str); + int err = p_WSAGetLastError(); + plug_closing(s->plug, winsock_error_string(err), err, 0); } else { plug_receive(s->plug, 2, buf, ret); } diff --git a/windows/winplink.c b/windows/winplink.c index 84e47d6e..65dd7702 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -22,20 +22,6 @@ struct agent_callback { 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, ...) { va_list ap;