Commit 650318f4 authored by Andrey Vagin's avatar Andrey Vagin Committed by Cyrill Gorcunov

crtools: add options to specified a log file

Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Acked-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent ecc2776f
......@@ -253,8 +253,9 @@ int main(int argc, char *argv[])
int ret = -1;
int opt, idx;
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[] = {
{ "dump", no_argument, NULL, 'd' },
{ "restore", no_argument, NULL, 'r' },
......@@ -262,9 +263,6 @@ 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)
......@@ -311,12 +309,20 @@ int main(int argc, char *argv[])
return 1;
}
break;
case 'o':
if (init_logging(optarg))
return 1;
log_inited = 1;
break;
case 'h':
default:
goto usage;
}
}
if (!log_inited && init_logging(NULL))
return 1;
if (getcwd(image_dir, sizeof(image_dir)) < 0) {
pr_perror("can't get currect directory\n");
return 1;
......
......@@ -15,7 +15,7 @@
#include "compiler.h"
#include "types.h"
extern int init_logging(void);
extern int init_logging(const char *file_name);
extern void deinit_logging(void);
extern void printk(const char *format, ...);
......
......@@ -42,9 +42,18 @@
static int logfd = STDERR_FILENO;
int init_logging(void)
int init_logging(const char *name)
{
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)) {
pr_err("can't get rlimit: %m\n");
......@@ -52,7 +61,7 @@ int init_logging(void)
}
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);
return 1;
}
......
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