[CRIU] [PATCH 2/3] unix: Factor out common parts restoration

Pavel Emelyanov xemul at virtuozzo.com
Tue Feb 14 01:48:05 PST 2017


Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/sk-unix.c | 41 +++++++++++++++++------------------------
 1 file changed, 17 insertions(+), 24 deletions(-)

diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index 23d29b6..31540f6 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -848,6 +848,20 @@ static int shutdown_unix_sk(int sk, struct unix_sk_info *ui)
 	return 0;
 }
 
+static int restore_sk_common(int fd, struct unix_sk_info *ui)
+{
+	if (rst_file_params(fd, ui->ue->fown, ui->ue->flags))
+		return -1;
+
+	if (restore_socket_opts(fd, ui->ue->opts))
+		return -1;
+
+	if (shutdown_unix_sk(fd, ui))
+		return -1;
+
+	return 0;
+}
+
 static void revert_unix_sk_cwd(int *prev_cwd_fd, int *root_fd)
 {
 	if (*root_fd >= 0) {
@@ -960,16 +974,7 @@ static int post_open_unix_sk(struct file_desc *d, int fd)
 	if (peer->queuer == ui->ue->ino && restore_sk_queue(fd, peer->ue->id))
 		return -1;
 
-	if (rst_file_params(fd, ui->ue->fown, ui->ue->flags))
-		return -1;
-
-	if (restore_socket_opts(fd, ui->ue->opts))
-		return -1;
-
-	if (shutdown_unix_sk(fd, ui))
-		return -1;
-
-	return 0;
+	return restore_sk_common(fd, ui);
 }
 
 static int bind_unix_sk(int sk, struct unix_sk_info *ui)
@@ -1106,13 +1111,7 @@ static int open_unixsk_pair_master(struct unix_sk_info *ui, int *new_fd)
 	if (bind_unix_sk(sk[0], ui))
 		return -1;
 
-	if (rst_file_params(sk[0], ui->ue->fown, ui->ue->flags))
-		return -1;
-
-	if (restore_socket_opts(sk[0], ui->ue->opts))
-		return -1;
-
-	if (shutdown_unix_sk(sk[0], ui))
+	if (restore_sk_common(sk[0], ui))
 		return -1;
 
 	fle = file_master(&peer->d);
@@ -1148,13 +1147,7 @@ static int open_unixsk_pair_slave(struct unix_sk_info *ui, int *new_fd)
 	if (bind_unix_sk(sk, ui))
 		return -1;
 
-	if (rst_file_params(sk, ui->ue->fown, ui->ue->flags))
-		return -1;
-
-	if (restore_socket_opts(sk, ui->ue->opts))
-		return -1;
-
-	if (shutdown_unix_sk(sk, ui))
+	if (restore_sk_common(sk, ui))
 		return -1;
 
 	*new_fd = sk;
-- 
2.5.0



More information about the CRIU mailing list