1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-03 04:22:47 -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

@ -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);