mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 19:12:48 -05:00
Make the backend_init error message dynamic. (NFC)
Now, instead of a 'const char *' in the static data segment, error messages returned from backend setup are dynamically allocated and freed by the caller. This will allow me to make the messages much more specific (including errno values and the like). However, this commit is pure refactoring: I've _just_ changed the allocation policy, and left all the messages alone.
This commit is contained in:
@ -368,9 +368,8 @@ static WinGuiSeat wgs = { .seat.vt = &win_seat_vt,
|
||||
static void start_backend(void)
|
||||
{
|
||||
const struct BackendVtable *vt;
|
||||
const char *error;
|
||||
const char *title;
|
||||
char *realhost;
|
||||
char *error, *realhost;
|
||||
int i;
|
||||
|
||||
/*
|
||||
@ -397,6 +396,7 @@ static void start_backend(void)
|
||||
char *str = dupprintf("%s Error", appname);
|
||||
char *msg = dupprintf("Unable to open connection to\n%s\n%s",
|
||||
conf_dest(conf), error);
|
||||
sfree(error);
|
||||
MessageBox(NULL, msg, str, MB_ICONERROR | MB_OK);
|
||||
sfree(str);
|
||||
sfree(msg);
|
||||
|
@ -492,8 +492,7 @@ int main(int argc, char **argv)
|
||||
*/
|
||||
winselcli_setup(); /* ensure event object exists */
|
||||
{
|
||||
const char *error;
|
||||
char *realhost;
|
||||
char *error, *realhost;
|
||||
/* nodelay is only useful if stdin is a character device (console) */
|
||||
bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) &&
|
||||
(GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR);
|
||||
@ -505,6 +504,7 @@ int main(int argc, char **argv)
|
||||
conf_get_bool(conf, CONF_tcp_keepalives));
|
||||
if (error) {
|
||||
fprintf(stderr, "Unable to open connection:\n%s", error);
|
||||
sfree(error);
|
||||
return 1;
|
||||
}
|
||||
sfree(realhost);
|
||||
|
@ -91,7 +91,7 @@ static void serial_sentdata(struct handle *h, size_t new_backlog, int err)
|
||||
}
|
||||
}
|
||||
|
||||
static const char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
|
||||
static char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
|
||||
{
|
||||
DCB dcb;
|
||||
COMMTIMEOUTS timeouts;
|
||||
@ -134,7 +134,8 @@ static const char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
|
||||
case 2: dcb.StopBits = ONESTOPBIT; str = "1 stop bit"; break;
|
||||
case 3: dcb.StopBits = ONE5STOPBITS; str = "1.5 stop bits"; break;
|
||||
case 4: dcb.StopBits = TWOSTOPBITS; str = "2 stop bits"; break;
|
||||
default: return "Invalid number of stop bits (need 1, 1.5 or 2)";
|
||||
default: return dupstr("Invalid number of stop bits "
|
||||
"(need 1, 1.5 or 2)");
|
||||
}
|
||||
logeventf(serial->logctx, "Configuring %s", str);
|
||||
|
||||
@ -169,7 +170,7 @@ static const char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
|
||||
logeventf(serial->logctx, "Configuring %s flow control", str);
|
||||
|
||||
if (!SetCommState(serport, &dcb))
|
||||
return "Unable to configure serial port";
|
||||
return dupstr("Unable to configure serial port");
|
||||
|
||||
timeouts.ReadIntervalTimeout = 1;
|
||||
timeouts.ReadTotalTimeoutMultiplier = 0;
|
||||
@ -177,7 +178,7 @@ static const char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
|
||||
timeouts.WriteTotalTimeoutMultiplier = 0;
|
||||
timeouts.WriteTotalTimeoutConstant = 0;
|
||||
if (!SetCommTimeouts(serport, &timeouts))
|
||||
return "Unable to configure serial timeouts";
|
||||
return dupstr("Unable to configure serial timeouts");
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -191,14 +192,14 @@ static const char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
|
||||
* Also places the canonical host name into `realhost'. It must be
|
||||
* freed by the caller.
|
||||
*/
|
||||
static const char *serial_init(const BackendVtable *vt, Seat *seat,
|
||||
Backend **backend_handle, LogContext *logctx,
|
||||
Conf *conf, const char *host, int port,
|
||||
char **realhost, bool nodelay, bool keepalive)
|
||||
static char *serial_init(const BackendVtable *vt, Seat *seat,
|
||||
Backend **backend_handle, LogContext *logctx,
|
||||
Conf *conf, const char *host, int port,
|
||||
char **realhost, bool nodelay, bool keepalive)
|
||||
{
|
||||
Serial *serial;
|
||||
HANDLE serport;
|
||||
const char *err;
|
||||
char *err;
|
||||
char *serline;
|
||||
|
||||
/* No local authentication phase in this protocol */
|
||||
@ -250,7 +251,7 @@ static const char *serial_init(const BackendVtable *vt, Seat *seat,
|
||||
}
|
||||
|
||||
if (serport == INVALID_HANDLE_VALUE)
|
||||
return "Unable to open serial port";
|
||||
return dupstr("Unable to open serial port");
|
||||
|
||||
err = serial_configure(serial, serport, conf);
|
||||
if (err)
|
||||
|
Reference in New Issue
Block a user