From 61ed1470447fcd3a2b380ccc2b9c76775ea7a108 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 31 Jan 2023 17:20:40 -0500 Subject: [PATCH] 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. --- .../input_server/devices/keyboard/KeyboardInputDevice.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp index 9ceecd3a9d..0d59b4caf3 100644 --- a/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp +++ b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp @@ -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;