Commit 2b6ed5bf authored by Andrei Vagin's avatar Andrei Vagin

util: move open_proc_fd to service_fd

We need this to avoid conflicts with file descriptors,
which has to be restored.

Currently open_proc_pid() doesn't used during restoring
file descriptors, but we are going to use it to restore
sockets in proper network namespaces.
Acked-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 6b7393c4
......@@ -9,6 +9,7 @@ enum sfd_type {
LOG_FD_OFF,
IMG_FD_OFF,
PROC_FD_OFF, /* fd with /proc for all proc_ calls */
PROC_PID_FD_OFF,
CTL_TTY_OFF,
SELF_STDIN_OFF,
CR_PROC_FD_OFF, /* some other's proc fd.
......
......@@ -291,7 +291,6 @@ int move_fd_from(int *img_fd, int want_fd)
*/
static pid_t open_proc_pid = PROC_NONE;
static int open_proc_fd = -1;
static pid_t open_proc_self_pid;
static int open_proc_self_fd = -1;
......@@ -304,13 +303,18 @@ static inline void set_proc_self_fd(int fd)
open_proc_self_pid = getpid();
}
static inline void set_proc_pid_fd(int pid, int fd)
static inline int set_proc_pid_fd(int pid, int fd)
{
if (open_proc_fd >= 0)
close(open_proc_fd);
int ret;
if (fd < 0)
return close_service_fd(PROC_PID_FD_OFF);
open_proc_pid = pid;
open_proc_fd = fd;
ret = install_service_fd(PROC_PID_FD_OFF, fd);
close(fd);
return ret;
}
static inline int get_proc_fd(int pid)
......@@ -322,7 +326,7 @@ static inline int get_proc_fd(int pid)
}
return open_proc_self_fd;
} else if (pid == open_proc_pid)
return open_proc_fd;
return get_service_fd(PROC_PID_FD_OFF);
else
return -1;
}
......@@ -406,7 +410,7 @@ inline int open_pid_proc(pid_t pid)
if (pid == PROC_SELF)
set_proc_self_fd(fd);
else
set_proc_pid_fd(pid, fd);
fd = set_proc_pid_fd(pid, fd);
return fd;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment