mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-03 07:45:17 +00:00
proc: Don't use parent proc_self_fd cached descriptor
When we call open_proc(PROC_SELF, ...) the /proc/self descriptor is cached in criu. If the process fork()-s after than and child goes open_proc(PROC_SELF, ...) then it will get the parent's proc descriptor. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Acked-by: Andrew Vagin <avagin@virtuozzo.com>
This commit is contained in:
10
util.c
10
util.c
@@ -174,6 +174,7 @@ int move_img_fd(int *img_fd, int want_fd)
|
|||||||
|
|
||||||
static pid_t open_proc_pid = PROC_NONE;
|
static pid_t open_proc_pid = PROC_NONE;
|
||||||
static int open_proc_fd = -1;
|
static int open_proc_fd = -1;
|
||||||
|
static pid_t open_proc_self_pid;
|
||||||
static int open_proc_self_fd = -1;
|
static int open_proc_self_fd = -1;
|
||||||
|
|
||||||
static inline void set_proc_self_fd(int fd)
|
static inline void set_proc_self_fd(int fd)
|
||||||
@@ -182,6 +183,7 @@ static inline void set_proc_self_fd(int fd)
|
|||||||
close(open_proc_self_fd);
|
close(open_proc_self_fd);
|
||||||
|
|
||||||
open_proc_self_fd = fd;
|
open_proc_self_fd = fd;
|
||||||
|
open_proc_self_pid = getpid();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void set_proc_pid_fd(int pid, int fd)
|
static inline void set_proc_pid_fd(int pid, int fd)
|
||||||
@@ -195,9 +197,13 @@ static inline void set_proc_pid_fd(int pid, int fd)
|
|||||||
|
|
||||||
static inline int get_proc_fd(int pid)
|
static inline int get_proc_fd(int pid)
|
||||||
{
|
{
|
||||||
if (pid == PROC_SELF)
|
if (pid == PROC_SELF) {
|
||||||
|
if (open_proc_self_fd != -1 && open_proc_self_pid != getpid()) {
|
||||||
|
close(open_proc_self_fd);
|
||||||
|
open_proc_self_fd = -1;
|
||||||
|
}
|
||||||
return open_proc_self_fd;
|
return open_proc_self_fd;
|
||||||
else if (pid == open_proc_pid)
|
} else if (pid == open_proc_pid)
|
||||||
return open_proc_fd;
|
return open_proc_fd;
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
Reference in New Issue
Block a user