1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32: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:
Simon Tatham
2020-04-18 13:28:33 +01:00
parent d9c4ce9fd8
commit df2994a05a
14 changed files with 88 additions and 87 deletions

View File

@ -5088,8 +5088,7 @@ static void gtk_seat_update_specials_menu(Seat *seat)
static void start_backend(GtkFrontend *inst)
{
const struct BackendVtable *vt;
char *realhost;
const char *error;
char *error, *realhost;
char *s;
vt = select_backend(inst->conf);
@ -5107,6 +5106,7 @@ static void start_backend(GtkFrontend *inst)
seat_connection_fatal(&inst->seat,
"Unable to open connection to %s:\n%s",
conf_dest(inst->conf), error);
sfree(error);
inst->exited = true;
return;
}

View File

@ -914,8 +914,7 @@ int main(int argc, char **argv)
*/
logctx = log_init(console_cli_logpolicy, conf);
{
const char *error;
char *realhost;
char *error, *realhost;
/* nodelay is only useful if stdin is a terminal device */
bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && isatty(0);
@ -931,6 +930,7 @@ int main(int argc, char **argv)
conf_get_bool(conf, CONF_tcp_keepalives));
if (error) {
fprintf(stderr, "Unable to open connection:\n%s\n", error);
sfree(error);
return 1;
}
ldisc_create(conf, NULL, backend, plink_seat);

View File

@ -1270,10 +1270,10 @@ Backend *pty_backend_create(
* it gets the argv array from the global variable pty_argv, expecting
* that it will have been invoked by pterm.
*/
static const char *pty_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 *pty_init(const BackendVtable *vt, Seat *seat,
Backend **backend_handle, LogContext *logctx,
Conf *conf, const char *host, int port,
char **realhost, bool nodelay, bool keepalive)
{
const char *cmd = NULL;
struct ssh_ttymodes modes;

View File

@ -63,14 +63,15 @@ static void serial_select_result(int fd, int event);
static void serial_uxsel_setup(Serial *serial);
static void serial_try_write(Serial *serial);
static const char *serial_configure(Serial *serial, Conf *conf)
static char *serial_configure(Serial *serial, Conf *conf)
{
struct termios options;
int bflag, bval, speed, flow, parity;
const char *str;
if (serial->fd < 0)
return "Unable to reconfigure already-closed serial connection";
return dupstr("Unable to reconfigure already-closed "
"serial connection");
tcgetattr(serial->fd, &options);
@ -189,7 +190,8 @@ static const char *serial_configure(Serial *serial, Conf *conf)
case 6: options.c_cflag |= CS6; break;
case 7: options.c_cflag |= CS7; break;
case 8: options.c_cflag |= CS8; break;
default: return "Invalid number of data bits (need 5, 6, 7 or 8)";
default: return dupstr("Invalid number of data bits "
"(need 5, 6, 7 or 8)");
}
logeventf(serial->logctx, "Configuring %d data bits",
conf_get_int(conf, CONF_serdatabits));
@ -266,7 +268,7 @@ static const char *serial_configure(Serial *serial, Conf *conf)
options.c_cc[VTIME] = 0;
if (tcsetattr(serial->fd, TCSANOW, &options) < 0)
return "Unable to configure serial port";
return dupstr("Unable to configure serial port");
return NULL;
}
@ -279,13 +281,13 @@ static const char *serial_configure(Serial *serial, 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;
const char *err;
char *err;
char *line;
/* No local authentication phase in this protocol */
@ -306,7 +308,7 @@ static const char *serial_init(const BackendVtable *vt, Seat *seat,
serial->fd = open(line, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (serial->fd < 0)
return "Unable to open serial port";
return dupstr("Unable to open serial port");
cloexec(serial->fd);