Re: NPTL: Parent thread receives SIGHUP when child thread terminates?

From: Roland McGrath
Date: Fri Oct 22 2004 - 06:05:27 EST


> When process is session leader, is it supposed to receive SIGHUP when child
> thread terminates?

Nope, this is certainly wrong.

> Probably disassociate_ctty(1) in do_exit() should not be invoked for all
> tsk->signal->leader, but only for those with thread_group_empty() == 1, i.e.
> when this process is really going away ? Or only for thread group leader?

Indeed, but that particular kind of test is subject to race conditions. I
think the easiest way to fix this is to use the bookkeeping I added to get
process accounting correct (another thing that has to happen on the last
thread's death). Start with this patch:

http://www.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.9/2.6.9-mm1/broken-out/acct-report-single-record-for-multithreaded-process.patch


Then throw this one on top.


Thanks,
Roland


---

The session leader should disassociate from its controlling terminal and
send SIGHUP signals only when the whole session leader process dies.
Currently, this gets done when any thread in that process dies, which is
wrong. This patch fixes it.


Signed-off-by: Roland McGrath <roland@xxxxxxxxxx>

--- linux-2.6/kernel/exit.c.acct
+++ linux-2.6/kernel/exit.c
@@ -783,6 +783,7 @@ static void exit_notify(struct task_stru
asmlinkage NORET_TYPE void do_exit(long code)
{
struct task_struct *tsk = current;
+ int group_dead;

profile_task_exit(tsk);

@@ -807,7 +808,8 @@ asmlinkage NORET_TYPE void do_exit(long
ptrace_notify((PTRACE_EVENT_EXIT << 8) | SIGTRAP);
}

- if (atomic_dec_and_test(&tsk->signal->live))
+ group_dead = atomic_dec_and_test(&tsk->signal->live);
+ if (group_dead)
acct_process(code);
__exit_mm(tsk);

@@ -818,7 +820,7 @@ asmlinkage NORET_TYPE void do_exit(long
exit_thread();
exit_keys(tsk);

- if (tsk->signal->leader)
+ if (group_dead && tsk->signal->leader)
disassociate_ctty(1);

module_put(tsk->thread_info->exec_domain->module);
-
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/