All of lore.kernel.org
 help / color / mirror / Atom feed
* Sysfs properties with libudev (for example capabilities/key)
@ 2010-10-30 21:17 Laszlo Papp
  2010-10-30 21:23 ` Laszlo Papp
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Laszlo Papp @ 2010-10-30 21:17 UTC (permalink / raw)
  To: linux-hotplug

Hi,

I would like to get the capabilities/key entry from sysfs for my
keyboard for example with libudev library.

From the documentation:
http://www.signal11.us/oss/udev/
'Any non-directory file or link in that directory can be queried with
udev_device_get_sysattr_value() to determine the properties of the
device.'

Hence in essence: the problem is that I can use
udev_device_get_sysattr_value(dev,"idVendor") way only for simple
files under the related sysfs entry, but I would to use in case a
'hello/world' file where 'hello' is the directory which contains the
'world' file. I hope I was clear, but feel free to contact me if you
need help with anything about the clarification. Thank you in advance!

Best Regards,
Laszlo Papp

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Sysfs properties with libudev (for example capabilities/key)
  2010-10-30 21:17 Sysfs properties with libudev (for example capabilities/key) Laszlo Papp
@ 2010-10-30 21:23 ` Laszlo Papp
  2010-10-31  1:39 ` Greg KH
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Laszlo Papp @ 2010-10-30 21:23 UTC (permalink / raw)
  To: linux-hotplug

Hi,

I would like to get the capabilities/key entry from sysfs for my
keyboard for example with libudev library.

From the documentation:
http://www.signal11.us/oss/udev/
'Any non-directory file or link in that directory can be queried with
udev_device_get_sysattr_value() to determine the properties of the
device.'

Hence in essence: the problem is that I can use
udev_device_get_sysattr_value(dev,"idVendor") way only for simple
files under the related sysfs entry, but I would to use in case a
'hello/world' file where 'hello' is the directory which contains the
'world' file. I hope I was clear, but feel free to contact me if you
need help with anything about the clarification. Thank you in advance!

Best Regards,
Laszlo Papp

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sysfs properties with libudev (for example capabilities/key)
  2010-10-30 21:17 Sysfs properties with libudev (for example capabilities/key) Laszlo Papp
  2010-10-30 21:23 ` Laszlo Papp
@ 2010-10-31  1:39 ` Greg KH
  2010-10-31 14:04 ` Laszlo Papp
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2010-10-31  1:39 UTC (permalink / raw)
  To: linux-hotplug

On Sat, Oct 30, 2010 at 02:17:20PM -0700, Laszlo Papp wrote:
> Hi,
> 
> I would like to get the capabilities/key entry from sysfs for my
> keyboard for example with libudev library.

Have you tried it?  It works here for me using libudev, do you have a
pointer to your code that does not work properly?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sysfs properties with libudev (for example capabilities/key)
  2010-10-30 21:17 Sysfs properties with libudev (for example capabilities/key) Laszlo Papp
  2010-10-30 21:23 ` Laszlo Papp
  2010-10-31  1:39 ` Greg KH
@ 2010-10-31 14:04 ` Laszlo Papp
  2010-10-31 14:23 ` Greg KH
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Laszlo Papp @ 2010-10-31 14:04 UTC (permalink / raw)
  To: linux-hotplug

Hi,

You can check the code out more in-depth in the following with the
produced output. This is the compilation command I used for testing:
gcc -Wall -o test -ggdb -ludev  main.c.

I just would like to get the real input devices.. so VID/PID: (null)
(null) and related device node entries are undesired. In essence I get
more outputs that I would expect because I expect the real entries
where I can use sysattr later and so on. I have just checked
get_parent method, but that did not help me too much.

Thank you in advance!

Best Regards,
Laszlo Papp

[code]

#include <libudev.h>
#include <stdio.h>

int main()
{
    struct udev *udev;
    struct udev_enumerate *enumerate;
    struct udev_list_entry *devices;
    struct udev_list_entry *dev_list_entry;
    struct udev_device *dev;

    udev = udev_new();
    if (!udev) {
        printf("Cannot create udev\n");
        return -1;
    }

    enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "input");
    udev_enumerate_scan_devices(enumerate);
    devices = udev_enumerate_get_list_entry(enumerate);

    udev_list_entry_foreach(dev_list_entry, devices) {
        const char *path;
        path = udev_list_entry_get_name(dev_list_entry);
        dev = udev_device_new_from_syspath(udev, path);
        printf("Device Node Path: %s, Name: %s\r\n", path,
                udev_device_get_sysattr_value(dev, "name"));
        printf("VID/PID: %s %s\r\n",
                udev_device_get_sysattr_value(dev,"id/vendor"),
                udev_device_get_sysattr_value(dev, "id/product"));
        udev_device_unref(dev);
    }

    udev_enumerate_unref(enumerate);
    udev_unref(udev);

    return 0;
}

[/code]

Device Node Path: /sys/devices/LNXSYSTM:00/LNXPWRBN:00/input/input3,
Name: Power Button
VID/PID: 0000 0001
Device Node Path:
/sys/devices/LNXSYSTM:00/LNXPWRBN:00/input/input3/event3, Name: (null)
VID/PID: (null) (null)
Device Node Path:
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input2, Name:
Power Button
VID/PID: 0000 0001
Device Node Path:
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input2/event2,
Name: (null)
VID/PID: (null) (null)
Device Node Path:
/sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5,
Name: Logitech USB Optical Mouse
VID/PID: 046d c00c
Device Node Path:
/sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5/event5,
Name: (null)
VID/PID: (null) (null)
Device Node Path:
/sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5/mouse1,
Name: (null)
VID/PID: (null) (null)
Device Node Path: /sys/devices/pci0000:00/0000:00:09.0/input/input6,
Name: HDA Digital PCBeep
VID/PID: 10ec 0662
Device Node Path:
/sys/devices/pci0000:00/0000:00:09.0/input/input6/event6, Name: (null)
VID/PID: (null) (null)
Device Node Path: /sys/devices/platform/i8042/serio0/input/input1,
Name: AT Translated Set 2 keyboard
VID/PID: 0001 0001
Device Node Path:
/sys/devices/platform/i8042/serio0/input/input1/event1, Name: (null)
VID/PID: (null) (null)
Device Node Path: /sys/devices/platform/pcspkr/input/input4, Name: PC Speaker
VID/PID: 001f 0001
Device Node Path: /sys/devices/platform/pcspkr/input/input4/event4, Name: (null)
VID/PID: (null) (null)
Device Node Path: /sys/devices/virtual/input/input0, Name: Macintosh
mouse button emulation
VID/PID: 0001 0001
Device Node Path: /sys/devices/virtual/input/input0/event0, Name: (null)
VID/PID: (null) (null)
Device Node Path: /sys/devices/virtual/input/input0/mouse0, Name: (null)
VID/PID: (null) (null)
Device Node Path: /sys/devices/virtual/input/mice, Name: (null)
VID/PID: (null) (null)



On Sat, Oct 30, 2010 at 6:39 PM, Greg KH <greg@kroah.com> wrote:
> On Sat, Oct 30, 2010 at 02:17:20PM -0700, Laszlo Papp wrote:
>> Hi,
>>
>> I would like to get the capabilities/key entry from sysfs for my
>> keyboard for example with libudev library.
>
> Have you tried it?  It works here for me using libudev, do you have a
> pointer to your code that does not work properly?
>
> thanks,
>
> greg k-h
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sysfs properties with libudev (for example capabilities/key)
  2010-10-30 21:17 Sysfs properties with libudev (for example capabilities/key) Laszlo Papp
                   ` (2 preceding siblings ...)
  2010-10-31 14:04 ` Laszlo Papp
@ 2010-10-31 14:23 ` Greg KH
  2010-10-31 14:39 ` Laszlo Papp
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2010-10-31 14:23 UTC (permalink / raw)
  To: linux-hotplug

On Sun, Oct 31, 2010 at 07:04:30AM -0700, Laszlo Papp wrote:
> Hi,
> 
> You can check the code out more in-depth in the following with the
> produced output. This is the compilation command I used for testing:
> gcc -Wall -o test -ggdb -ludev  main.c.
> 
> I just would like to get the real input devices.. so VID/PID: (null)
> (null) and related device node entries are undesired.

But those are "real" input devices, why do you think otherwise?

If you don't want them, then filter them out by ignoring the event
types, but note that they are needed by your system to work properly
(i.e. x.org uses them.)

So your code is working as designed, I just don't think that you
realized there are all of these input devices present :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sysfs properties with libudev (for example capabilities/key)
  2010-10-30 21:17 Sysfs properties with libudev (for example capabilities/key) Laszlo Papp
                   ` (3 preceding siblings ...)
  2010-10-31 14:23 ` Greg KH
@ 2010-10-31 14:39 ` Laszlo Papp
  2010-10-31 14:52 ` Laszlo Papp
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Laszlo Papp @ 2010-10-31 14:39 UTC (permalink / raw)
  To: linux-hotplug

On Sun, Oct 31, 2010 at 7:23 AM, Greg KH <greg@kroah.com> wrote:
> On Sun, Oct 31, 2010 at 07:04:30AM -0700, Laszlo Papp wrote:
>> Hi,
>>
>> You can check the code out more in-depth in the following with the
>> produced output. This is the compilation command I used for testing:
>> gcc -Wall -o test -ggdb -ludev  main.c.
>>
>> I just would like to get the real input devices.. so VID/PID: (null)
>> (null) and related device node entries are undesired.
>
> But those are "real" input devices, why do you think otherwise?
>
> If you don't want them, then filter them out by ignoring the event
> types, but note that they are needed by your system to work properly
> (i.e. x.org uses them.)
>
> So your code is working as designed, I just don't think that you
> realized there are all of these input devices present :)
>
> thanks,
>
> greg k-h
>

root /home/djszapi #  cat main.c
#include <libudev.h>
#include <stdio.h>

int main()
{
   struct udev *udev;
   struct udev_enumerate *enumerate;
   struct udev_list_entry *devices;
   struct udev_list_entry *dev_list_entry;
   struct udev_device *dev;

   udev = udev_new();
   if (!udev) {
       printf("Cannot create udev\n");
       return -1;
   }

   enumerate = udev_enumerate_new(udev);
   udev_enumerate_add_match_subsystem(enumerate, "input");
   udev_enumerate_scan_devices(enumerate);
   devices = udev_enumerate_get_list_entry(enumerate);

   udev_list_entry_foreach(dev_list_entry, devices) {
       const char *path;
       path = udev_list_entry_get_name(dev_list_entry);
       dev = udev_device_new_from_syspath(udev, path);
       dev = udev_device_get_parent_with_subsystem_devtype(dev, "input", 0);
       if (dev = 0)
           continue;

       printf("Device Node Path: %s, Name: %s\r\n", path,
               udev_device_get_sysattr_value(dev, "name"));
       printf("VID/PID: %s %s\r\n",
               udev_device_get_sysattr_value(dev,"id/vendor"),
               udev_device_get_sysattr_value(dev, "id/product"));
       udev_device_unref(dev);
   }

   udev_enumerate_unref(enumerate);
   udev_unref(udev);

   return 0;
}
root /home/djszapi #  ./test
Device Node Path:
/sys/devices/LNXSYSTM:00/LNXPWRBN:00/input/input3/event3, Name: Power
Button
VID/PID: 0000 0001
Device Node Path:
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input2/event2,
Name: Power Button
VID/PID: 0000 0001
Device Node Path:
/sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5/event5,
Name: Logitech USB Optical Mouse
VID/PID: 046d c00c
Device Node Path:
/sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5/mouse1,
Name: Logitech USB Optical Mouse
VID/PID: 046d c00c
Device Node Path:
/sys/devices/pci0000:00/0000:00:09.0/input/input6/event6, Name: HDA
Digital PCBeep
VID/PID: 10ec 0662
Device Node Path:
/sys/devices/platform/i8042/serio0/input/input1/event1, Name: AT
Translated Set 2 keyboard
VID/PID: 0001 0001
Device Node Path: /sys/devices/platform/pcspkr/input/input4/event4,
Name: PC Speaker
VID/PID: 001f 0001
Device Node Path: /sys/devices/virtual/input/input0/event0, Name:
Macintosh mouse button emulation
VID/PID: 0001 0001
Device Node Path: /sys/devices/virtual/input/input0/mouse0, Name:
Macintosh mouse button emulation
VID/PID: 0001 0001
root /home/djszapi #

Better, but every device occurs two times o_O

Best Regards,
Laszlo Papp

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sysfs properties with libudev (for example capabilities/key)
  2010-10-30 21:17 Sysfs properties with libudev (for example capabilities/key) Laszlo Papp
                   ` (4 preceding siblings ...)
  2010-10-31 14:39 ` Laszlo Papp
@ 2010-10-31 14:52 ` Laszlo Papp
  2010-10-31 16:09 ` Laszlo Papp
  2010-10-31 20:54 ` Greg KH
  7 siblings, 0 replies; 9+ messages in thread
From: Laszlo Papp @ 2010-10-31 14:52 UTC (permalink / raw)
  To: linux-hotplug

On Sun, Oct 31, 2010 at 7:39 AM, Laszlo Papp <djszapi@archlinux.us> wrote:
> On Sun, Oct 31, 2010 at 7:23 AM, Greg KH <greg@kroah.com> wrote:
>> On Sun, Oct 31, 2010 at 07:04:30AM -0700, Laszlo Papp wrote:
>>> Hi,
>>>
>>> You can check the code out more in-depth in the following with the
>>> produced output. This is the compilation command I used for testing:
>>> gcc -Wall -o test -ggdb -ludev  main.c.
>>>
>>> I just would like to get the real input devices.. so VID/PID: (null)
>>> (null) and related device node entries are undesired.
>>
>> But those are "real" input devices, why do you think otherwise?
>>
>> If you don't want them, then filter them out by ignoring the event
>> types, but note that they are needed by your system to work properly
>> (i.e. x.org uses them.)
>>
>> So your code is working as designed, I just don't think that you
>> realized there are all of these input devices present :)
>>
>> thanks,
>>
>> greg k-h
>>
>
> root /home/djszapi #  cat main.c
> #include <libudev.h>
> #include <stdio.h>
>
> int main()
> {
>    struct udev *udev;
>    struct udev_enumerate *enumerate;
>    struct udev_list_entry *devices;
>    struct udev_list_entry *dev_list_entry;
>    struct udev_device *dev;
>
>    udev = udev_new();
>    if (!udev) {
>        printf("Cannot create udev\n");
>        return -1;
>    }
>
>    enumerate = udev_enumerate_new(udev);
>    udev_enumerate_add_match_subsystem(enumerate, "input");
>    udev_enumerate_scan_devices(enumerate);
>    devices = udev_enumerate_get_list_entry(enumerate);
>
>    udev_list_entry_foreach(dev_list_entry, devices) {
>        const char *path;
>        path = udev_list_entry_get_name(dev_list_entry);
>        dev = udev_device_new_from_syspath(udev, path);
>        dev = udev_device_get_parent_with_subsystem_devtype(dev, "input", 0);
>        if (dev = 0)
>            continue;
>
>        printf("Device Node Path: %s, Name: %s\r\n", path,
>                udev_device_get_sysattr_value(dev, "name"));
>        printf("VID/PID: %s %s\r\n",
>                udev_device_get_sysattr_value(dev,"id/vendor"),
>                udev_device_get_sysattr_value(dev, "id/product"));
>        udev_device_unref(dev);
>    }
>
>    udev_enumerate_unref(enumerate);
>    udev_unref(udev);
>
>    return 0;
> }
> root /home/djszapi #  ./test
> Device Node Path:
> /sys/devices/LNXSYSTM:00/LNXPWRBN:00/input/input3/event3, Name: Power
> Button
> VID/PID: 0000 0001
> Device Node Path:
> /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input2/event2,
> Name: Power Button
> VID/PID: 0000 0001
> Device Node Path:
> /sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5/event5,
> Name: Logitech USB Optical Mouse
> VID/PID: 046d c00c
> Device Node Path:
> /sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5/mouse1,
> Name: Logitech USB Optical Mouse
> VID/PID: 046d c00c
> Device Node Path:
> /sys/devices/pci0000:00/0000:00:09.0/input/input6/event6, Name: HDA
> Digital PCBeep
> VID/PID: 10ec 0662
> Device Node Path:
> /sys/devices/platform/i8042/serio0/input/input1/event1, Name: AT
> Translated Set 2 keyboard
> VID/PID: 0001 0001
> Device Node Path: /sys/devices/platform/pcspkr/input/input4/event4,
> Name: PC Speaker
> VID/PID: 001f 0001
> Device Node Path: /sys/devices/virtual/input/input0/event0, Name:
> Macintosh mouse button emulation
> VID/PID: 0001 0001
> Device Node Path: /sys/devices/virtual/input/input0/mouse0, Name:
> Macintosh mouse button emulation
> VID/PID: 0001 0001
> root /home/djszapi #
>
> Better, but every device occurs two times o_O
>
> Best Regards,
> Laszlo Papp
>

root /sys/devices/platform/i8042/serio0/input/input1 #  cd /home/djszapi/
root /home/djszapi #  cat main.c
#include <libudev.h>
#include <stdio.h>

int main()
{
    struct udev *udev;
    struct udev_enumerate *enumerate;
    struct udev_list_entry *devices;
    struct udev_list_entry *dev_list_entry;
    struct udev_device *dev;
    struct udev_device *parent_dev;

    udev = udev_new();
    if (!udev) {
        printf("Cannot create udev\n");
        return -1;
    }

    enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "input");
    udev_enumerate_scan_devices(enumerate);
    devices = udev_enumerate_get_list_entry(enumerate);

    udev_list_entry_foreach(dev_list_entry, devices) {
        const char *path;
        path = udev_list_entry_get_name(dev_list_entry);
        dev = udev_device_new_from_syspath(udev, path);
        parent_dev udev_device_get_parent_with_subsystem_devtype(dev, "input", 0);
        if (parent_dev) {
            udev_device_unref(parent_dev);
            continue;
        }

        printf("Device Node Path: %s, Name: %s\r\n", path,
                udev_device_get_sysattr_value(dev, "name"));
        printf("VID/PID: %s %s\r\n",
                udev_device_get_sysattr_value(dev,"id/vendor"),
                udev_device_get_sysattr_value(dev, "id/product"));
        udev_device_unref(dev);
    }

    udev_enumerate_unref(enumerate);
    udev_unref(udev);

    return 0;
}
root /home/djszapi #  gcc -Wall -o test -ggdb -ludev  main.c
root /home/djszapi #  ./test
Device Node Path: /sys/devices/LNXSYSTM:00/LNXPWRBN:00/input/input3,
Name: Power Button
VID/PID: 0000 0001
Device Node Path:
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input2, Name:
Power Button
VID/PID: 0000 0001
Device Node Path:
/sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5,
Name: Logitech USB Optical Mouse
VID/PID: 046d c00c
Device Node Path: /sys/devices/pci0000:00/0000:00:09.0/input/input6,
Name: HDA Digital PCBeep
VID/PID: 10ec 0662
Device Node Path: /sys/devices/platform/i8042/serio0/input/input1,
Name: AT Translated Set 2 keyboard
VID/PID: 0001 0001
Device Node Path: /sys/devices/platform/pcspkr/input/input4, Name: PC Speaker
VID/PID: 001f 0001
Device Node Path: /sys/devices/virtual/input/input0, Name: Macintosh
mouse button emulation
VID/PID: 0001 0001
Device Node Path: /sys/devices/virtual/input/mice, Name: (null)
VID/PID: (null) (null)
root /home/djszapi #

OK, seems to work, but please fix me, if this is not the way to do it.

Best Regards,
Laszlo Papp

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sysfs properties with libudev (for example capabilities/key)
  2010-10-30 21:17 Sysfs properties with libudev (for example capabilities/key) Laszlo Papp
                   ` (5 preceding siblings ...)
  2010-10-31 14:52 ` Laszlo Papp
@ 2010-10-31 16:09 ` Laszlo Papp
  2010-10-31 20:54 ` Greg KH
  7 siblings, 0 replies; 9+ messages in thread
From: Laszlo Papp @ 2010-10-31 16:09 UTC (permalink / raw)
  To: linux-hotplug

Hi,

My further question is that whether libudev can help me to handle
input events, like keyboard, mouse, touch presses ? What is the best
to do that in a userspace input system where I would like to avoid the
'root' usage, 'root' privileges so that simple users can use it.

Best Regards,
Laszlo Papp

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sysfs properties with libudev (for example capabilities/key)
  2010-10-30 21:17 Sysfs properties with libudev (for example capabilities/key) Laszlo Papp
                   ` (6 preceding siblings ...)
  2010-10-31 16:09 ` Laszlo Papp
@ 2010-10-31 20:54 ` Greg KH
  7 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2010-10-31 20:54 UTC (permalink / raw)
  To: linux-hotplug

On Sun, Oct 31, 2010 at 09:09:03AM -0700, Laszlo Papp wrote:
> Hi,
> 
> My further question is that whether libudev can help me to handle
> input events, like keyboard, mouse, touch presses ?

No, that is what x.org is for.

> What is the best to do that in a userspace input system where I would
> like to avoid the 'root' usage, 'root' privileges so that simple users
> can use it.

See the x.org input subsystem code for examples of how to do this.

good luck,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-10-31 20:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-30 21:17 Sysfs properties with libudev (for example capabilities/key) Laszlo Papp
2010-10-30 21:23 ` Laszlo Papp
2010-10-31  1:39 ` Greg KH
2010-10-31 14:04 ` Laszlo Papp
2010-10-31 14:23 ` Greg KH
2010-10-31 14:39 ` Laszlo Papp
2010-10-31 14:52 ` Laszlo Papp
2010-10-31 16:09 ` Laszlo Papp
2010-10-31 20:54 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.