keyboard: Store errno right after calling open() if an error occurred.

errno is a thread-local variable, we can't read it in another thread
and have the value make any sense. Thus we need to store it.

Fortunately, as our errors are all negative already, we can just put it
directly in fFD instead of having to make a new variable altogether.

Should help with diagnosing a problem seen in some syslogs.
This commit is contained in:
Augustin Cavalier 2023-01-31 17:20:40 -05:00
parent d891ca1119
commit 61ed147044

View File

@ -194,7 +194,10 @@ KeyboardDevice::Start()
TRACE("name: %s\n", fDeviceRef.name);
fFD = open(fPath, O_RDWR);
if (fFD < 0) {
// let the control thread handle any error on opening the device
fFD = errno;
}
char threadName[B_OS_NAME_LENGTH];
snprintf(threadName, B_OS_NAME_LENGTH, "%s watcher", fDeviceRef.name);
@ -266,7 +269,7 @@ KeyboardDevice::_ControlThread()
if (fFD < B_OK) {
LOG_ERR("KeyboardDevice: error when opening %s: %s\n",
fPath, strerror(errno));
fPath, strerror(fFD));
_ControlThreadCleanup();
// TOAST!
return B_ERROR;