mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roland McGrath <roland@redhat.com>
To: Petr Vandrovec <vandrove@vc.cvut.cz>
Cc: linux-kernel@vger.kernel.org
Subject: Re: NPTL: Parent thread receives SIGHUP when child thread terminates?
Date: Fri, 22 Oct 2004 04:01:54 -0700	[thread overview]
Message-ID: <200410221101.i9MB1sMi029552@magilla.sf.frob.com> (raw)
In-Reply-To: Petr Vandrovec's message of  Thursday, 21 October 2004 12:13:13 +0200 <20041021101313.GA19246@vana.vc.cvut.cz>

>   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@redhat.com>

--- 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);

      parent reply	other threads:[~2004-10-22 11:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-21 10:13 Petr Vandrovec
2004-10-21 23:10 ` Ulrich Drepper
2004-10-22 11:01 ` Roland McGrath [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200410221101.i9MB1sMi029552@magilla.sf.frob.com \
    --to=roland@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vandrove@vc.cvut.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®