LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Alan Cox <alan@redhat.com>,
	Davide Libenzi <davidel@xmailserver.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Ingo Molnar <mingo@elte.hu>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Roland McGrath <roland@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] will_become_orphaned_pgrp: partially fix insufficient ->exit_state check
Date: Sun, 2 Mar 2008 21:44:42 +0300	[thread overview]
Message-ID: <20080302184442.GA16368@tv-sign.ru> (raw)

p->exit_state != 0 doesn't mean this process is dead, it may have sub-threads.
Change the code to use "p->exit_state && thread_group_empty(p)" instead.

Without this patch, ^Z doesn't deliver SIGTSTP to the foreground process if
the main thread has exited.

However, the new check is not perfect too. There is a window when exit_notify()
drops tasklist and before release_task(). Suppose that the last (non-leader)
thread exits. This means that entire group exits, but thread_group_empty() is
not true yet.

As Eric pointed out, is_global_init() is wrong as well, but I did not dare to
do other changes.

Just for the record, has_stopped_jobs() is absolutely wrong too. But we can't
fix it now, we should first fix SIGNAL_STOP_STOPPED issues.

And. Even with this patch ^Z doesn't play well with the dead main thread. The
task is stopped correctly but do_wait(WSTOPPED) can't see it. This is another
unrelated issue, will be (hopefully) fixed separately.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- 25/kernel/exit.c~2_WBOP	2008-03-02 19:18:58.000000000 +0300
+++ 25/kernel/exit.c	2008-03-02 19:42:56.000000000 +0300
@@ -214,20 +214,19 @@ struct pid *session_of_pgrp(struct pid *
 static int will_become_orphaned_pgrp(struct pid *pgrp, struct task_struct *ignored_task)
 {
 	struct task_struct *p;
-	int ret = 1;
 
 	do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
-		if (p == ignored_task
-				|| p->exit_state
-				|| is_global_init(p->real_parent))
+		if ((p == ignored_task) ||
+		    (p->exit_state && thread_group_empty(p)) ||
+		    is_global_init(p->real_parent))
 			continue;
+
 		if (task_pgrp(p->real_parent) != pgrp &&
-		    task_session(p->real_parent) == task_session(p)) {
-			ret = 0;
-			break;
-		}
+		    task_session(p->real_parent) == task_session(p))
+			return 0;
 	} while_each_pid_task(pgrp, PIDTYPE_PGID, p);
-	return ret;	/* (sighing) "Often!" */
+
+	return 1;
 }
 
 int is_current_pgrp_orphaned(void)


                 reply	other threads:[~2008-03-02 18:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20080302184442.GA16368@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=akpm@linux-foundation.org \
    --cc=alan@redhat.com \
    --cc=davidel@xmailserver.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=roland@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --subject='Re: [PATCH 2/3] will_become_orphaned_pgrp: partially fix insufficient ->exit_state check' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).