6

I am learning programming in embedded systems using Linux as my main platform. And I want to create a Device Event Management Service. This service is a user-space application/daemon that will detect if a connected hardware module triggered an event. But my problem is I don't know where should I start.

I read about Netlink implementation for userspace-kernelspace communication and it seems its a good idea but not sure if it is the best solution. But I read that the UDEV device manager uses Netlink to wait a "uevent" from the kernel space but it is not clear for me how to do that.

I read about polling sysfs but it seems it is not a good idea to poll filesystem.

What do you think the implementation that should I use in my service? Should I use netlink(hard/no clue how to) or just polling the sysfs(not sure if it works)?

Thanks

domlao
  • 15,663
  • 34
  • 95
  • 134
  • You could also us inotify to be notified when a directory in question in sysfs changes instead of polling. – MikeK Mar 02 '11 at 01:52

2 Answers2

1

If all you do is wait for an event you can use sysfs, which will be a lot simpler than netlink. An example is the GPIO system's edge file.

Hervé
  • 275
  • 4
  • 5
1

Yes, polling is ill-advised. These resources: LJ article on Netlink, "Understanding and Programming with Netlink Sockets" make it seem not so hard to do netlink. Here's an example of netlink sockets in python.

udevtrigger is a great utility for reacting to udev changes.

http://www.linuxjournal.com/article/7356

http://smacked.org/docs/netlink.pdf

http://guichaz.free.fr/misc/iotop.py

http://manpages.ubuntu.com/manpages/gutsy/man8/udevtrigger.8.html

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Brian Cain
  • 14,403
  • 3
  • 50
  • 88