Commit df9d9451 authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Andrei Vagin

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: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarKir Kolyshkin <kir@openvz.org>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent ba78d155
......@@ -359,11 +359,9 @@ static int access_autofs_mount(struct mount_info *pm)
if (new_pid_ns < 0)
return -1;
old_pid_ns = open("/proc/self/ns/pid", O_RDONLY);
if (old_pid_ns < 0) {
pr_perror("Can't open /proc/self/ns/pid");
old_pid_ns = open_proc(PROC_SELF, "ns/pid");
if (old_pid_ns < 0)
goto close_new_pid_ns;
}
if (switch_ns(pm->nsid->ns_pid, &mnt_ns_desc, &old_mnt_ns)) {
pr_err("failed to switch to mount namespace\n");
......
......@@ -244,11 +244,9 @@ static int check_fcntl(void)
u32 v[2];
int fd;
fd = open("/proc/self/comm", O_RDONLY);
if (fd < 0) {
pr_perror("Can't open self comm file");
fd = open_proc(PROC_SELF, "comm");
if (fd < 0)
return -1;
}
if (fcntl(fd, F_GETOWNER_UIDS, (long)v)) {
pr_perror("Can'r fetch file owner UIDs");
......@@ -726,11 +724,9 @@ static unsigned long get_ring_len(unsigned long addr)
FILE *maps;
char buf[256];
maps = fopen("/proc/self/maps", "r");
if (!maps) {
pr_perror("No maps proc file");
maps = fopen_proc(PROC_SELF, "maps");
if (!maps)
return 0;
}
while (fgets(buf, sizeof(buf), maps)) {
unsigned long start, end;
......
......@@ -294,9 +294,8 @@ int kerndat_get_dirty_track(void)
goto no_dt;
ret = -1;
pm2 = open("/proc/self/pagemap", O_RDONLY);
pm2 = open_proc(PROC_SELF, "pagemap");
if (pm2 < 0) {
pr_perror("Can't open pagemap file");
munmap(map, PAGE_SIZE);
return ret;
}
......@@ -397,11 +396,9 @@ int kerndat_fdinfo_has_lock()
int fd, pfd = -1, exit_code = -1, len;
char buf[PAGE_SIZE];
fd = open("/proc/locks", O_RDONLY);
if (fd < 0) {
pr_perror("Unable to open /proc/locks");
fd = open_proc(PROC_GEN, "locks");
if (fd < 0)
return -1;
}
if (flock(fd, LOCK_SH)) {
pr_perror("Can't take a lock");
......
......@@ -238,16 +238,12 @@ int switch_ns(int pid, 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;
if (rst) {
snprintf(buf, sizeof(buf), "/proc/self/ns/%s", nd->str);
*rst = open(buf, O_RDONLY);
if (*rst < 0) {
pr_perror("Can't open ns file");
*rst = open_proc(PROC_SELF, "ns/%s", nd->str);
if (*rst < 0)
goto err_ns;
}
}
ret = setns(nsfd, nd->cflag);
......
......@@ -1715,11 +1715,9 @@ int netns_keep_nsfd(void)
* that before we leave the existing namespaces.
*/
ns_fd = open("/proc/self/ns/net", O_RDONLY | O_CLOEXEC);
if (ns_fd < 0) {
pr_perror("Can't cache net fd");
ns_fd = __open_proc(PROC_SELF, 0, O_RDONLY | O_CLOEXEC, "ns/net");
if (ns_fd < 0)
return -1;
}
ret = install_service_fd(NS_FD_OFF, ns_fd);
if (ret < 0)
......
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