mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-02 07:15:31 +00:00
crtools: add options to specified a log file
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:
committed by
Cyrill Gorcunov
parent
ecc2776fc9
commit
650318f4b2
14
crtools.c
14
crtools.c
@@ -253,8 +253,9 @@ int main(int argc, char *argv[])
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
int opt, idx;
|
int opt, idx;
|
||||||
int action = -1;
|
int action = -1;
|
||||||
|
int log_inited = 0;
|
||||||
|
|
||||||
static const char short_opts[] = "drskf:p:t:hcD:";
|
static const char short_opts[] = "drskf:p:t:hcD:o:";
|
||||||
static const struct option long_opts[] = {
|
static const struct option long_opts[] = {
|
||||||
{ "dump", no_argument, NULL, 'd' },
|
{ "dump", no_argument, NULL, 'd' },
|
||||||
{ "restore", no_argument, NULL, 'r' },
|
{ "restore", no_argument, NULL, 'r' },
|
||||||
@@ -262,9 +263,6 @@ int main(int argc, char *argv[])
|
|||||||
{ NULL, no_argument, NULL, 0 }
|
{ NULL, no_argument, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (init_logging())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
|
BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
@@ -311,12 +309,20 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'o':
|
||||||
|
if (init_logging(optarg))
|
||||||
|
return 1;
|
||||||
|
log_inited = 1;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!log_inited && init_logging(NULL))
|
||||||
|
return 1;
|
||||||
|
|
||||||
if (getcwd(image_dir, sizeof(image_dir)) < 0) {
|
if (getcwd(image_dir, sizeof(image_dir)) < 0) {
|
||||||
pr_perror("can't get currect directory\n");
|
pr_perror("can't get currect directory\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
extern int init_logging(void);
|
extern int init_logging(const char *file_name);
|
||||||
extern void deinit_logging(void);
|
extern void deinit_logging(void);
|
||||||
extern void printk(const char *format, ...);
|
extern void printk(const char *format, ...);
|
||||||
|
|
||||||
|
13
util.c
13
util.c
@@ -42,9 +42,18 @@
|
|||||||
|
|
||||||
static int logfd = STDERR_FILENO;
|
static int logfd = STDERR_FILENO;
|
||||||
|
|
||||||
int init_logging(void)
|
int init_logging(const char *name)
|
||||||
{
|
{
|
||||||
struct rlimit rlimit;
|
struct rlimit rlimit;
|
||||||
|
int fd = STDERR_FILENO;
|
||||||
|
|
||||||
|
if (name) {
|
||||||
|
fd = open(name, O_CREAT | O_WRONLY);
|
||||||
|
if (fd == -1) {
|
||||||
|
pr_perror("Can't create log file %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (getrlimit(RLIMIT_NOFILE, &rlimit)) {
|
if (getrlimit(RLIMIT_NOFILE, &rlimit)) {
|
||||||
pr_err("can't get rlimit: %m\n");
|
pr_err("can't get rlimit: %m\n");
|
||||||
@@ -52,7 +61,7 @@ int init_logging(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
logfd = rlimit.rlim_cur - 1;
|
logfd = rlimit.rlim_cur - 1;
|
||||||
if (dup2(2, logfd) < 0) {
|
if (dup2(fd, logfd) < 0) {
|
||||||
pr_err("can't duplicate descriptor 2->%d: %m\n", logfd);
|
pr_err("can't duplicate descriptor 2->%d: %m\n", logfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user