Skip to contentSkip to conversation

leds: triggers: send uevent when changing triggers

PATCH In review Colin Cross 4 participants 9 messages Aug 7, 2012 – Aug 27, 2012 LED

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 leds: triggers: send uevent when changing triggers

Some triggers create sysfs files when they are enabled. Send a uevent "change" notification whenever the trigger is changed to allow userspace processes such as udev to modify permissions on the new files.

A change notification will also be sent during registration of led class devices or led triggers if the default trigger of an led class device is found.

---
 drivers/leds/led-triggers.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
drivers/leds/led-triggers.c +13 -0
index 46b4c76..a85ce09 100644
@@ -102,6 +102,12 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
 void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger)
 {
 	unsigned long flags;
+	char *event = NULL;
+	char *envp[2];
+	const char *name;
+
+	name = trigger ? trigger->name : "none";
+	event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name);
 
 	/* Remove any existing trigger */
 	if (led_cdev->trigger) {
@@ -122,6 +128,13 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger)
 		if (trigger->activate)
 			trigger->activate(led_cdev);
 	}
+
+	if (event) {
+		envp[0] = event;
+		envp[1] = NULL;
+		kobject_uevent_env(&led_cdev->dev->kobj, KOBJ_CHANGE, envp);
+		kfree(event);
+	}
 }
 EXPORT_SYMBOL_GPL(led_trigger_set);
 
Signature · 1 line
1.7.7.3
#1 lore raw
Quoted 7 lines · Colin Cross

Some triggers create sysfs files when they are enabled. Send a uevent "change" notification whenever the trigger is changed to allow userspace processes such as udev to modify permissions on the new files.

A change notification will also be sent during registration of led class devices or led triggers if the default trigger of an led class device is found.

Why would a change event be needed at this point in time? Nothing would have changed from the original "add" notification, right?

greg k-h

#2 lore raw
Quoted 11 lines · Greg KH
Quoted 7 lines · Colin Cross

Some triggers create sysfs files when they are enabled. Send a uevent "change" notification whenever the trigger is changed to allow userspace processes such as udev to modify permissions on the new files.

A change notification will also be sent during registration of led class devices or led triggers if the default trigger of an led class device is found.

Why would a change event be needed at this point in time? Nothing would have changed from the original "add" notification, right?

If the led class device has a default trigger configured, device_create will called before the trigger has been set and the trigger sysfs files have been created. The "change" notification will happen after the extra files have been created.

#3 lore raw
Quoted 10 lines · Colin Cross
Quoted 9 lines · Greg KH
Quoted 7 lines · Colin Cross

Some triggers create sysfs files when they are enabled. Send a uevent "change" notification whenever the trigger is changed to allow userspace processes such as udev to modify permissions on the new files.

A change notification will also be sent during registration of led class devices or led triggers if the default trigger of an led class device is found.

Quoted 7 lines
Quoted 2 lines

Why would a change event be needed at this point in time? Nothing would have changed from the original "add" notification, right?

If the led class device has a default trigger configured, device_create will called before the trigger has been set and the trigger sysfs files have been created. The "change" notification will happen after the extra files have been created.

Ok, that make sense, and is a good reason to send the change event, thanks for explaining it.

greg k-h

Acked-by on v2 1/1
#4 lore raw
In reply to Colin Cross
Quoted 9 lines · Colin Cross

Some triggers create sysfs files when they are enabled. Send a uevent "change" notification whenever the trigger is changed to allow userspace processes such as udev to modify permissions on the new files.

A change notification will also be sent during registration of led class devices or led triggers if the default trigger of an led class device is found.

Acked-by on v2 1/1
#5 lore raw
In reply to Colin Cross
Quoted 9 lines · Colin Cross

Some triggers create sysfs files when they are enabled. Send a uevent "change" notification whenever the trigger is changed to allow userspace processes such as udev to modify permissions on the new files.

A change notification will also be sent during registration of led class devices or led triggers if the default trigger of an led class device is found.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#6 lore raw
Quoted 5 lines · Henrique de Moraes Holschuh
Quoted 4 lines · Colin Cross

Some triggers create sysfs files when they are enabled. Send a uevent "change" notification whenever the trigger is changed to allow userspace processes such as udev to modify permissions on the new files.

Quoted 8 lines
Quoted 5 lines

A change notification will also be sent during registration of led class devices or led triggers if the default trigger of an led class device is found.

Colin, could you please resend an update patch with some documentations as Henrique pointed out? Then I will add Ack from Henrique and Greg and apply this patch.

Thanks,
-Bryan

#7 lore raw
Quoted 11 lines · Bryan Wu
Quoted 9 lines · Henrique de Moraes Holschuh
Quoted 8 lines · Colin Cross

Some triggers create sysfs files when they are enabled. Send a uevent "change" notification whenever the trigger is changed to allow userspace processes such as udev to modify permissions on the new files.

A change notification will also be sent during registration of led class devices or led triggers if the default trigger of an led class device is found.

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Colin, could you please resend an update patch with some documentations as Henrique pointed out? Then I will add Ack from Henrique and Greg and apply this patch.

Colin, will you update the patch or just keep this one.

-Bryan

#8 lore raw

My bad. I apologize to the delay. I missed the v2 original patch email in this thread, but googled and found it.
Applied to my for-next branch now.

Thanks,
-Bryan

Quoted 25 lines · Bryan Wu
Quoted 11 lines · Bryan Wu
Quoted 9 lines · Henrique de Moraes Holschuh
Quoted 8 lines · Colin Cross

Some triggers create sysfs files when they are enabled. Send a uevent "change" notification whenever the trigger is changed to allow userspace processes such as udev to modify permissions on the new files.

A change notification will also be sent during registration of led class devices or led triggers if the default trigger of an led class device is found.

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Colin, could you please resend an update patch with some documentations as Henrique pointed out? Then I will add Ack from Henrique and Greg and apply this patch.

Colin, will you update the patch or just keep this one.

-Bryan

Signature · 4 lines
Bryan Wu <[email protected]>
Kernel Developer    +86.186-168-78255 Mobile
Canonical Ltd.      www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com