[patch] fs/proc/array.c FIXMEs fixed. (2.2.3)

Tigran Aivazian (tigran@aivazian.demon.co.uk)
Sat, 13 Mar 1999 23:33:55 +0000 (GMT)


This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.

---1463811583-2048220196-921368035=:416
Content-Type: TEXT/PLAIN; charset=US-ASCII

Hi guys,

I went through the fs/proc/array.c fixing all those FIXMEs related to the
use of tasklist_lock whereby it was unlocked sooner than it should have.

Most of it is straightfoward, except one place in read_maps() where the
comments "we might have fallen asleep" confused me a bit (perhaps because
I myself was half falling asleep). So I left alone the read_maps() for the
time being in hope that I will think over it while asleep and if there are
no race conditions I could do exactly the same thing there too.

Any ideas and comments will be appreciated.

Regards,
Tigran.

PS. Thanks for all the comments on my /proc/.config. Although I am
convinced (by Alan Cox) that my approach is not the best one, I will still
finish it off - just to avoid leaving something half-done.

diff -urN linux/fs/proc/array.c linux-2.2.3-proc_tasklock/fs/proc/array.c
--- linux/fs/proc/array.c Sat Mar 13 11:57:16 1999
+++ linux-2.2.3-proc_tasklock/fs/proc/array.c Sat Mar 13 23:14:27 1999
@@ -454,26 +454,31 @@
static int get_env(int pid, char * buffer)
{
struct task_struct *p;
+ int len = 0;

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->env_start, p->mm->env_end, buffer);
+ goto out;
+ len = get_array(p, p->mm->env_start, p->mm->env_end, buffer);
+out:
+ read_unlock(&tasklist_lock);
+ return len;
}

static int get_arg(int pid, char * buffer)
{
struct task_struct *p;
+ int len = 0;

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);
+ goto out;
+ len = get_array(p, p->mm->arg_start, p->mm->arg_end, buffer);
+out:
+ read_unlock(&tasklist_lock);
+ return len;
}

/*
@@ -825,14 +830,15 @@

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;
+ goto out;
buffer = task_name(tsk, buffer);
buffer = task_state(tsk, buffer);
buffer = task_mem(tsk, buffer);
buffer = task_sig(tsk, buffer);
buffer = task_cap(tsk, buffer);
+out:
+ read_unlock(&tasklist_lock);
return buffer - orig;
}

@@ -841,15 +847,14 @@
struct task_struct *tsk;
unsigned long vsize, eip, esp, wchan;
long priority, nice;
- int tty_pgrp;
+ int tty_pgrp, len = 0;
sigset_t sigign, sigcatch;
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;
+ goto out;
state = *get_task_state(tsk);
vsize = eip = esp = 0;
if (tsk->mm && tsk->mm != &init_mm) {
@@ -878,7 +883,7 @@
nice = tsk->priority;
nice = 20 - (nice * 20 + DEF_PRIORITY / 2) / DEF_PRIORITY;

- return sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
+ len = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
%lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu %lu %lu \
%lu %lu %lu %lu %lu %lu %lu %lu %d\n",
pid,
@@ -923,6 +928,9 @@
tsk->nswap,
tsk->cnswap,
tsk->exit_signal);
+out:
+ read_unlock(&tasklist_lock);
+ return len;
}

static inline void statm_pte_range(pmd_t * pmd, unsigned long address, unsigned long size,
@@ -1001,13 +1009,12 @@
static int get_statm(int pid, char * buffer)
{
struct task_struct *tsk;
- int size=0, resident=0, share=0, trs=0, lrs=0, drs=0, dt=0;
+ int len=0, 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;
+ goto out;
if (tsk->mm && tsk->mm != &init_mm) {
struct vm_area_struct * vma = tsk->mm->mmap;

@@ -1031,8 +1038,11 @@
vma = vma->vm_next;
}
}
- return sprintf(buffer,"%d %d %d %d %d %d %d\n",
+ len = sprintf(buffer,"%d %d %d %d %d %d %d\n",
size, resident, share, trs, lrs, drs, dt);
+out:
+ read_unlock(&tasklist_lock);
+ return len;
}

/*
@@ -1200,15 +1210,13 @@
static int get_pidcpu(int pid, char * buffer)
{
struct task_struct * tsk = current ;
- int i, len;
+ int i, len = 0;

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;
+ goto out;

len = sprintf(buffer,
"cpu %lu %lu\n",
@@ -1220,7 +1228,8 @@
i,
tsk->per_cpu_utime[cpu_logical_map(i)],
tsk->per_cpu_stime[cpu_logical_map(i)]);
-
+out:
+ read_unlock(&tasklist_lock);
return len;
}
#endif

---1463811583-2048220196-921368035=:416
Content-Type: APPLICATION/x-gunzip; name="tasklock1.patch.gz"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.3.96.990313233355.416B@perseo.homenet>
Content-Description: fixes for fs/proc/array.c

H4sICDL06jYCA3Rhc2tsb2NrMS5wYXRjaADVV21v2zYQ/iz/ikuGBrJFxZbs
NHaCBPmwFgjQdkPXARvWQWAk2iEiUQJJpcnW/vfdUbJnO86bV6BrYInvd6d7
njteMjmdQljrd5BLVd/0p6Zf6TLtc6357X7azIbxfrw/DGkhsdxc5WV6tb6z
E4bhZhneL9zCW64hGkIUHR0cHkUvIZpMJp0gCJ6uYFlMPDyKRkfxYSPm7AzC
0cGIxS8hoHYYwdlZB4zlVqYglYWZsIlQ1z71K5kxSC9RUA8u6ulU6G4H/u6A
Z6yuUwukP2n7veq4E3h0KhcKTmBwjPvwpwXPEj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s2DfKayYRMbyPhddC7M87BjQgNMPKALDtsxkrXlqHQnmjxbCZ3g
0aS2shB/UC8vZzLleYJc92X3zw17zX17yU/PLLsWZPoBa2457fwDnuyZU60P
AAA=
---1463811583-2048220196-921368035=:416--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/