2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

log: close unused descriptor

This code opens a log file and duplicates the descriptor to logfd,
but forgets to close the first one.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
Andrey Vagin
2012-01-10 16:39:00 +04:00
committed by Cyrill Gorcunov
parent 5d5e8b801c
commit f274f16081

18
log.c
View File

@@ -32,6 +32,11 @@ int init_log(const char *name)
struct rlimit rlimit;
int fd = STDERR_FILENO;
if (getrlimit(RLIMIT_NOFILE, &rlimit)) {
pr_err("can't get rlimit: %m\n");
return -1;
}
if (name) {
fd = open(name, O_CREAT | O_WRONLY);
if (fd == -1) {
@@ -40,20 +45,19 @@ int init_log(const char *name)
}
}
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) {
if (reopen_fd_as(logfd, fd) < 0) {
pr_err("can't duplicate descriptor %d->%d: %m\n",
fd, logfd);
logfd = STDERR_FILENO;
return -1;
goto err;
}
return 0;
err:
if (name)
close(fd);
return -1;
}
void fini_log(void)