Re: [PATCH 2.6.7] kill(2), killpg(2) wrongly fail with EPERM

From: Linus Torvalds
Date: Wed Jun 16 2004 - 11:17:15 EST




On Wed, 16 Jun 2004, Michael Kerrisk wrote:
>
> The following patch for 2.6.7 fixes the problem. Please apply.

How about this imho nicer version instead? It results in the main loop
being just:

success = 0;
retval = -ESRCH;
for_each_task_pid(pgrp, PIDTYPE_PGID, p, l, pid) {
int err = group_send_sig_info(sig, info, p);
success |= !err;
retval = err;
}
return success ? 0 : retval;

which seems sensible. If _any_ group-send succeeded, we want to return
success (ie this is not a EPERM vs everything else issue).

Does this work for you?

Linus

-----
===== kernel/signal.c 1.120 vs edited =====
--- 1.120/kernel/signal.c Wed Jun 9 01:46:51 2004
+++ edited/kernel/signal.c Wed Jun 16 09:09:51 2004
@@ -1071,23 +1071,19 @@
struct task_struct *p;
struct list_head *l;
struct pid *pid;
- int retval;
- int found;
+ int retval, success;

if (pgrp <= 0)
return -EINVAL;

- found = 0;
- retval = 0;
+ success = 0;
+ retval = -ESRCH;
for_each_task_pid(pgrp, PIDTYPE_PGID, p, l, pid) {
- int err;
-
- found = 1;
- err = group_send_sig_info(sig, info, p);
- if (!retval)
- retval = err;
+ int err = group_send_sig_info(sig, info, p);
+ success |= !err;
+ retval = err;
}
- return found ? retval : -ESRCH;
+ return success ? 0 : retval;
}

int
-
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/