Linux udev 规则似乎不起作用
我正在编写一个必须在 Fedora Core 4 上运行的应用程序。该应用程序需要在没有 root 权限的情况下访问 USB 设备。使用 libusb-1.0.8 我已经成功编写了应用程序,除了一个问题。如果我没有 root 权限,libusb_open 将失败并显示 -3“权限被拒绝”。
我读到可以使用 udev 规则更改设备的权限。因此,我使用以下行将 10-local.rules 添加到 /etc/udev/rules.d 中:
BUS=="usb", SYSFS{idVendor}=="040a", SYSFS{idProduct}=="4e00", MODE="0666"
我从 udevinfo 的输出中复制了上述信息。
即使采用上述规则,设备权限始终以“0644”结尾,并且我无法从用户应用程序打开 USB 设备。即使重新启动后。
有人对我可能做错了什么有什么建议吗? Fedora Core 4 支持我想做的事情吗? 谢谢
I am writing an application that MUST run on Fedora Core 4. The application needs to access a USB device WITHOUT root privileges. Using libusb-1.0.8 I have successfully written the application except for one problem. If I do not have root privileges, libusb_open fails with -3 "Permission Denied".
I've read that I can alter the permissions of the device with a udev rule. And so I added 10-local.rules to /etc/udev/rules.d with the following line:
BUS=="usb", SYSFS{idVendor}=="040a", SYSFS{idProduct}=="4e00", MODE="0666"
I copied the above information from the output of udevinfo.
Even with the above rule, the device permissions always end up "0644" and I cannot open the USB device from a user application. Even after rebooting.
Does anyone have any suggestions as to what I may be doing wrong?
Does Fedora Core 4 support what I am trying to do?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Udev 在脚本运行后设置 USB 权限。重命名您的规则,使文件名以大于 50 的数字开头(USB 权限在 /lib/udev/rules.d/50-udev-default.rules 中设置)。由于您的脚本名称是 10-...,因此首先运行它,然后重置权限。将文件名更改为例如 99-local.rules。然后它将是最后运行的脚本之一,并且任何设置都不会被覆盖。
来源:http://virtuallyhyper.com/ 2013/02/修复-android-phone-device-permissions-on-fedora-17/
Udev sets usb permissions after your script runs. Rename your rule so that the filename starts with a number greater than 50 (USB Permissions are set in the /lib/udev/rules.d/50-udev-default.rules). Since your script name is 10-..., it is run first, then the permissions are reset. Changing the filename to, for example, 99-local.rules. Then it will be one of the last scripts run, and none of the settings will be overwritten.
Source: http://virtuallyhyper.com/2013/02/fixing-android-phone-device-permissions-on-fedora-17/
尝试如下:
udev 规则中的条件充其量是棘手的。您可以使用该命令检查哪些参数可用:
输出还包括以下通知:
另请注意某些属性名称中的结尾 S。它出现在父设备中,但不出现在设备本身中。
Try something like:
Conditions in the udev rules are tricky at best. You can check what parameter are available with the command:
The output also includes the following notice:
Also note the ending S in some attribute names. It appears in the parent devices, but not in the device itself.
根据 Linux 的版本(HAL、udev、hotplug 等),修改 USB 设备的权限似乎至少可以通过 3 种不同的方式进行处理。经过几次失败的尝试后,我终于找到了一个提供准确信息的网站。
至少对于 Linux 2.6.11,答案是热插拔。解决方案是在 /etc/hotplug/usb 中创建自定义用户映射文件。以内置用户映射(/etc/hotplug/usb.usermap)为例。用户映射文件指定连接匹配设备时要执行的脚本。该脚本还应位于 /etc/hotplug/usb 中。
例如,我使用设备的 VID 和 PID 以及要执行的名为 chmodmyusbdvc 的脚本创建了 /etc/hotplug/usb/myusbdvc.usermap。
我还创建了 /etc/hotplug/usb/chmodmyusbdvc ,内容如下:
Modifiying permissions for USB devices seems to be handled at least 3 different ways depending on the version of Linux (HAL, udev, hotplug, etc.). After several unsuccessful attempts I finally came across a site with accurate information.
For Linux 2.6.11 at least, the answer is hotplug. The solution is to create a custom usermap file in /etc/hotplug/usb. Use the built-in usermap (/etc/hotplug/usb.usermap) as an example. The usermap file specifies a script to execute when a matching device is connected. The script should also be located in /etc/hotplug/usb.
For example, I created /etc/hotplug/usb/myusbdvc.usermap with the VID and PID of my device and a script to execute named chmodmyusbdvc.
I also created /etc/hotplug/usb/chmodmyusbdvc with the follow contents: