mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 14:55:39 +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:
committed by
Cyrill Gorcunov
parent
5d5e8b801c
commit
f274f16081
18
log.c
18
log.c
@@ -32,6 +32,11 @@ int init_log(const char *name)
|
|||||||
struct rlimit rlimit;
|
struct rlimit rlimit;
|
||||||
int fd = STDERR_FILENO;
|
int fd = STDERR_FILENO;
|
||||||
|
|
||||||
|
if (getrlimit(RLIMIT_NOFILE, &rlimit)) {
|
||||||
|
pr_err("can't get rlimit: %m\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
fd = open(name, O_CREAT | O_WRONLY);
|
fd = open(name, O_CREAT | O_WRONLY);
|
||||||
if (fd == -1) {
|
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;
|
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",
|
pr_err("can't duplicate descriptor %d->%d: %m\n",
|
||||||
fd, logfd);
|
fd, logfd);
|
||||||
logfd = STDERR_FILENO;
|
logfd = STDERR_FILENO;
|
||||||
return -1;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
err:
|
||||||
|
if (name)
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fini_log(void)
|
void fini_log(void)
|
||||||
|
Reference in New Issue
Block a user