1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Improve serial-port setup error messages.

Now you can see exactly what pathname the backend tried to open for
the serial port, and what error code it got back from the OS when it
tried. That should help users distinguish between (for example) a
permissions problem and a typo in the filename.
This commit is contained in:
Simon Tatham 2020-04-18 13:30:42 +01:00
parent df2994a05a
commit 21492da89e
2 changed files with 39 additions and 34 deletions

View File

@ -268,7 +268,7 @@ static char *serial_configure(Serial *serial, Conf *conf)
options.c_cc[VTIME] = 0;
if (tcsetattr(serial->fd, TCSANOW, &options) < 0)
return dupstr("Unable to configure serial port");
return dupprintf("Configuring serial port: %s", strerror(errno));
return NULL;
}
@ -308,7 +308,8 @@ static 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 dupstr("Unable to open serial port");
return dupprintf("Opening serial port '%s': %s",
line, strerror(errno));
cloexec(serial->fd);

View File

@ -170,7 +170,8 @@ static char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
logeventf(serial->logctx, "Configuring %s flow control", str);
if (!SetCommState(serport, &dcb))
return dupstr("Unable to configure serial port");
return dupprintf("Configuring serial port: %s",
win_strerror(GetLastError()));
timeouts.ReadIntervalTimeout = 1;
timeouts.ReadTotalTimeoutMultiplier = 0;
@ -178,7 +179,8 @@ static char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
timeouts.WriteTotalTimeoutMultiplier = 0;
timeouts.WriteTotalTimeoutConstant = 0;
if (!SetCommTimeouts(serport, &timeouts))
return dupstr("Unable to configure serial timeouts");
return dupprintf("Configuring serial timeouts: %s",
win_strerror(GetLastError()));
}
return NULL;
@ -219,7 +221,6 @@ static char *serial_init(const BackendVtable *vt, Seat *seat,
serline = conf_get_str(conf, CONF_serline);
logeventf(serial->logctx, "Opening serial device %s", serline);
{
/*
* Munge the string supplied by the user into a Windows filename.
*
@ -247,11 +248,14 @@ static char *serial_init(const BackendVtable *vt, Seat *seat,
dupprintf("%s%s", strchr(serline, '\\') ? "" : "\\\\.\\", serline);
serport = CreateFile(serfilename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
if (serport == INVALID_HANDLE_VALUE) {
err = dupprintf("Opening '%s': %s",
serfilename, win_strerror(GetLastError()));
sfree(serfilename);
return err;
}
if (serport == INVALID_HANDLE_VALUE)
return dupstr("Unable to open serial port");
sfree(serfilename);
err = serial_configure(serial, serport, conf);
if (err)