1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 11:02:48 -05:00

Various error-handling fixes, mostly in Unix PuTTY but one (failure

to save a session) crosses over into the platform-independent side.

[originally from svn r3041]
This commit is contained in:
Simon Tatham
2003-04-01 18:10:25 +00:00
parent 09ba8ca111
commit 7706da5e17
11 changed files with 114 additions and 46 deletions

View File

@ -2337,6 +2337,13 @@ void old_keyfile_warning(void)
*/
}
void fatal_message_box(void *window, char *msg)
{
messagebox(window, "PuTTY Fatal Error", msg,
string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
"OK", 'o', 1, 1, NULL);
}
void fatalbox(char *p, ...)
{
va_list ap;
@ -2344,23 +2351,7 @@ void fatalbox(char *p, ...)
va_start(ap, p);
msg = dupvprintf(p, ap);
va_end(ap);
messagebox(NULL, "PuTTY Fatal Error", msg,
string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
"OK", 'o', 1, 1, NULL);
sfree(msg);
cleanup_exit(1);
}
void connection_fatal(void *frontend, char *p, ...)
{
va_list ap;
char *msg;
va_start(ap, p);
msg = dupvprintf(p, ap);
va_end(ap);
messagebox(GTK_WIDGET(get_window(frontend)),
"PuTTY Fatal Error", msg,
string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
"OK", 'o', 1, 1, NULL);
fatal_message_box(NULL, msg);
sfree(msg);
cleanup_exit(1);
}

View File

@ -86,6 +86,23 @@ char *x_get_default(const char *key)
return XGetDefault(GDK_DISPLAY(), app_name, key);
}
void connection_fatal(void *frontend, char *p, ...)
{
Terminal *term = (Terminal *)frontend;
struct gui_data *inst = (struct gui_data *)term->frontend;
va_list ap;
char *msg;
va_start(ap, p);
msg = dupvprintf(p, ap);
va_end(ap);
inst->exited = TRUE;
fatal_message_box(inst->window, msg);
sfree(msg);
if (inst->cfg.close_on_exit == FORCE_ON)
cleanup_exit(1);
}
/*
* Default settings that are specific to pterm.
*/
@ -1018,7 +1035,8 @@ gint timer_func(gpointer data)
struct gui_data *inst = (struct gui_data *)data;
int exitcode;
if ((exitcode = inst->back->exitcode(inst->backhandle)) >= 0) {
if (!inst->exited &&
(exitcode = inst->back->exitcode(inst->backhandle)) >= 0) {
inst->exited = TRUE;
if (inst->cfg.close_on_exit == FORCE_ON ||
(inst->cfg.close_on_exit == AUTO && exitcode == 0))
@ -1032,10 +1050,17 @@ gint timer_func(gpointer data)
void fd_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
{
select_result(sourcefd,
(condition == GDK_INPUT_READ ? 1 :
condition == GDK_INPUT_WRITE ? 2 :
condition == GDK_INPUT_EXCEPTION ? 4 : -1));
/*
* We must process exceptional notifications before ordinary
* readability ones, or we may go straight past the urgent
* marker.
*/
if (condition & GDK_INPUT_EXCEPTION)
select_result(sourcefd, 4);
if (condition & GDK_INPUT_READ)
select_result(sourcefd, 1);
if (condition & GDK_INPUT_WRITE)
select_result(sourcefd, 2);
}
void destroy(GtkWidget *widget, gpointer data)
@ -2437,13 +2462,24 @@ int pt_main(int argc, char **argv)
uxsel_init();
term_size(inst->term, inst->cfg.height, inst->cfg.width, inst->cfg.savelines);
inst->back = select_backend(&inst->cfg);
{
char *realhost;
char *realhost, *error;
inst->back->init((void *)inst->term, &inst->backhandle, &inst->cfg,
inst->cfg.host, inst->cfg.port, &realhost,
inst->cfg.tcp_nodelay);
error = inst->back->init((void *)inst->term, &inst->backhandle,
&inst->cfg, inst->cfg.host, inst->cfg.port,
&realhost, inst->cfg.tcp_nodelay);
if (error) {
char *msg = dupprintf("Unable to open connection to %s:\n%s",
inst->cfg.host, error);
inst->exited = TRUE;
fatal_message_box(inst->window, msg);
sfree(msg);
return 0;
}
if (inst->cfg.wintitle[0])
set_title(inst, inst->cfg.wintitle);
@ -2457,8 +2493,6 @@ int pt_main(int argc, char **argv)
term_provide_resize_fn(inst->term, inst->back->size, inst->backhandle);
term_size(inst->term, inst->cfg.height, inst->cfg.width, inst->cfg.savelines);
inst->ldisc =
ldisc_create(&inst->cfg, inst->term, inst->back, inst->backhandle, inst);
ldisc_send(inst->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */

View File

@ -3,6 +3,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include "putty.h"
@ -16,6 +17,16 @@ int cfgbox(Config *cfg)
return 1; /* no-op in pterm */
}
void fatal_message_box(void *window, char *msg)
{
/* also a no-op in pterm */
}
void cleanup_exit(int code)
{
exit(code);
}
int process_nonoption_arg(char *arg, Config *cfg)
{
return 0; /* pterm doesn't have any. */

View File

@ -58,6 +58,9 @@ long get_windowid(void *frontend);
/* Things gtkdlg.c needs from pterm.c */
void *get_window(void *frontend); /* void * to avoid depending on gtk.h */
/* Things pterm.c needs from gtkdlg.c */
void fatal_message_box(void *window, char *msg);
/* Things pterm.c needs from {ptermm,uxputty}.c */
char *make_default_wintitle(char *hostname);
int process_nonoption_arg(char *arg, Config *cfg);

View File

@ -5,7 +5,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
@ -132,24 +134,32 @@ static char *fgetline(FILE *fp)
* file somewhere or other.
*/
void *open_settings_w(const char *sessionname)
void *open_settings_w(const char *sessionname, char **errmsg)
{
char filename[FILENAME_MAX];
FILE *fp;
*errmsg = NULL;
/*
* Start by making sure the sessions subdir exists. Ignore the
* error return from mkdir since it's perfectly likely to be
* `already exists', and any other error will trip us up later
* on so there's no real need to catch it now.
* Start by making sure the .putty directory and its sessions
* subdir actually exist. Ignore error returns from mkdir since
* they're perfectly likely to be `already exists', and any
* other error will trip us up later on so there's no real need
* to catch it now.
*/
make_filename(filename, INDEX_DIR, sessionname);
mkdir(filename, 0700);
make_filename(filename, INDEX_SESSIONDIR, sessionname);
mkdir(filename, 0700);
make_filename(filename, INDEX_SESSION, sessionname);
fp = fopen(filename, "w");
if (!fp)
return NULL; /* can't open */
if (!fp) {
*errmsg = dupprintf("Unable to create %s: %s",
filename, strerror(errno));
return NULL; /* can't open */
}
return fp;
}