Commit 7a25c82b authored by Stanislav Kinsburskiy's avatar Stanislav Kinsburskiy Committed by Pavel Emelyanov

util: shutdown log in cr_system_userns if error fd is negative

Otherwise error in case of exec error won't be printed
The problem is that when err fd is negative, it's replaced by log fd.
Then err is moved to STDERR (that means, that log_fd is _closed_).
But log facility still consider log fd as valid and tries to use it to print
error message in case of exec failure.
Which is equal to writing to /dev/null, basically.
This patch shutdown log, if err fd was negative, thus forcing criu to output
exec error to STDERR (which was replaced by log fs, btw).
Signed-off-by: 's avatarStanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 781601a0
......@@ -609,6 +609,8 @@ 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;
......@@ -620,8 +622,10 @@ int cr_system_userns(int in, int out, int err, char *cmd,
if (out < 0)
out = log_get_fd();
if (err < 0)
if (err < 0) {
err = log_get_fd();
stop_log_fd = true;
}
/*
* out, err, in should be a separate fds,
......@@ -637,6 +641,9 @@ 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 {
......
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