Commit cd74e1dc authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] kthreads hold files open

keventd and friends are currently holding /dev/console open three times.
It's all inherited from init.

Steal the relevant parts of daemonize() to fix that up.
parent dac10907
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/unistd.h> #include <linux/unistd.h>
#include <linux/file.h>
#include <asm/semaphore.h> #include <asm/semaphore.h>
struct kthread_create_info struct kthread_create_info
...@@ -41,6 +42,21 @@ int kthread_should_stop(void) ...@@ -41,6 +42,21 @@ int kthread_should_stop(void)
return (kthread_stop_info.k == current); return (kthread_stop_info.k == current);
} }
static void kthread_exit_files(void)
{
struct fs_struct *fs;
struct task_struct *tsk = current;
exit_fs(tsk); /* current->fs->count--; */
fs = init_task.fs;
tsk->fs = fs;
atomic_inc(&fs->count);
exit_files(tsk);
current->files = init_task.files;
atomic_inc(&tsk->files->count);
}
static int kthread(void *_create) static int kthread(void *_create)
{ {
struct kthread_create_info *create = _create; struct kthread_create_info *create = _create;
...@@ -50,6 +66,8 @@ static int kthread(void *_create) ...@@ -50,6 +66,8 @@ static int kthread(void *_create)
int ret = -EINTR; int ret = -EINTR;
cpumask_t mask = CPU_MASK_ALL; cpumask_t mask = CPU_MASK_ALL;
kthread_exit_files();
/* Copy data: it's on keventd's stack */ /* Copy data: it's on keventd's stack */
threadfn = create->threadfn; threadfn = create->threadfn;
data = create->data; data = create->data;
......
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