[PATCH 3/4] tty: Iterate only thread group leaders in __do_SAK()

From: Kirill Tkhai
Date: Thu Jan 11 2018 - 10:53:39 EST


Since threads can't have additional fd in comparison
to thread group leader (previous patch closed races
with failing exec), we may skip useless iterations
over threads files, as they definitely have the same
files struct, as thread group leader.

So, skip the pointless iterations and make __do_SAK()
faster.

Signed-off-by: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx>
---
drivers/tty/tty_io.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index dc60aeea87d8..94813ae40983 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2704,7 +2704,7 @@ void __do_SAK(struct tty_struct *tty)
#ifdef TTY_SOFT_SAK
tty_hangup(tty);
#else
- struct task_struct *g, *p;
+ struct task_struct *p;
struct pid *session;
int i;

@@ -2725,7 +2725,7 @@ void __do_SAK(struct tty_struct *tty)
} while_each_pid_task(session, PIDTYPE_SID, p);

/* Now kill any processes that happen to have the tty open */
- do_each_thread(g, p) {
+ for_each_process(p) {
if (p->signal->tty == tty) {
tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n",
task_pid_nr(p), p->comm);
@@ -2740,7 +2740,7 @@ void __do_SAK(struct tty_struct *tty)
force_sig(SIGKILL, p);
}
task_unlock(p);
- } while_each_thread(g, p);
+ }
read_unlock(&tasklist_lock);
#endif
}