mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-03 07:45:17 +00:00
Use *open_proc* where possible
Using open_proc/fopen_proc/__open_proc is better since - it uses openat - it comes with nice error reporting Let's use it in places where we can. Even if it does not give any improvements (such as in cr-check.c), error message unification is good enough reason to do so. Requested-by: Pavel Emelyanov <xemul@virtuozzo.com> Signed-off-by: Kir Kolyshkin <kir@openvz.org> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
committed by
Andrei Vagin
parent
ba78d15557
commit
df9d94515f
@@ -359,11 +359,9 @@ static int access_autofs_mount(struct mount_info *pm)
|
|||||||
if (new_pid_ns < 0)
|
if (new_pid_ns < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
old_pid_ns = open("/proc/self/ns/pid", O_RDONLY);
|
old_pid_ns = open_proc(PROC_SELF, "ns/pid");
|
||||||
if (old_pid_ns < 0) {
|
if (old_pid_ns < 0)
|
||||||
pr_perror("Can't open /proc/self/ns/pid");
|
|
||||||
goto close_new_pid_ns;
|
goto close_new_pid_ns;
|
||||||
}
|
|
||||||
|
|
||||||
if (switch_ns(pm->nsid->ns_pid, &mnt_ns_desc, &old_mnt_ns)) {
|
if (switch_ns(pm->nsid->ns_pid, &mnt_ns_desc, &old_mnt_ns)) {
|
||||||
pr_err("failed to switch to mount namespace\n");
|
pr_err("failed to switch to mount namespace\n");
|
||||||
|
@@ -244,11 +244,9 @@ static int check_fcntl(void)
|
|||||||
u32 v[2];
|
u32 v[2];
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open("/proc/self/comm", O_RDONLY);
|
fd = open_proc(PROC_SELF, "comm");
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
pr_perror("Can't open self comm file");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (fcntl(fd, F_GETOWNER_UIDS, (long)v)) {
|
if (fcntl(fd, F_GETOWNER_UIDS, (long)v)) {
|
||||||
pr_perror("Can'r fetch file owner UIDs");
|
pr_perror("Can'r fetch file owner UIDs");
|
||||||
@@ -726,11 +724,9 @@ static unsigned long get_ring_len(unsigned long addr)
|
|||||||
FILE *maps;
|
FILE *maps;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
maps = fopen("/proc/self/maps", "r");
|
maps = fopen_proc(PROC_SELF, "maps");
|
||||||
if (!maps) {
|
if (!maps)
|
||||||
pr_perror("No maps proc file");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), maps)) {
|
while (fgets(buf, sizeof(buf), maps)) {
|
||||||
unsigned long start, end;
|
unsigned long start, end;
|
||||||
|
@@ -294,9 +294,8 @@ int kerndat_get_dirty_track(void)
|
|||||||
goto no_dt;
|
goto no_dt;
|
||||||
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
pm2 = open("/proc/self/pagemap", O_RDONLY);
|
pm2 = open_proc(PROC_SELF, "pagemap");
|
||||||
if (pm2 < 0) {
|
if (pm2 < 0) {
|
||||||
pr_perror("Can't open pagemap file");
|
|
||||||
munmap(map, PAGE_SIZE);
|
munmap(map, PAGE_SIZE);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -397,11 +396,9 @@ int kerndat_fdinfo_has_lock()
|
|||||||
int fd, pfd = -1, exit_code = -1, len;
|
int fd, pfd = -1, exit_code = -1, len;
|
||||||
char buf[PAGE_SIZE];
|
char buf[PAGE_SIZE];
|
||||||
|
|
||||||
fd = open("/proc/locks", O_RDONLY);
|
fd = open_proc(PROC_GEN, "locks");
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
pr_perror("Unable to open /proc/locks");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (flock(fd, LOCK_SH)) {
|
if (flock(fd, LOCK_SH)) {
|
||||||
pr_perror("Can't take a lock");
|
pr_perror("Can't take a lock");
|
||||||
|
@@ -238,17 +238,13 @@ int switch_ns(int pid, struct ns_desc *nd, int *rst)
|
|||||||
|
|
||||||
int switch_ns_by_fd(int nsfd, struct ns_desc *nd, int *rst)
|
int switch_ns_by_fd(int nsfd, struct ns_desc *nd, int *rst)
|
||||||
{
|
{
|
||||||
char buf[32];
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (rst) {
|
if (rst) {
|
||||||
snprintf(buf, sizeof(buf), "/proc/self/ns/%s", nd->str);
|
*rst = open_proc(PROC_SELF, "ns/%s", nd->str);
|
||||||
*rst = open(buf, O_RDONLY);
|
if (*rst < 0)
|
||||||
if (*rst < 0) {
|
|
||||||
pr_perror("Can't open ns file");
|
|
||||||
goto err_ns;
|
goto err_ns;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ret = setns(nsfd, nd->cflag);
|
ret = setns(nsfd, nd->cflag);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@@ -1715,11 +1715,9 @@ int netns_keep_nsfd(void)
|
|||||||
* that before we leave the existing namespaces.
|
* that before we leave the existing namespaces.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ns_fd = open("/proc/self/ns/net", O_RDONLY | O_CLOEXEC);
|
ns_fd = __open_proc(PROC_SELF, 0, O_RDONLY | O_CLOEXEC, "ns/net");
|
||||||
if (ns_fd < 0) {
|
if (ns_fd < 0)
|
||||||
pr_perror("Can't cache net fd");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
ret = install_service_fd(NS_FD_OFF, ns_fd);
|
ret = install_service_fd(NS_FD_OFF, ns_fd);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
Reference in New Issue
Block a user