[英]Segmentation fault in libusb 1.0 program when run as user, not as sudo
I'm writing a camera capture program that uses libusb 1.0 and cImg. 我正在编写一个使用libusb 1.0和cImg的相机捕获程序。 It connects to my Atik 314L astronomy camera and captures images to display on screen.
它连接到我的Atik 314L天文相机,并捕获图像以显示在屏幕上。 It compiles fine when compiled as regular or superuser and runs well when executed as a root user, but generates a segmentation fault when run any other way.
当以常规或超级用户身份编译时,它可以很好地编译,以根用户身份运行时,它可以很好地运行,但是以任何其他方式运行时,都会产生分段错误 。
I'm using Code::Blocks , and the call stack shows that the segmentation fault happens when calling the usb_control_msg()
function: 我正在使用Code :: Blocks ,并且调用堆栈显示在调用
usb_control_msg()
函数时发生分段错误:
#0 (usb_control_msg(dev=0x0, requesttype=64, request=160, value=58880, index=0 bytes=0x7fffffffe5df "\001 \346\377\377\377\177", size=1, timeout=500) (linux.c:152)
I'm rather new to programming in a Linux environment, and I'm not sure what to do to get this to run for normal users. 我对Linux环境中的编程很陌生,而且我不确定该如何为普通用户运行它。 Here are the steps I've tried so far:
到目前为止,这是我尝试过的步骤:
/etc/udev/rules.d
that went a little something like this: PROGRAM="/home/[username]/git/camera/prog", MODE="0660", GROUP="camera" /etc/udev/rules.d
,如下所示:PROGRAM =“ / home / [用户名] / git / camera / prog”,MODE =“ 0660”,GROUP =“ camera” I'm learning how to debug as I go, so if you need logs or anything to see what's wrong, just let me know. 我正在学习如何进行调试,因此,如果您需要日志或其他任何东西以查看有什么问题,请告诉我。
You possibly need to set/get the flags of the device using a function like fnctl()
, and according to your requirement you can set the file access mode ( O_RDONLY / O_WRONLY / O_RDWR
) and file creation flags ( O_CREAT / O_EXCL / O_NOCTTY / O_TRUNC
). 您可能需要使用诸如
fnctl()
类的功能来设置/获取设备的标志,并且根据您的要求,您可以设置文件访问模式( O_RDONLY / O_WRONLY / O_RDWR
)和文件创建标志( O_CREAT / O_EXCL / O_NOCTTY / O_TRUNC
)。 However, on Linux this command can change only the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME
and O_NONBLOCK
flags. 但是,在Linux上,此命令只能更改
O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME
和O_NONBLOCK
标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.