util: cr_system_userns() should not affect log_fd

Submitted by Andrei Vagin on April 22, 2016, 4:48 p.m.

Details

Message ID 1461343712-21348-1-git-send-email-avagin@openvz.org
State Accepted
Series "util: cr_system_userns() should not affect log_fd"
Commit 16ecb46205f010e76bc8c520d48b20445a06cf74
Headers show

Patch hide | download patch | download mbox

diff --git a/criu/util.c b/criu/util.c
index dae6031..e8ebe61 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -609,8 +609,6 @@  int cr_system_userns(int in, int out, int err, char *cmd,
 		pr_perror("fork() failed");
 		goto out;
 	} else if (pid == 0) {
-		bool stop_log_fd = false;
-
 		if (userns_pid > 0) {
 			if (switch_ns(userns_pid, &user_ns_desc, NULL))
 				goto out_chld;
@@ -621,11 +619,9 @@  int cr_system_userns(int in, int out, int err, char *cmd,
 		}
 
 		if (out < 0)
-			out = log_get_fd();
-		if (err < 0) {
-			err = log_get_fd();
-			stop_log_fd = true;
-		}
+			out = DUP_SAFE(log_get_fd(), out_chld);
+		if (err < 0)
+			err = DUP_SAFE(log_get_fd(), out_chld);
 
 		/*
 		 * out, err, in should be a separate fds,
@@ -641,9 +637,6 @@  int cr_system_userns(int in, int out, int err, char *cmd,
 		    move_img_fd(&err, STDIN_FILENO))
 			goto out_chld;
 
-		if (stop_log_fd)
-			log_fini();
-
 		if (in < 0) {
 			close(STDIN_FILENO);
 		} else {

Comments

Andrey Vagin April 22, 2016, 5 p.m.
cr_system_userns moves files descriptors, so we can take log_fd
directly and need to duplicate it.

On Fri, Apr 22, 2016 at 07:48:32PM +0300, Andrey Vagin wrote:
> From: Andrew Vagin <avagin@virtuozzo.com>
> 
> Fixes: 1dc2f87b33ce ("util: shutdown log in cr_system_userns if error fd is negative")
> Cc: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
> Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
> ---
>  criu/util.c | 13 +++----------
>  1 file changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/criu/util.c b/criu/util.c
> index dae6031..e8ebe61 100644
> --- a/criu/util.c
> +++ b/criu/util.c
> @@ -609,8 +609,6 @@ int cr_system_userns(int in, int out, int err, char *cmd,
>  		pr_perror("fork() failed");
>  		goto out;
>  	} else if (pid == 0) {
> -		bool stop_log_fd = false;
> -
>  		if (userns_pid > 0) {
>  			if (switch_ns(userns_pid, &user_ns_desc, NULL))
>  				goto out_chld;
> @@ -621,11 +619,9 @@ int cr_system_userns(int in, int out, int err, char *cmd,
>  		}
>  
>  		if (out < 0)
> -			out = log_get_fd();
> -		if (err < 0) {
> -			err = log_get_fd();
> -			stop_log_fd = true;
> -		}
> +			out = DUP_SAFE(log_get_fd(), out_chld);
> +		if (err < 0)
> +			err = DUP_SAFE(log_get_fd(), out_chld);
>  
>  		/*
>  		 * out, err, in should be a separate fds,
> @@ -641,9 +637,6 @@ int cr_system_userns(int in, int out, int err, char *cmd,
>  		    move_img_fd(&err, STDIN_FILENO))
>  			goto out_chld;
>  
> -		if (stop_log_fd)
> -			log_fini();
> -
>  		if (in < 0) {
>  			close(STDIN_FILENO);
>  		} else {
> -- 
> 2.5.5
>
Pavel Emelianov April 25, 2016, 9:02 a.m.
Applied