Re: [1/2][PATCH] nproc: netlink access to /proc information

Roger Luethi
2004-08-27T13:41:36Z

I failed to mention that the patch is missing some rather basic locking
(say, in nproc_select_pid). Yeah, it is _that_ experimental :-/. I ignored
the locking issue when mulling over the semantics of the new interface and
forgot it later.

The patch below should be an improvement.

Roger

--- kernel/nproc.c.01 2004-08-27 15:38:36.686602557 +0200
+++ kernel/nproc.c 2004-08-27 15:38:36.686602557 +0200
@@ -278,18 +278,23 @@ int nproc_select_pid(struct nlmsghdr *nl

for (i = 0; i < tcnt; i++) {
task_t *tsk;
+ read_lock(&tasklist_lock);
tsk = find_task_by_pid(pids[i]);
+ if (tsk)
+ get_task_struct(tsk);
+ read_unlock(&tasklist_lock);
+ if (!tsk)
+ goto err_srch;
pdebug("task found for pid %d: %s.\n", pids[i], tsk->comm);
- if (!tsk) {
- err = -ESRCH;
- goto out;
- }
err = nproc_pid_fields(nlh, fdata, len, tsk);
+ put_task_struct(tsk);
}

-out:
return err;

+err_srch:
+ return -ESRCH;
+
err_inval:
return -EINVAL;
}