2012-08-07 20:36:28

by Colin Cross

[permalink] [raw]
Subject: [PATCH v2] 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.

Signed-off-by: Colin Cross <[email protected]>
---
drivers/leds/led-triggers.c | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 46b4c76..a85ce09 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -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);

--
1.7.7.3


2012-08-07 20:42:34

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2] leds: triggers: send uevent when changing triggers

On Tue, Aug 07, 2012 at 12:58:15PM -0700, Colin Cross wrote:
> 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

2012-08-07 20:47:26

by Colin Cross

[permalink] [raw]
Subject: Re: [PATCH v2] leds: triggers: send uevent when changing triggers

On Tue, Aug 7, 2012 at 1:42 PM, Greg KH <[email protected]> wrote:
> On Tue, Aug 07, 2012 at 12:58:15PM -0700, Colin Cross wrote:
>> 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.

2012-08-07 20:56:38

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2] leds: triggers: send uevent when changing triggers

On Tue, Aug 07, 2012 at 01:47:23PM -0700, Colin Cross wrote:
> On Tue, Aug 7, 2012 at 1:42 PM, Greg KH <[email protected]> wrote:
> > On Tue, Aug 07, 2012 at 12:58:15PM -0700, Colin Cross wrote:
> >> 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.

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

greg k-h

2012-08-07 20:57:45

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2] leds: triggers: send uevent when changing triggers

On Tue, Aug 07, 2012 at 12:58:15PM -0700, Colin Cross wrote:
> 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.
>
> Signed-off-by: Colin Cross <[email protected]>

Acked-by: Greg Kroah-Hartman <[email protected]>

Subject: Re: [PATCH v2] leds: triggers: send uevent when changing triggers

On Tue, 07 Aug 2012, Colin Cross wrote:
> 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.
>
> Signed-off-by: Colin Cross <[email protected]>

Acked-by: Henrique de Moraes Holschuh <[email protected]>

--
"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

2012-08-08 02:17:05

by Bryan Wu

[permalink] [raw]
Subject: Re: [PATCH v2] leds: triggers: send uevent when changing triggers

On Wed, Aug 8, 2012 at 9:12 AM, Henrique de Moraes Holschuh
<[email protected]> wrote:
> On Tue, 07 Aug 2012, Colin Cross wrote:
>> 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.
>>
>> Signed-off-by: Colin Cross <[email protected]>
>
> Acked-by: Henrique de Moraes Holschuh <[email protected]>
>

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

2012-08-14 11:35:22

by Bryan Wu

[permalink] [raw]
Subject: Re: [PATCH v2] leds: triggers: send uevent when changing triggers

On Wed, Aug 8, 2012 at 10:16 AM, Bryan Wu <[email protected]> wrote:
> On Wed, Aug 8, 2012 at 9:12 AM, Henrique de Moraes Holschuh
> <[email protected]> wrote:
>> On Tue, 07 Aug 2012, Colin Cross wrote:
>>> 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.
>>>
>>> Signed-off-by: Colin Cross <[email protected]>
>>
>> Acked-by: Henrique de Moraes Holschuh <[email protected]>
>>
>
> 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

2012-08-27 01:44:12

by Bryan Wu

[permalink] [raw]
Subject: Re: [PATCH v2] leds: triggers: send uevent when changing triggers

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

On Tue, Aug 14, 2012 at 7:34 PM, Bryan Wu <[email protected]> wrote:
> On Wed, Aug 8, 2012 at 10:16 AM, Bryan Wu <[email protected]> wrote:
>> On Wed, Aug 8, 2012 at 9:12 AM, Henrique de Moraes Holschuh
>> <[email protected]> wrote:
>>> On Tue, 07 Aug 2012, Colin Cross wrote:
>>>> 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.
>>>>
>>>> Signed-off-by: Colin Cross <[email protected]>
>>>
>>> Acked-by: Henrique de Moraes Holschuh <[email protected]>
>>>
>>
>> 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



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