mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
Move logging functions to log.c
Instead of keeping all unrelated to C/R procedure helpers in util.c move logging related helpers to log.c. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
38
util.c
38
util.c
@@ -37,50 +37,16 @@
|
||||
#include "types.h"
|
||||
#include "list.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "crtools.h"
|
||||
|
||||
static int logfd = STDERR_FILENO;
|
||||
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
|
||||
logfd = rlimit.rlim_cur - 1;
|
||||
if (dup2(fd, 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);
|
||||
vdprintf(logfd, format, params);
|
||||
vdprintf(get_logfd(), format, params);
|
||||
va_end(params);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user