[CRIU] Re: [PATCH 5/5] tty: Make tty_get_sid_pgrp() to use parasite code

Cyrill Gorcunov gorcunov at openvz.org
Mon Oct 15 13:27:42 EDT 2012


On Mon, Oct 15, 2012 at 09:07:11PM +0400, Cyrill Gorcunov wrote:
> 
> We need to use namespace local sid/pgid parameters
> assigned on tty link, thus use parasite helper.
> 
> Otherwise we might fail on restore in namespace.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>

Pick this two instead of this one.
-------------- next part --------------
>From a3ad61ab0e5992523cbed5cb37bf4cc5c72a2026 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Mon, 15 Oct 2012 21:22:48 +0400
Subject: [PATCH 1/2] parasite: Make parasite_args helper global

Will need it in tty layer.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 include/parasite-syscall.h |    2 ++
 parasite-syscall.c         |    2 +-
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/include/parasite-syscall.h b/include/parasite-syscall.h
index 512e367..a187310 100644
--- a/include/parasite-syscall.h
+++ b/include/parasite-syscall.h
@@ -22,6 +22,8 @@ struct parasite_ctl {
 	int			tsock;					/* transport socket for transfering fds */
 };
 
+extern void *parasite_args(struct parasite_ctl *ctl, int args_size);
+
 struct cr_fdset;
 struct list_head;
 
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 8bd7c03..95711f2 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -223,7 +223,7 @@ err:
 	return ret;
 }
 
-static void *parasite_args(struct parasite_ctl *ctl, int args_size)
+void *parasite_args(struct parasite_ctl *ctl, int args_size)
 {
 	BUG_ON(args_size > PARASITE_ARG_SIZE);
 	return ctl->addr_args;
-- 
1.7.7.6

-------------- next part --------------
>From c209a11fb3fe42d1b4fefea888e5221e470e8140 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Mon, 15 Oct 2012 18:42:36 +0400
Subject: [PATCH 2/2] tty: Make tty_get_sid_pgrp() to use parasite code

We need to use namespace local sid/pgid parameters
assigned on tty link, thus use parasite helper.

Otherwise we might fail on restoring controlling
terminal inside namespace (though everything else
will work even without this patch).

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 tty.c |   42 +++++++++++++++++-------------------------
 1 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/tty.c b/tty.c
index 2df6180..37c02ad 100644
--- a/tty.c
+++ b/tty.c
@@ -28,6 +28,10 @@
 
 #include "protobuf.h"
 #include "protobuf/tty.pb-c.h"
+#include "protobuf/creds.pb-c.h"
+
+#include "parasite-syscall.h"
+#include "parasite.h"
 
 #include "pstree.h"
 #include "tty.h"
@@ -309,36 +313,24 @@ static int lock_pty(int fd)
 	return 0;
 }
 
-static int tty_get_sid_pgrp(int fd, int *sid, int *pgrp, bool *hangup)
+static int tty_get_sid_pgrp(const struct fd_parms *p, int major,
+			    int *sid, int *pgrp, bool *hangup)
 {
+	struct parasite_dump_tty *args = parasite_args(p->ctl, sizeof(*args));
 	int ret;
 
-	ret = ioctl(fd, TIOCGSID, sid);
-	if (ret < 0) {
-		if (errno != ENOTTY)
-			goto err;
-		*sid = 0;
-	}
-
-	ret = ioctl(fd, TIOCGPGRP, pgrp);
-	if (ret < 0) {
-		if (errno != ENOTTY)
-			goto err;
-		*pgrp = 0;
-	}
-
-	*hangup = false;
-	return 0;
+	*args = (struct parasite_dump_tty) {
+		.fd = p->fd,
+	};
 
-err:
-	if (errno != EIO) {
-		pr_perror("Can't get sid/pgrp on %d", fd);
+	ret = parasite_dump_tty(p->ctl);
+	if (ret)
 		return -1;
-	}
 
-	/* kernel reports EIO for get ioctls on pair-less ptys */
-	*sid = *pgrp = 0;
-	*hangup = true;
+	*sid = args->sid;
+	*pgrp = args->pgrp;
+	*hangup = args->hangup;
+
 	return 0;
 }
 
@@ -932,7 +924,7 @@ static int dump_pty_info(int lfd, u32 id, const struct fd_parms *p, int major, i
 	BUILD_BUG_ON(sizeof(termios.c_cc) != sizeof(void *));
 	BUILD_BUG_ON((sizeof(termios.c_cc) * TERMIOS_NCC) < sizeof(t.c_cc));
 
-	if (tty_get_sid_pgrp(lfd, &sid, &pgrp, &hangup))
+	if (tty_get_sid_pgrp(p, major, &sid, &pgrp, &hangup))
 		return -1;
 
 	info.id			= id;
-- 
1.7.7.6



More information about the CRIU mailing list