Commit 990f80dd authored by Pavel Emelyanov's avatar Pavel Emelyanov

tty: Sanitize slavery and ctl tty setups

We need to do two non-trivial things with ttys -- interconnect
slaves to masters (or to each other) and setup ctl-tty restoring
task.

Now this is done in subsequently depending on each other steps:

1. collect ttys
2. interconnect slaves and mark ctl-tty tasks
3. collect fake fds for tty-ctl tasks
4. setup orphaned slaves

We can relax this logic in two ways:

1. don't split marking ctl-tty tasks and then creating fds for them
   do it in one step at the end
2. don't interconnect slaves with masters and orphaned slaves in
   two steps -- do it in one place after fds are collected
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent ff875dc4
...@@ -139,10 +139,6 @@ static int prepare_shared(void) ...@@ -139,10 +139,6 @@ static int prepare_shared(void)
ret = prepare_fd_pid(pi->pid.virt, pi->rst); ret = prepare_fd_pid(pi->pid.virt, pi->rst);
if (ret < 0) if (ret < 0)
break; break;
ret = prepare_ctl_tty(pi->pid.virt, pi->rst, pi->ctl_tty_id);
if (ret < 0)
break;
} }
if (ret < 0) if (ret < 0)
...@@ -150,9 +146,7 @@ static int prepare_shared(void) ...@@ -150,9 +146,7 @@ static int prepare_shared(void)
mark_pipe_master(); mark_pipe_master();
ret = tty_setup_orphan_slavery(&opts); tty_setup_slavery();
if (ret)
goto err;
ret = resolve_unix_peers(); ret = resolve_unix_peers();
if (ret) if (ret)
......
...@@ -11,7 +11,6 @@ struct pstree_item { ...@@ -11,7 +11,6 @@ struct pstree_item {
pid_t pgid; pid_t pgid;
pid_t sid; pid_t sid;
pid_t born_sid; pid_t born_sid;
u32 ctl_tty_id;
int state; /* TASK_XXX constants */ int state; /* TASK_XXX constants */
int nr_threads; /* number of threads */ int nr_threads; /* number of threads */
struct pid *threads; /* array of threads */ struct pid *threads; /* array of threads */
......
...@@ -17,6 +17,6 @@ extern int dump_tty(struct fd_parms *p, int lfd, const struct cr_fdset *set); ...@@ -17,6 +17,6 @@ extern int dump_tty(struct fd_parms *p, int lfd, const struct cr_fdset *set);
extern int collect_tty(void); extern int collect_tty(void);
extern int tty_is_master(struct fdinfo_list_entry *le); extern int tty_is_master(struct fdinfo_list_entry *le);
extern int prepare_shared_tty(void); extern int prepare_shared_tty(void);
extern int tty_setup_orphan_slavery(const struct cr_options *opts); extern void tty_setup_slavery(void);
#endif /* CR_TTY_H__ */ #endif /* CR_TTY_H__ */
...@@ -638,18 +638,15 @@ static int tty_find_restoring_task(struct tty_info *info) ...@@ -638,18 +638,15 @@ static int tty_find_restoring_task(struct tty_info *info)
pr_info("Set a control terminal to %d\n", info->tie->sid); pr_info("Set a control terminal to %d\n", info->tie->sid);
for_each_pstree_item(item) { for_each_pstree_item(item)
if (item->sid == info->tie->sid) { if (item->sid == info->tie->sid)
item->ctl_tty_id = info->tfe->id; return prepare_ctl_tty(item->pid.virt, item->rst, info->tfe->id);
return 0;
}
}
pr_err("No task found with sid %d\n", info->tie->sid); pr_err("No task found with sid %d\n", info->tie->sid);
return -1; return -1;
} }
int tty_setup_orphan_slavery(const struct cr_options *opts) static void tty_setup_orphan_slavery(void)
{ {
struct tty_info *info, *peer, *m; struct tty_info *info, *peer, *m;
...@@ -688,11 +685,9 @@ int tty_setup_orphan_slavery(const struct cr_options *opts) ...@@ -688,11 +685,9 @@ int tty_setup_orphan_slavery(const struct cr_options *opts)
m->tfe->id); m->tfe->id);
} }
} }
return 0;
} }
static int tty_setup_slavery(void) void tty_setup_slavery(void)
{ {
struct tty_info *info, *peer, *m; struct tty_info *info, *peer, *m;
...@@ -720,7 +715,7 @@ static int tty_setup_slavery(void) ...@@ -720,7 +715,7 @@ static int tty_setup_slavery(void)
tty_show_pty_info(" `- sibling", peer); tty_show_pty_info(" `- sibling", peer);
} }
return 0; tty_setup_orphan_slavery();
} }
static int verify_termios(u32 id, TermiosEntry *e) static int verify_termios(u32 id, TermiosEntry *e)
...@@ -851,9 +846,6 @@ int collect_tty(void) ...@@ -851,9 +846,6 @@ int collect_tty(void)
ret = collect_image(CR_FD_TTY, PB_TTY, ret = collect_image(CR_FD_TTY, PB_TTY,
sizeof(struct tty_info), sizeof(struct tty_info),
collect_one_tty); collect_one_tty);
if (!ret)
ret = tty_setup_slavery();
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment