Re: [patch 2/13] signal/timer/event fds v7 - signalfd core ...

From: Oleg Nesterov
Date: Mon Mar 19 2007 - 20:13:14 EST


On 03/19, Davide Libenzi wrote:
>
> +struct signalfd_lockctx {
> + struct task_struct *tsk;
> + struct sighand_struct *sighand;
> + unsigned long flags;
> +};

signalfd_lockctx is "private" to signalfd_lock/signalfd_unlock. But lk->sighand
is used only by signalfd_lock(). I'd suggest to remove it.

> +void signalfd_deliver(struct task_struct *tsk, int sig)
> +{
> + struct sighand_struct *sighand = tsk->sighand;
> + struct signalfd_ctx *ctx, *tmp;
> +
> + list_for_each_entry_safe(ctx, tmp, &sighand->sfdlist, lnk) {
> + /*
> + * We use a negative signal value as a way to broadcast that the
> + * sighand has been orphaned, so that we can notify all the
> + * listeners about this. Remeber the ctx->sigmask is inverted,
> + * so if the user is interested in a signal, that corresponding
> + * bit will be zero.
> + */
> + if (sig < 0) {
> + if (ctx->tsk == tsk) {
> + ctx->tsk = NULL;
> + list_del_init(&ctx->lnk);
> + wake_up(&ctx->wqh);
> + }
> + } else if (sig > 0) {
> + if (!sigismember(&ctx->sigmask, sig))
> + wake_up(&ctx->wqh);
> + }
> + }
> +}

I tried to avoid this comment, but can't help myself :)

This is a matter of taste, of course, but imho this is a classical "hide the
problem" example.

Why "else if (sig > 0)" ? sig can't be == 0. In my opinion, it is better to
add BUG_ON(!sig), but use just "else".

Oleg.

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