patch-2.1.90 linux/fs/proc/array.c

Next file: linux/fs/proc/base.c
Previous file: linux/fs/open.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.89/linux/fs/proc/array.c linux/fs/proc/array.c
@@ -446,7 +446,11 @@
 
 static int get_env(int pid, char * buffer)
 {
-	struct task_struct *p = find_task_by_pid(pid);
+	struct task_struct *p;
+	
+	read_lock(&tasklist_lock);
+	p = find_task_by_pid(pid);
+	read_unlock(&tasklist_lock);	/* FIXME!! This should be done after the last use */
 
 	if (!p || !p->mm)
 		return 0;
@@ -455,8 +459,11 @@
 
 static int get_arg(int pid, char * buffer)
 {
-	struct task_struct *p = find_task_by_pid(pid);
+	struct task_struct *p;
 
+	read_lock(&tasklist_lock);
+	p = find_task_by_pid(pid);
+	read_unlock(&tasklist_lock);	/* FIXME!! This should be done after the last use */
 	if (!p || !p->mm)
 		return 0;
 	return get_array(p, p->mm->arg_start, p->mm->arg_end, buffer);
@@ -760,8 +767,11 @@
 static int get_status(int pid, char * buffer)
 {
 	char * orig = buffer;
-	struct task_struct *tsk = find_task_by_pid(pid);
+	struct task_struct *tsk;
 
+	read_lock(&tasklist_lock);
+	tsk = find_task_by_pid(pid);
+	read_unlock(&tasklist_lock);	/* FIXME!! This should be done after the last use */
 	if (!tsk)
 		return 0;
 	buffer = task_name(tsk, buffer);
@@ -773,7 +783,7 @@
 
 static int get_stat(int pid, char * buffer)
 {
-	struct task_struct *tsk = find_task_by_pid(pid);
+	struct task_struct *tsk;
 	unsigned long vsize, eip, esp, wchan;
 	long priority, nice;
 	int tty_pgrp;
@@ -784,6 +794,9 @@
 	char sigcatch_str[sizeof(sigset_t)*2+1];
 	char state;
 
+	read_lock(&tasklist_lock);
+	tsk = find_task_by_pid(pid);
+	read_unlock(&tasklist_lock);	/* FIXME!! This should be done after the last use */
 	if (!tsk)
 		return 0;
 	state = *get_task_state(tsk);
@@ -938,6 +951,9 @@
 	struct task_struct *tsk = find_task_by_pid(pid);
 	int size=0, resident=0, share=0, trs=0, lrs=0, drs=0, dt=0;
 
+	read_lock(&tasklist_lock);
+	tsk = find_task_by_pid(pid);
+	read_unlock(&tasklist_lock);	/* FIXME!! This should be done after the last use */
 	if (!tsk)
 		return 0;
 	if (tsk->mm && tsk->mm != &init_mm) {
@@ -1020,7 +1036,9 @@
 		goto out;
 
 	retval = -EINVAL;
+	read_lock(&tasklist_lock);
 	p = find_task_by_pid(pid);
+	read_unlock(&tasklist_lock);	/* FIXME!! This should be done after the last use */
 	if (!p)
 		goto freepage_out;
 
@@ -1131,9 +1149,11 @@
 {
 	struct task_struct * tsk = current ;
 	int i, len;
-	
+
+	read_lock(&tasklist_lock);
 	if (pid != tsk->pid)
 		tsk = find_task_by_pid(pid);
+	read_unlock(&tasklist_lock);	/* FIXME!! This should be done after the last use */
 
 	if (tsk == NULL)
 		return 0;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov