Commit 3f9f17d4 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: switch gameport core to using kthread API instead of

       using daemonize() and signals. This way kgameportd will
       never be accidentially killed.
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent a9180ab2
...@@ -17,11 +17,10 @@ ...@@ -17,11 +17,10 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/gameport.h> #include <linux/gameport.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/completion.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/smp_lock.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/kthread.h>
/*#include <asm/io.h>*/ /*#include <asm/io.h>*/
...@@ -238,8 +237,7 @@ struct gameport_event { ...@@ -238,8 +237,7 @@ struct gameport_event {
static DEFINE_SPINLOCK(gameport_event_lock); /* protects gameport_event_list */ static DEFINE_SPINLOCK(gameport_event_lock); /* protects gameport_event_list */
static LIST_HEAD(gameport_event_list); static LIST_HEAD(gameport_event_list);
static DECLARE_WAIT_QUEUE_HEAD(gameport_wait); static DECLARE_WAIT_QUEUE_HEAD(gameport_wait);
static DECLARE_COMPLETION(gameport_exited); static struct task_struct *gameport_task;
static int gameport_pid;
static void gameport_queue_event(void *object, struct module *owner, static void gameport_queue_event(void *object, struct module *owner,
enum gameport_event_type event_type) enum gameport_event_type event_type)
...@@ -250,12 +248,12 @@ static void gameport_queue_event(void *object, struct module *owner, ...@@ -250,12 +248,12 @@ static void gameport_queue_event(void *object, struct module *owner,
spin_lock_irqsave(&gameport_event_lock, flags); spin_lock_irqsave(&gameport_event_lock, flags);
/* /*
* Scan event list for the other events for the same gameport port, * Scan event list for the other events for the same gameport port,
* starting with the most recent one. If event is the same we * starting with the most recent one. If event is the same we
* do not need add new one. If event is of different type we * do not need add new one. If event is of different type we
* need to add this event and should not look further because * need to add this event and should not look further because
* we need to preseve sequence of distinct events. * we need to preseve sequence of distinct events.
*/ */
list_for_each_entry_reverse(event, &gameport_event_list, node) { list_for_each_entry_reverse(event, &gameport_event_list, node) {
if (event->object == object) { if (event->object == object) {
if (event->type == event_type) if (event->type == event_type)
...@@ -432,20 +430,15 @@ static struct gameport *gameport_get_pending_child(struct gameport *parent) ...@@ -432,20 +430,15 @@ static struct gameport *gameport_get_pending_child(struct gameport *parent)
static int gameport_thread(void *nothing) static int gameport_thread(void *nothing)
{ {
lock_kernel();
daemonize("kgameportd");
allow_signal(SIGTERM);
do { do {
gameport_handle_events(); gameport_handle_events();
wait_event_interruptible(gameport_wait, !list_empty(&gameport_event_list)); wait_event_interruptible(gameport_wait,
kthread_should_stop() || !list_empty(&gameport_event_list));
try_to_freeze(PF_FREEZE); try_to_freeze(PF_FREEZE);
} while (!signal_pending(current)); } while (!kthread_should_stop());
printk(KERN_DEBUG "gameport: kgameportd exiting\n"); printk(KERN_DEBUG "gameport: kgameportd exiting\n");
return 0;
unlock_kernel();
complete_and_exit(&gameport_exited, 0);
} }
...@@ -773,9 +766,10 @@ void gameport_close(struct gameport *gameport) ...@@ -773,9 +766,10 @@ void gameport_close(struct gameport *gameport)
static int __init gameport_init(void) static int __init gameport_init(void)
{ {
if (!(gameport_pid = kernel_thread(gameport_thread, NULL, CLONE_KERNEL))) { gameport_task = kthread_run(gameport_thread, NULL, "kgameportd");
if (IS_ERR(gameport_task)) {
printk(KERN_ERR "gameport: Failed to start kgameportd\n"); printk(KERN_ERR "gameport: Failed to start kgameportd\n");
return -1; return PTR_ERR(gameport_task);
} }
gameport_bus.dev_attrs = gameport_device_attrs; gameport_bus.dev_attrs = gameport_device_attrs;
...@@ -789,8 +783,7 @@ static int __init gameport_init(void) ...@@ -789,8 +783,7 @@ static int __init gameport_init(void)
static void __exit gameport_exit(void) static void __exit gameport_exit(void)
{ {
bus_unregister(&gameport_bus); bus_unregister(&gameport_bus);
kill_proc(gameport_pid, SIGTERM, 1); kthread_stop(gameport_task);
wait_for_completion(&gameport_exited);
} }
module_init(gameport_init); module_init(gameport_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment