From b5c9a83f65cf44804932f96ae4933dd60399a00e Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 9 Oct 2025 12:20:42 -0700
Subject: [PATCH] Display error messages when evdev devices can't be opened
Fixes https://github.com/libsdl-org/SDL/issues/13141
---
src/core/linux/SDL_evdev.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c
index a966bfcfafe7a..69155ed300798 100644
--- a/src/core/linux/SDL_evdev.c
+++ b/src/core/linux/SDL_evdev.c
@@ -32,10 +32,11 @@
#include "SDL_evdev.h"
#include "SDL_evdev_kbd.h"
-#include <sys/stat.h>
-#include <unistd.h>
+#include <errno.h>
#include <fcntl.h>
+#include <unistd.h>
#include <sys/ioctl.h>
+#include <sys/stat.h>
#include <linux/input.h>
#include "../../events/SDL_events_c.h"
@@ -674,7 +675,8 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
if (ret < 0) {
SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen name");
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed to get evdev touchscreen name");
+ return false;
}
item->touchscreen_data->name = SDL_strdup(name);
@@ -687,7 +689,8 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
if (ret < 0) {
SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed to get evdev touchscreen limits");
+ return false;
}
if (abs_info.maximum == 0) {
@@ -704,7 +707,8 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
if (ret < 0) {
SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed to get evdev touchscreen limits");
+ return false;
}
item->touchscreen_data->min_x = abs_info.minimum;
item->touchscreen_data->max_x = abs_info.maximum;
@@ -714,7 +718,8 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
if (ret < 0) {
SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed to get evdev touchscreen limits");
+ return false;
}
item->touchscreen_data->min_y = abs_info.minimum;
item->touchscreen_data->max_y = abs_info.maximum;
@@ -724,7 +729,8 @@ static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
if (ret < 0) {
SDL_free(item->touchscreen_data->name);
SDL_free(item->touchscreen_data);
- return SDL_SetError("Failed to get evdev touchscreen limits");
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Failed to get evdev touchscreen limits");
+ return false;
}
item->touchscreen_data->min_pressure = abs_info.minimum;
item->touchscreen_data->max_pressure = abs_info.maximum;
@@ -908,8 +914,9 @@ static bool SDL_EVDEV_device_added(const char *dev_path, int udev_class)
item->fd = open(dev_path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (item->fd < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Couldn't open %s: %s", dev_path, strerror(errno));
SDL_free(item);
- return SDL_SetError("Unable to open %s", dev_path);
+ return false;
}
item->path = SDL_strdup(dev_path);