[libhid-discuss] libhid problems with interrupt_read/write

Charles Lepple clepple at ghz.cc
Thu Apr 5 18:58:18 UTC 2007


Thomas Maclean wrote:
>
> Greetings:
>
> Please excuse me if this is the wrong forum to ask about libhid usage
> problems ...

you've come to the right place.

> I am trying to debug a problem I am having with Bruce Perens' Ion
> software, which uses libhid to access a USB HID-connected home automation
> controller.  (See http://www.perens.com/Ion/ )
>
> The software uses hid_interrupt_write and and
> hid_interrupt_read to access the controller.  I am using libhid-svn
> (changelist 330) on a Centos 4 platform  (a redhat clone), with
> libusb-0.1.8-3.

Which kernel version does CentOS 4 use?

> The software compiles without problem.  The first time it runs fine, the
> second and subsequent times, it segfaults.  (If I run it under gdb, it
> segafaults every second time only.)  Ion has a call to hid_interrupt_write
> in the main function.  If I wrap this call in a function call in another
> function, it doesn't crash, but frequently returns 21.  If I add unrelated
> lines of code (like a new case in a switch statement that desn't do
> anything!), it sometimes segfaults.
>
> I stripped down the code to the point where it writes the command to the
> HID and then fecthes any available bytes from the output HID, in a loop
> every 0.5 seconds (20 times). I added calls to hid_set_debug and
> hid_set_debug_stream.  In my stripped-down version, it seems that write
> works the first time, reads work and then the second write fails and
> subsequent reads fail. hid_close works.  My stripped-down version doens't
> segfault (but doesn't do anything useful!)
>
> My questions:
>
> 1)  How stable is the libhid code in SVN? (i.e. is it believed robust, or
> highly experimental?)  No criticism implied ... I'm new around here and I
> don't know.

I would consider it stable, but then again, I don't really exercise it
that much. The trunk is essentially a "release candidate" for 0.2.16, if
you want to look at it that way. (I tend to make branches for things that
might destabilize the trunk.) Also, nothing has really changed in the code
recently - most of the changes have been to try and address shortcomings
in the build process.

A lot of what libhid does is abstraction - a determined programmer could
replace most of the libhid calls with libusb calls one-for-one, at the
expense of readability. The original plan (which is still being kicked
around) was to enable programmers to use the same API but use libusb in
Linux, Win32 calls on Windows, etc.

> 2) Any suggestions as to why I might be seeing segfaults (in believed good
> code)?

Not offhand - can you post a snippet of code that shows how you are
allocating buffers, etc.?

> 3) Any idea why me second write fails? What should I be doing differently?

Hard to say. See #2.

-- 
Charles Lepple
clepple at ghz.cc




More information about the libhid-discuss mailing list