Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netlink user-space and kernel-space communication

Tags:

linux

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

like image 651
domlao Avatar asked Jun 12 '10 01:06

domlao


2 Answers

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

like image 113
Brian Cain Avatar answered Oct 17 '22 12:10

Brian Cain


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.

like image 28
Hervé Avatar answered Oct 17 '22 10:10

Hervé