Using Sysfs uevents.

Greg KH greg at kroah.com
Wed Feb 15 12:06:19 EST 2012


On Wed, Feb 15, 2012 at 06:17:28PM +0530, Pranay Kumar Srivastava wrote:
> Hi,
> 
> I was playing with sysfs and I'm able to create kset and kobjects
> within them as well.

Nice, but why?  Almost no one ever should be touching "raw" sysfs
kobjects and ksets.

> I need to know how do I use the uevents of these kobjects that I
> create. For example while reading the code I found that certain events
> like ADD, DEL a couple more were there are apparently fired. Now
> currently I'm not handling these events, the ops field is null, so
> they don't bother me hence they are not mandatory?

They are created by the kobject core automatically for you.

> If I were to actually do something with these events what it should
> be? Since my module runs fine and the uevents are supposed to be for
> userland applications (Hotplug) but the point is again how will a
> userspace application get to know about it? Does the application needs
> to create netlink sockets for it? If it does then why bother with the
> uevents of kobject?

No, udev grabs all of these events and allows other programs to
subscribe to it and get that information.  You don't have to write your
own program to do this, the infrastructure is all there already.

But I wouldn't really worry about it to much, you shouldn't be messing
with kobjects directly anyway, why not use 'struct device' instead?

thanks,

greg k-h



More information about the Kernelnewbies mailing list