Re: Python or Perl for a Debian maintainance project?
On Thu, Feb 19, 2004 at 10:42:56AM +0800, Isaac To wrote:
> ...
> Perhaps you want to enlighten the kernel developers. A typical kernel
> function, say sys_getpgid, is implemented (in 2.4.24 kernel) like this:
>
> asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
> {
> ....
>
> /* From this point forward we keep holding onto the tasklist lock
> * so that our parent does not change from under us. -DaveM
> */
> read_lock(&tasklist_lock);
>
> err = -ESRCH;
> p = find_task_by_pid(pid);
> if (!p)
> goto out;
>
> if (p->p_pptr == current || p->p_opptr == current) {
> err = -EPERM;
> if (p->session != current->session)
> goto out;
>...
> out:
> /* All paths lead to here, thus we are safe. -DaveM */
> read_unlock(&tasklist_lock);
> return err;
> }
An alternative method in C, if you dont want to write a new function,
is to fake one in-line, using a one-shot while loop.
No goto required. Just an indent level.
Which has a nice side effect of very clearly demarking,
"Hey, something special is going on here"
(ie: I'm HOLDING A LOCK)
asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
{
int err=0;
....
read_lock(&tasklist_lock);
do {
p = find_task_by_pid(pid);
if (!p){
err=-ESRCH;
break;
}
if (p->session != current->session){
err = -EPERM;
break;
}
... /* do stuff... */
} while (0); /* allow for early termination */
read_unlock(&tasklist_lock);
return err;
}
Reply to: