[6/7] tty: Move session lookup leader into find_session_leader

Submitted by Cyrill Gorcunov on Feb. 15, 2018, 8:30 p.m.

Details

Message ID 20180215203030.7513-7-gorcunov@virtuozzo.com
State New
Series "criu: Add support for ctty inheritance"
Headers show

Commit Message

Cyrill Gorcunov Feb. 15, 2018, 8:30 p.m.
Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
---
 criu/tty.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/tty.c b/criu/tty.c
index 4cc99690f..41d8dcaa2 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -1292,12 +1292,12 @@  static struct file_desc_ops tty_desc_ops = {
 	.name		= tty_d_name,
 };
 
-static struct pstree_item *find_first_sid(int sid)
+static struct pstree_item *find_session_leader(pid_t sid)
 {
 	struct pstree_item *item;
 
 	for_each_pstree_item(item) {
-		if (item->sid == sid)
+		if (item->sid == sid && vpid(item) == sid)
 			return item;
 	}
 
@@ -1383,8 +1383,8 @@  static int tty_find_restoring_task(struct tty_info *info)
 		 * and it can restore the controlling terminal
 		 * for us.
 		 */
-		item = find_first_sid(info->tie->sid);
-		if (item && vpid(item) == item->sid) {
+		item = find_session_leader(info->tie->sid);
+		if (item) {
 			pr_info("Set a control terminal %#x to %d\n",
 				info->tfe->id, info->tie->sid);
 			return prepare_ctl_tty(vpid(item),
@@ -1843,9 +1843,9 @@  int dump_verify_tty_sids(void)
 	 */
 	list_for_each_entry_safe(dinfo, n, &all_ttys, list) {
 		if (!ret && dinfo->sid) {
-			struct pstree_item *item = find_first_sid(dinfo->sid);
+			struct pstree_item *item = find_session_leader(dinfo->sid);
 
-			if (!item || vpid(item) != dinfo->sid) {
+			if (!item) {
 				if (!opts.shell_job) {
 					pr_err("Found dangling tty with sid %d pgid %d (%s) on peer fd %d.\n",
 					       dinfo->sid, dinfo->pgrp,