public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Exclude kernel threads from kill(-1, ..)
@ 2006-04-22  0:31 Chris Spiegel
  0 siblings, 0 replies; only message in thread
From: Chris Spiegel @ 2006-04-22  0:31 UTC (permalink / raw)
  To: linux-kernel

kill(-1, ..) currently will try to signal kernel threads, which of
course won't die off even with SIGKILL, meaning that ESRCH will never be
returned.  Instead, allow kill() to return ESRCH if the only processes
left are simply unkillable (kernel threads).  This does not violate
POSIX which says that "an unspecified set of system processes" may be
excluded when killing -1.

Signed-off-by: Chris Spiegel <linuxml@happyjack.org>

---
(please CC replies to me)

There is a comment in signal.c which says that Linux's kill(-1, ..) does
something that is probably wrong and should be like BSD or SysV.  Well,
this is a bit more like the modern BSDs (possibly SysV, I'm not familiar
with it), although we still don't kill the calling process, a choice I
agree with.

This isn't just a pathological fix, it's a problem I ran into with the
following code (from NetBSD's /sbin/reboot):

for (i = 1;; ++i) {
	if (kill(-1, SIGKILL) == -1) {
		if (errno == ESRCH)
			break;
		goto restart;
	}
	if (i > 5) {
		warnx("WARNING: some process(es) wouldn't die");
		break;
	}
	(void)sleep(2 * i);
}

So it fixes a real-world (my world, anyway) problem.

--- linux-2.6/kernel/signal.c.orig	2006-04-21 15:44:17.618784128 -0700
+++ linux-2.6/kernel/signal.c	2006-04-21 16:20:52.269454557 -0700
@@ -1156,7 +1156,8 @@ static int kill_something_info(int sig, 
 
 		read_lock(&tasklist_lock);
 		for_each_process(p) {
-			if (p->pid > 1 && p->tgid != current->tgid) {
+			if (p->pid > 1 && p->tgid != current->tgid &&
+					  p->mm != NULL) {
 				int err = group_send_sig_info(sig, info, p);
 				++count;
 				if (err != -EPERM)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-04-22  0:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-22  0:31 [PATCH] Exclude kernel threads from kill(-1, ..) Chris Spiegel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox