Skip to contentSkip to conversation

signals: introduce SIGQUEUE_CANCELLED

PATCH In review Oleg Nesterov 2 participants 2 messages May 17, 2008 – May 21, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 signals: introduce SIGQUEUE_CANCELLED

Suggested by Linus Torvalds.

Introduce SIGQUEUE_CANCELLED flag. If it is set, the pending signal should be ignored and collect_signal() should return 0.

Note that the new flag is completely orthogonal to SIGQUEUE_PREALLOC, and it can be set without ->siglock held.

No users of this new flag yet, see the next patch.

include/linux/signal.h renamed from include/linux/signal.h~5_INTRODUCE_CANCELLED +1 -0
@@ -20,6 +20,7 @@ struct sigqueue {
 
 /* flags values. */
 #define SIGQUEUE_PREALLOC	1
+#define SIGQUEUE_CANCELLED	2
 
 struct sigpending {
 	struct list_head list;
kernel/signal.c renamed from kernel/signal.c~5_INTRODUCE_CANCELLED +7 -6
@@ -326,11 +326,13 @@ static int collect_signal(int sig, struc
 		}
 	}
 	if (first) {
-		list_del_init(&first->list);
-		copy_siginfo(info, &first->info);
-		__sigqueue_free(first);
 		if (!still_pending)
 			sigdelset(&list->signal, sig);
+		if (unlikely(first->flags & SIGQUEUE_CANCELLED))
+			sig = 0;
+		copy_siginfo(info, &first->info);
+		list_del_init(&first->list);
+		__sigqueue_free(first);
 	} else {
 
 		/* Ok, it wasn't in the queue.  This must be
@@ -344,7 +346,7 @@ static int collect_signal(int sig, struc
 		info->si_pid = 0;
 		info->si_uid = 0;
 	}
-	return 1;
+	return sig;
 }
 
 static int __dequeue_signal(struct sigpending *pending, sigset_t *mask,
@@ -362,8 +364,7 @@ static int __dequeue_signal(struct sigpe
 			}
 		}
 
-		if (!collect_signal(sig, pending, info))
-			sig = 0;
+		sig = collect_signal(sig, pending, info);
 	}
 
 	return sig;
Acked-by on v1 2/3
#1 lore raw
Quoted 2 lines

Introduce SIGQUEUE_CANCELLED flag. If it is set, the pending signal should be ignored and collect_signal() should return 0.

Quoted 2 lines

Note that the new flag is completely orthogonal to SIGQUEUE_PREALLOC, and it can be set without ->siglock held.

I think to keep things easier to understand, we should say the rule is that touching q->flags is always controlled by siglock when q is on a queue. Before it's queued or after it's been dequeued (i.e. list_empty(&q->list) with siglock held), then the "owner" of the struct sigqueue of course needs noone's siglock.

Thanks,
Roland