[5/5] tty: allocate a separate tty info id for each external tty

Submitted by Andrei Vagin on Sept. 27, 2018, 7:01 a.m.

Details

Message ID 20180927070149.7915-1-avagin@openvz.org
State Accepted
Series "files: save inherited file descriptors in fdstore"
Headers show

Commit Message

Andrei Vagin Sept. 27, 2018, 7:01 a.m.
From: Andrei Vagin <avagin@virtuozzo.com>

Otherwise all external tty-s will share the same tty info,
what is obviously wrong.

v2: allocate a separate tty index range for externl terminals

Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
---
 criu/tty.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/tty.c b/criu/tty.c
index 214d97a8e..6acbb6713 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -136,7 +136,7 @@  static int self_stdin_fdid = -1;
  * Pretty acceptable trade off in a sake of simplicity.
  */
 
-#define MAX_TTYS	1024
+#define MAX_TTYS	1088
 
 /*
  * Custom indices should be even numbers just in case if we
@@ -147,8 +147,9 @@  static int self_stdin_fdid = -1;
 #define CONSOLE_INDEX	1002
 #define VT_INDEX	1004
 #define CTTY_INDEX	1006
-#define ETTY_INDEX	1008
 #define STTY_INDEX	1010
+#define ETTY_INDEX	1012
+#define ETTY_INDEX_MAX	1152
 #define INDEX_ERR	(MAX_TTYS + 1)
 
 static DECLARE_BITMAP(tty_bitmap, (MAX_TTYS << 1));
@@ -189,6 +190,20 @@  static int pty_get_index(struct tty_info *ti)
 	return ti->tie->pty->index;
 }
 
+static int ext_fd_get_index(int fd, const struct fd_parms *p)
+{
+	static int index;
+
+	index++;
+
+	if (index + ETTY_INDEX > ETTY_INDEX_MAX) {
+		pr_err("Too many external terminals");
+		return INDEX_ERR;
+	}
+
+	return index;
+}
+
 static int pty_open_ptmx(struct tty_info *info);
 
 static struct tty_driver ptm_driver = {
@@ -229,6 +244,7 @@  static struct tty_driver ext_driver = {
 	.name			= "ext",
 	.index			= ETTY_INDEX,
 	.open			= open_ext_tty,
+	.fd_get_index		= ext_fd_get_index,
 };
 
 static struct tty_driver serial_driver = {

Comments

Cyrill Gorcunov Sept. 27, 2018, 7:42 a.m.
On Thu, Sep 27, 2018 at 10:01:49AM +0300, Andrei Vagin wrote:
>  
> +static int ext_fd_get_index(int fd, const struct fd_parms *p)
> +{
> +	static int index;
> +
> +	index++;
> +
> +	if (index + ETTY_INDEX > ETTY_INDEX_MAX) {
> +		pr_err("Too many external terminals");
> +		return INDEX_ERR;
> +	}
> +
> +	return index;
> +}

Should not here be

	return index + ETTY_INDEX;

instead? Other than that looks ok to me.
Andrey Vagin Oct. 2, 2018, 12:48 a.m.
On Thu, Sep 27, 2018 at 10:42:22AM +0300, Cyrill Gorcunov wrote:
> On Thu, Sep 27, 2018 at 10:01:49AM +0300, Andrei Vagin wrote:
> >  
> > +static int ext_fd_get_index(int fd, const struct fd_parms *p)
> > +{
> > +	static int index;
> > +
> > +	index++;
> > +
> > +	if (index + ETTY_INDEX > ETTY_INDEX_MAX) {
> > +		pr_err("Too many external terminals");
> > +		return INDEX_ERR;
> > +	}
> > +
> > +	return index;
> > +}
> 
> Should not here be
> 
> 	return index + ETTY_INDEX;
> 
> instead? Other than that looks ok to me.

Oops. You are right. Thanks!