input: Introduces activity counters revealing user interactivity
PATCH 1/1 input: Introduces activity counters revealing user interactivity
Hello,
the attached patch* introduces activity counters into input device drivers so that a proper user-space daemon leveraging these counters can implement event notification facilities (e.g. screen savers, intrusion detection, etc.) At this purpose, a second patch has been also attached: it provides a working Perl daemon simulating the activity of a screen saver.
I had submitted something similar a couple of years ago, by way of a kernel module named SIN (http://lkml.org/lkml/2007/1/18/138)
Despite SIN has been properly maintained in this period, it revealed soon some design weaknesses which urged me towards alternative approaches. So here I am once more. The submitted patch is quite straightforward yet provides good features, such as:
1) daemons retain the whole control logic
2) daemons are EVIOCGRAB hassle free
3) daemons do not get biased towards a specific environment (e.g. one monitor, one keyboard...)
That's it.
Cheers,
Alessandro
* 2.6.28.1 friendly
==============================================================================
drivers/input/input.c +49 -0
@@ -72,6 +72,12 @@ static void input_pass_event(struct inpu unsigned int type, unsigned int code, int value) { struct input_handle *handle; + + dev->activity =ktime_get (); + +if (dev->activity_notifier) { +sysfs_notify_dirent (dev->activity_notifier); + }rcu_read_lock ();
@@ -1012,11 +1018,25 @@ static ssize_t input_dev_show_modalias(s } static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL); +static ssize_t input_dev_show_activity (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct input_dev *id =to_input_dev (dev); + +return scnprintf (buf,PAGE_SIZE ,"A: %Ld\nD: %Ld\n" , +ktime_to_ns (id->activity), +ktime_to_us (ktime_sub (ktime_get (), id->activity))); +} + +static DEVICE_ATTR(activity, S_IRUGO, input_dev_show_activity, NULL); +static struct attribute *input_dev_attrs[] = { &dev_attr_name.attr, &dev_attr_phys.attr, &dev_attr_uniq.attr, &dev_attr_modalias.attr, + &dev_attr_activity.attr,NULL };
@@ -1227,10 +1247,34 @@ static int input_dev_uevent(struct devicreturn 0 ; } +static inline int warp_activity (struct device *dev) +{ +struct input_dev *id =to_input_dev (dev); + + id->activity =ktime_sub (ktime_get (), id->activity); +return 0 ; +} + +int input_dev_suspend (struct device *dev,pm_message_t state) +{ +if (state.event & (PM_EVENT_FREEZE |PM_EVENT_SUSPEND )) { + (void )warp_activity (dev); + } + +return 0 ; +} + +int input_dev_resume (struct device *dev) +{ +return warp_activity (dev); +} +static struct device_type input_dev_type = { .groups = input_dev_attr_groups, .release = input_dev_release, .uevent = input_dev_uevent, + .suspend = input_dev_suspend, + .resume = input_dev_resume, };struct class input_class = {
@@ -1401,6 +1445,8 @@ int input_register_device(struct input_d dev->name ? dev->name : "Unspecified device", path ? path : "N/A");kfree (path); + dev->activity_notifier =sysfs_get_dirent (dev->dev.kobj.sd,"activity" ); + error =mutex_lock_interruptible (&input_mutex);if (error) {device_del (&dev->dev);
@@ -1446,6 +1492,9 @@ void input_unregister_device(struct inpumutex_unlock (&input_mutex); +sysfs_put (dev->activity_notifier); + dev->activity_notifier =NULL ; +device_unregister (&dev->dev); }EXPORT_SYMBOL (input_unregister_device);
include/linux/input.h +3 -0
@@ -1094,6 +1094,9 @@ struct input_dev {struct input_handle *grab; +struct sysfs_dirent *activity_notifier; +ktime_t activity; +spinlock_t event_lock;struct mutex mutex;
==============================================================================
SIN.pl +259 -0
259 lines not on this page · raw message
Signature · 1 line
He who strikes terror into others is himself in continual fear. - Claudian