[CRIU] [PATCH 3/5] proc: don't use global variables for saving service fds
Andrey Vagin
avagin at openvz.org
Sun Jan 6 05:48:14 EST 2013
It's preparation for cloning service descriptors
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
util.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/util.c b/util.c
index 59ed831..a0e4489 100644
--- a/util.c
+++ b/util.c
@@ -173,7 +173,7 @@ int move_img_fd(int *img_fd, int want_fd)
static pid_t open_proc_pid = 0;
static int open_proc_fd = -1;
-static int proc_dir_fd = -1;
+static bool proc_dir_inited = false;
int close_pid_proc(void)
{
@@ -190,10 +190,15 @@ int close_pid_proc(void)
void close_proc()
{
+ int fd = get_service_fd(PROC_FD_OFF);
+
close_pid_proc();
- if (proc_dir_fd > 0)
- close(proc_dir_fd);
- proc_dir_fd = -1;
+
+ if (!proc_dir_inited)
+ return;
+
+ close(fd);
+ proc_dir_inited = false;
}
int set_proc_fd(int fd)
@@ -206,7 +211,7 @@ int set_proc_fd(int fd)
return -1;
}
- proc_dir_fd = sfd;
+ proc_dir_inited = true;
return 0;
}
@@ -230,7 +235,7 @@ int set_proc_mountpoint(char *path)
return -1;
}
- proc_dir_fd = sfd;
+ proc_dir_inited = true;
return 0;
}
@@ -239,20 +244,21 @@ inline int open_pid_proc(pid_t pid)
{
char path[18];
int fd;
+ int dfd = get_service_fd(PROC_FD_OFF);
if (pid == open_proc_pid)
return open_proc_fd;
close_pid_proc();
- if (proc_dir_fd == -1) {
+ if (!proc_dir_inited) {
fd = set_proc_mountpoint("/proc");
if (fd < 0)
return fd;
}
snprintf(path, sizeof(path), "%d", pid);
- fd = openat(proc_dir_fd, path, O_RDONLY);
+ fd = openat(dfd, path, O_RDONLY);
if (fd < 0)
pr_perror("Can't open %s", path);
else {
--
1.7.11.7
More information about the CRIU
mailing list