简体   繁体   中英

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. It connects to my Atik 314L astronomy camera and captures images to display on screen. 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:

#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. Here are the steps I've tried so far:

  1. Add my user to all user groups to see if it's a group permissions issue (heck-- I even tried adding myself to "root", but it didn't do anything)
  2. Add a rule to /etc/udev/rules.d that went a little something like this: PROGRAM="/home/[username]/git/camera/prog", MODE="0660", GROUP="camera"
  3. Try to change permissions of the program itself to 777. That was a last ditch effort though-- I didn't really expect it to work.

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 ). However, on Linux this command can change only the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME and O_NONBLOCK flags.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM