Skip to contentSkip to conversation

signal/timer/event fds v7 - signalfd core ...

PATCH Oleg Nesterov 2 participants 4 messages Mar 20, 2007 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Review

Quoted 6 lines · Davide Libenzi
(quoted diff) +5 -0
+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.

Quoted 15 lines
(quoted diff) +15 -0
+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) {

Review

Quoted 10 lines
(quoted diff) +10 -0
+				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.

#2 lore raw
Quoted 10 lines · Oleg Nesterov

Review

Quoted 6 lines · Davide Libenzi
(quoted diff) +5 -0
+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.

Ack

Quoted 19 lines
Quoted 19 lines
(quoted diff) +19 -0
+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);
+			}
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+		} else if (sig > 0) {
+			if (!sigismember(&ctx->sigmask, sig))
+				wake_up(&ctx->wqh);
+		}
+	}
+}

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

Added BUG_ON() and using "else".

- Davide

#3 lore raw
In reply to a message not in the archive

Review

Quoted 6 lines · Davide Libenzi
(quoted diff) +5 -0
+static void signalfd_unlock(struct signalfd_ctx *ctx,
+			    struct signalfd_lockctx *lk)
+{
+	unlock_task_sighand(lk->tsk, &lk->flags);
+}

Again, this is a matter of taste. But I can't understand why signalfd_unlock() needs "signalfd_ctx *ctx" parameter. If we have "struct signalfd_lockctx *lk", signalfd_lock() can setup lk->ctx if it is ever needed.

Oleg.

#4 lore raw
Quoted 11 lines · Oleg Nesterov

Review

Quoted 6 lines · Davide Libenzi
(quoted diff) +5 -0
+static void signalfd_unlock(struct signalfd_ctx *ctx,
+			    struct signalfd_lockctx *lk)
+{
+	unlock_task_sighand(lk->tsk, &lk->flags);
+}

Again, this is a matter of taste. But I can't understand why signalfd_unlock() needs "signalfd_ctx *ctx" parameter. If we have "struct signalfd_lockctx *lk", signalfd_lock() can setup lk->ctx if it is ever needed.

With the new API, I agree. Removed.

- Davide