2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-03 07:45:17 +00:00

Don't use standard descriptors for logging

The standard descriptors may be redirected.

crtool dumplicates stderr in rlimit.maxfileno-1 and this descriptor
is inherited by all children and will be closed before sigreturn.

Known issues:

 - The logging descriptor may be used by a target process and
   a resume will fail.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
Andrey Vagin
2011-12-05 12:07:52 +04:00
committed by Cyrill Gorcunov
parent e57a4c2945
commit 2c237b6973
4 changed files with 34 additions and 1 deletions

View File

@@ -1623,6 +1623,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
task_args->thread_args);
close_safe(&fd_pstree);
deinit_logging();
/*
* An indirect call to task_restore, note it never resturns

View File

@@ -241,6 +241,9 @@ int main(int argc, char *argv[])
{ NULL, no_argument, NULL, 0 }
};
if (init_logging())
return 1;
BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
if (argc < 3)

View File

@@ -15,6 +15,8 @@
#include "compiler.h"
#include "types.h"
extern int init_logging(void);
extern void deinit_logging(void);
extern void printk(const char *format, ...);
#define PREF_SHIFT_OP(pref, op, size) ((size) op (pref ##BYTES_SHIFT))

29
util.c
View File

@@ -31,6 +31,7 @@
#include <sys/ptrace.h>
#include <sys/user.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include "compiler.h"
#include "types.h"
@@ -39,12 +40,38 @@
#include "crtools.h"
static int logfd = STDERR_FILENO;
int init_logging(void)
{
struct rlimit rlimit;
if (getrlimit(RLIMIT_NOFILE, &rlimit)) {
pr_err("can't get rlimit: %m\n");
return 1;
}
logfd = rlimit.rlim_cur - 1;
if (dup2(2, logfd) < 0) {
pr_err("can't duplicate descriptor 2->%d: %m\n", logfd);
return 1;
}
return 0;
}
void deinit_logging(void)
{
close(logfd);
logfd = -1;
}
void printk(const char *format, ...)
{
va_list params;
va_start(params, format);
vfprintf(stdout, format, params);
vdprintf(logfd, format, params);
va_end(params);
}