All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Christoph Hellwig <hch@infradead.org>,
	Andrew Morton <akpm@osdl.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] pids: simplify do_each_task_pid/while_each_task_pid
Date: Thu, 13 Apr 2006 16:07:22 +0100	[thread overview]
Message-ID: <20060413150722.GA5217@infradead.org> (raw)
In-Reply-To: <20060413175431.GA108@oleg>

On Thu, Apr 13, 2006 at 09:54:31PM +0400, Oleg Nesterov wrote:
> > 
> > #define for_each_task_pid(task, pid, type, pos) \
> > 	hlist_for_each_entry_rcu((task), (pos),  \
> > 		(&(pid))->tasks[type], pids[type].node) {
> > 
> > and move the find_pid to the caller?  That would make the code a whole lot
> > more readable.
> 
> Then the caller should check find_pid() doesn't return NULL. But yes,
> we can hide this check inside for_each_task_pid().
> 
> But what about current users of do_each_task_pid ? We can't just remove
> these macros.

They'd have to switch over to the new variant.  There's just 18 callers
ayway, currently, and with a patch like the one below that number firther
decreases :)


Index: linux-2.6/drivers/char/tty_io.c
===================================================================
--- linux-2.6.orig/drivers/char/tty_io.c	2006-04-13 16:22:12.000000000 +0200
+++ linux-2.6/drivers/char/tty_io.c	2006-04-13 16:39:57.000000000 +0200
@@ -1174,6 +1174,17 @@
 
 EXPORT_SYMBOL(tty_hung_up_p);
 
+static void clear_session_ttys(pid_t session)
+{
+	struct task_struct *p;
+
+	read_lock(&tasklist_lock);
+	do_each_task_pid(session, PIDTYPE_SID, p) {
+		p->signal->tty = NULL;
+	} while_each_task_pid(session, PIDTYPE_SID, p);
+	read_unlock(&tasklist_lock);
+}
+
 /*
  * This function is typically called only by the session leader, when
  * it wants to disassociate itself from its controlling tty.
@@ -1190,7 +1201,6 @@
 void disassociate_ctty(int on_exit)
 {
 	struct tty_struct *tty;
-	struct task_struct *p;
 	int tty_pgrp = -1;
 
 	lock_kernel();
@@ -1224,11 +1234,7 @@
 	tty->pgrp = -1;
 
 	/* Now clear signal->tty under the lock */
-	read_lock(&tasklist_lock);
-	do_each_task_pid(current->signal->session, PIDTYPE_SID, p) {
-		p->signal->tty = NULL;
-	} while_each_task_pid(current->signal->session, PIDTYPE_SID, p);
-	read_unlock(&tasklist_lock);
+	clear_session_ttys(current->signal->session);
 	mutex_unlock(&tty_mutex);
 	unlock_kernel();
 }
@@ -1927,17 +1933,9 @@
 	 * tty.
 	 */
 	if (tty_closing || o_tty_closing) {
-		struct task_struct *p;
-
-		read_lock(&tasklist_lock);
-		do_each_task_pid(tty->session, PIDTYPE_SID, p) {
-			p->signal->tty = NULL;
-		} while_each_task_pid(tty->session, PIDTYPE_SID, p);
+		clear_session_ttys(tty->session);
 		if (o_tty)
-			do_each_task_pid(o_tty->session, PIDTYPE_SID, p) {
-				p->signal->tty = NULL;
-			} while_each_task_pid(o_tty->session, PIDTYPE_SID, p);
-		read_unlock(&tasklist_lock);
+			clear_session_ttys(o_tty->session);
 	}
 
 	mutex_unlock(&tty_mutex);
@@ -2348,8 +2346,6 @@
 
 static int tiocsctty(struct tty_struct *tty, int arg)
 {
-	task_t *p;
-
 	if (current->signal->leader &&
 	    (current->signal->session == tty->session))
 		return 0;
@@ -2364,18 +2360,12 @@
 		 * This tty is already the controlling
 		 * tty for another session group!
 		 */
-		if ((arg == 1) && capable(CAP_SYS_ADMIN)) {
-			/*
-			 * Steal it away
-			 */
-
-			read_lock(&tasklist_lock);
-			do_each_task_pid(tty->session, PIDTYPE_SID, p) {
-				p->signal->tty = NULL;
-			} while_each_task_pid(tty->session, PIDTYPE_SID, p);
-			read_unlock(&tasklist_lock);
-		} else
+		if (arg != 1 || !capable(CAP_SYS_ADMIN))
 			return -EPERM;
+		/*
+		 * Steal it away
+		 */
+		clear_session_ttys(tty->session);
 	}
 	task_lock(current);
 	current->signal->tty = tty;


  parent reply	other threads:[~2006-04-13 15:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-13 16:37 [PATCH] pids: simplify do_each_task_pid/while_each_task_pid Oleg Nesterov
2006-04-13 13:38 ` Christoph Hellwig
2006-04-13 17:54   ` Oleg Nesterov
2006-04-13 14:27     ` Arjan van de Ven
2006-04-13 15:07     ` Christoph Hellwig [this message]
2006-04-13 20:21       ` Oleg Nesterov
2006-04-13 16:32         ` Christoph Hellwig
2006-04-13 17:50           ` Eric W. Biederman
2006-04-13 21:56   ` Oleg Nesterov

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=20060413150722.GA5217@infradead.org \
    --to=hch@infradead.org \
    --cc=akpm@osdl.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@tv-sign.ru \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.