c - 打开/dev/hidraw2可以用steamcontroller挂

标签 c linux controller steam

我的问题是关于通过“/dev/hidraw2”打开 Steam Controller ,这有时会导致程序挂起。我最大的问题是我不知道在哪里报告这个问题,所以我希望有人知道该去哪里解决这个问题。

问题: 我有一个正在运行的 arch Linux,它有一个连接到它的 Steam Controller (与提供的加密狗连接)。 当尝试通过打开“/dev/hidraw2”来访问设备时,我的程序卡在了“打开”调用中。我的程序就是不返回。也不可能用 kill -9 杀死它。唯一的恢复方法是重新启动我的机器。

我将有问题的代码简化为:

// compiled with gcc main.c
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>

int main() {
    for(;;) {
        printf("opening steam controller\n");
        # It doesn't return from the following open
        int fd = open("/dev/hidraw2", O_RDWR | O_NONBLOCK | O_CLOEXEC);

        printf("closing steam controller\n");
        if (fd != -1) {
            close(fd);
        }
        usleep(100000);
    }
    return 0;
}

要重现,您必须插入 Steam Controller 加密狗,启动上述程序,然后打开 Steam Controller (它不会每次都挂起,因此您可能需要关闭 Controller 并重新打开)。

关于我的机器的更多信息:

$ uname -a
Linux schenker 4.20.7-arch1-1-ARCH #1 SMP PREEMPT Wed Feb 6 18:42:40 UTC 2019 x86_64 GNU/Linux
$ gcc --version                                                                                                   
gcc (GCC) 8.2.1 20181127

我如何调查有关此问题的更多信息?我是否必须深入了解 Steam Controller 驱动程序?还是 hidraw 层的问题更多?

更新:

请求dmesg 输出。重现错误需要三次尝试。我似乎没有怀疑:

[  141.161817] hid-steam 0003:28DE:1142.0002: Steam Controller 'XXXXXXXXXX' connected
[  141.163527] input: Wireless Steam Controller as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.1/0003:28DE:1142.0002/input/input34                                                                                                         
[  151.291873] input: Wireless Steam Controller as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.1/0003:28DE:1142.0002/input/input35                                                                                                         
[  152.940759] input: Wireless Steam Controller as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.1/0003:28DE:1142.0002/input/input36                                                                                                         
[  155.287349] input: Wireless Steam Controller as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.1/0003:28DE:1142.0002/input/input37                                                                                                         
[  160.634001] hid-steam 0003:28DE:1142.0002: Steam Controller 'XXXXXXXXXX' disconnected
[  172.665613] hid-steam 0003:28DE:1142.0002: Steam Controller 'XXXXXXXXXX' connected
[  172.667006] input: Wireless Steam Controller as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.1/0003:28DE:1142.0002/input/input38                                                                                                         
[  181.306918] hid-steam 0003:28DE:1142.0002: Steam Controller 'XXXXXXXXXX' disconnected
[  185.465807] hid-steam 0003:28DE:1142.0002: Steam Controller 'XXXXXXXXXX' connected
[  185.467249] input: Wireless Steam Controller as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.1/0003:28DE:1142.0002/input/input39                                                                                                         
[  187.030851] input: Wireless Steam Controller as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.1/0003:28DE:1142.0002/input/input40                                                                                                         
[  192.673722] hid-steam 0003:28DE:1142.0002: Steam Controller 'XXXXXXXXXX' disconnected
[  196.937743] hid-steam 0003:28DE:1142.0002: Steam Controller 'XXXXXXXXXX' connected
[  196.939272] input: Wireless Steam Controller as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.1/0003:28DE:1142.0002/input/input41

更新2 还有一些 strace 输出:

openat(AT_FDCWD, "/dev/hidraw1", O_RDWR|O_NONBLOCK|O_CLOEXEC) = 3
write(1, "closing steam controller /dev/hi"..., 38closing steam controller /dev/hidraw1
) = 38
close(3)                                = 0
nanosleep({tv_sec=0, tv_nsec=100000000}, NULL) = 0
write(1, "opening steam controller /dev/hi"..., 38opening steam controller /dev/hidraw1
) = 38
openat(AT_FDCWD, "/dev/hidraw1", O_RDWR|O_NONBLOCK|O_CLOEXEC

这个问题不仅限于hidraw2,hidraw1也会出现(我猜这取决于实际的steam Controller 连接到哪里)

我还注意到,当我的程序卡住并且我在另一个控制台上调用启动第二个实例时,它立即卡在 open() 上,与 Controller 的关闭/打开状态无关。

最佳答案

原来是hid_steam驱动与acpid交互时的bug。

我联系了 hid_steam 驱动程序的作者 (Rodrigo Rivas Costa),这是 LKML 协议(protocol)要做的正确事情(参见 http://vger.kernel.org/lkml/#s2-1 )

对我来说,短期解决方案是卸载 hid_steam,因为我正在直接访问/dev/hidrawX:

# modprobe -R hid_steam

Rodrigo 已经在开发补丁。 非常感谢 Rodrigo 如此快速地排除故障。 谢谢!

关于c - 打开/dev/hidraw2可以用steamcontroller挂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55077504/

相关文章:

c - C 中的 Malloc 2D 金字塔数组

python - 使用 Cython 将 C 函数创建的二维数组返回到 Python

Linux:可执行文件找不到共享库

spring - 在 Kotlin 上添加 Spring Security 后测试 Spring Controller POST 方法

c - Perl 结构流向 C

linux - 如何通过Linux命令 'grep'获得值

c - C中访问并运行/usr/bin程序

ruby-on-rails - 如何在没有模型的情况下创建 Controller 和操作?

javascript - AngularJS - 我的部分 Controller

c - 邻接表,分割一个数组并在c中搜索该数组中的单词