mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 09:58:01 +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:
parent
df2994a05a
commit
21492da89e
@ -268,7 +268,7 @@ static char *serial_configure(Serial *serial, Conf *conf)
|
|||||||
options.c_cc[VTIME] = 0;
|
options.c_cc[VTIME] = 0;
|
||||||
|
|
||||||
if (tcsetattr(serial->fd, TCSANOW, &options) < 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;
|
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);
|
serial->fd = open(line, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
|
||||||
if (serial->fd < 0)
|
if (serial->fd < 0)
|
||||||
return dupstr("Unable to open serial port");
|
return dupprintf("Opening serial port '%s': %s",
|
||||||
|
line, strerror(errno));
|
||||||
|
|
||||||
cloexec(serial->fd);
|
cloexec(serial->fd);
|
||||||
|
|
||||||
|
@ -170,7 +170,8 @@ static char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
|
|||||||
logeventf(serial->logctx, "Configuring %s flow control", str);
|
logeventf(serial->logctx, "Configuring %s flow control", str);
|
||||||
|
|
||||||
if (!SetCommState(serport, &dcb))
|
if (!SetCommState(serport, &dcb))
|
||||||
return dupstr("Unable to configure serial port");
|
return dupprintf("Configuring serial port: %s",
|
||||||
|
win_strerror(GetLastError()));
|
||||||
|
|
||||||
timeouts.ReadIntervalTimeout = 1;
|
timeouts.ReadIntervalTimeout = 1;
|
||||||
timeouts.ReadTotalTimeoutMultiplier = 0;
|
timeouts.ReadTotalTimeoutMultiplier = 0;
|
||||||
@ -178,7 +179,8 @@ static char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
|
|||||||
timeouts.WriteTotalTimeoutMultiplier = 0;
|
timeouts.WriteTotalTimeoutMultiplier = 0;
|
||||||
timeouts.WriteTotalTimeoutConstant = 0;
|
timeouts.WriteTotalTimeoutConstant = 0;
|
||||||
if (!SetCommTimeouts(serport, &timeouts))
|
if (!SetCommTimeouts(serport, &timeouts))
|
||||||
return dupstr("Unable to configure serial timeouts");
|
return dupprintf("Configuring serial timeouts: %s",
|
||||||
|
win_strerror(GetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -219,7 +221,6 @@ static char *serial_init(const BackendVtable *vt, Seat *seat,
|
|||||||
serline = conf_get_str(conf, CONF_serline);
|
serline = conf_get_str(conf, CONF_serline);
|
||||||
logeventf(serial->logctx, "Opening serial device %s", serline);
|
logeventf(serial->logctx, "Opening serial device %s", serline);
|
||||||
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* Munge the string supplied by the user into a Windows filename.
|
* 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);
|
dupprintf("%s%s", strchr(serline, '\\') ? "" : "\\\\.\\", serline);
|
||||||
serport = CreateFile(serfilename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
serport = CreateFile(serfilename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
||||||
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||||
|
if (serport == INVALID_HANDLE_VALUE) {
|
||||||
|
err = dupprintf("Opening '%s': %s",
|
||||||
|
serfilename, win_strerror(GetLastError()));
|
||||||
sfree(serfilename);
|
sfree(serfilename);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serport == INVALID_HANDLE_VALUE)
|
sfree(serfilename);
|
||||||
return dupstr("Unable to open serial port");
|
|
||||||
|
|
||||||
err = serial_configure(serial, serport, conf);
|
err = serial_configure(serial, serport, conf);
|
||||||
if (err)
|
if (err)
|
||||||
|
Loading…
Reference in New Issue
Block a user